staging: iio: Use kcalloc instead of kzalloc to allocate array
[firefly-linux-kernel-4.4.55.git] / drivers / staging / iio / industrialio-core.c
index ee5e0640aa29b9a5a8f9dbca27b78951bb89e31d..d8cd9e3c07a6e1d3a32b5b8724a9460c3c0ed652 100644 (file)
@@ -25,8 +25,8 @@
 #include "iio.h"
 #include "iio_core.h"
 #include "iio_core_trigger.h"
-#include "chrdev.h"
 #include "sysfs.h"
+#include "events.h"
 
 /* IDA to assign each registered device a unique id*/
 static DEFINE_IDA(iio_ida);
@@ -77,15 +77,16 @@ static const char * const iio_modifier_names[] = {
 
 /* relies on pairs of these shared then separate */
 static const char * const iio_chan_info_postfix[] = {
-       [IIO_CHAN_INFO_SCALE_SHARED/2] = "scale",
-       [IIO_CHAN_INFO_OFFSET_SHARED/2] = "offset",
-       [IIO_CHAN_INFO_CALIBSCALE_SHARED/2] = "calibscale",
-       [IIO_CHAN_INFO_CALIBBIAS_SHARED/2] = "calibbias",
-       [IIO_CHAN_INFO_PEAK_SHARED/2] = "peak_raw",
-       [IIO_CHAN_INFO_PEAK_SCALE_SHARED/2] = "peak_scale",
-       [IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SHARED/2]
-       = "quadrature_correction_raw",
-       [IIO_CHAN_INFO_AVERAGE_RAW_SHARED/2] = "mean_raw",
+       [IIO_CHAN_INFO_SCALE] = "scale",
+       [IIO_CHAN_INFO_OFFSET] = "offset",
+       [IIO_CHAN_INFO_CALIBSCALE] = "calibscale",
+       [IIO_CHAN_INFO_CALIBBIAS] = "calibbias",
+       [IIO_CHAN_INFO_PEAK] = "peak_raw",
+       [IIO_CHAN_INFO_PEAK_SCALE] = "peak_scale",
+       [IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW] = "quadrature_correction_raw",
+       [IIO_CHAN_INFO_AVERAGE_RAW] = "mean_raw",
+       [IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY]
+       = "filter_low_pass_3db_frequency",
 };
 
 /**
@@ -261,7 +262,7 @@ static int iio_event_getfd(struct iio_dev *indio_dev)
                                indio_dev->event_interface, O_RDONLY);
        if (fd < 0) {
                mutex_lock(&indio_dev->event_interface->event_list_lock);
-               clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
+               clear_bit(IIO_BUSY_BIT_POS, &indio_dev->event_interface->flags);
                mutex_unlock(&indio_dev->event_interface->event_list_lock);
        }
        return fd;
@@ -603,7 +604,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
                                             chan,
                                             &iio_read_channel_info,
                                             &iio_write_channel_info,
-                                            (1 << i),
+                                            i/2,
                                             !(i%2),
                                             &indio_dev->dev,
                                             &indio_dev->channel_attr_list);
@@ -668,10 +669,9 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
        if (indio_dev->name)
                attrcount++;
 
-       indio_dev->chan_attr_group.attrs
-               = kzalloc(sizeof(indio_dev->chan_attr_group.attrs[0])*
-                         (attrcount + 1),
-                         GFP_KERNEL);
+       indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1,
+                                                  sizeof(indio_dev->chan_attr_group.attrs[0]),
+                                                  GFP_KERNEL);
        if (indio_dev->chan_attr_group.attrs == NULL) {
                ret = -ENOMEM;
                goto error_clear_attrs;
@@ -791,6 +791,9 @@ static ssize_t iio_ev_value_store(struct device *dev,
        unsigned long val;
        int ret;
 
+       if (!indio_dev->info->write_event_value)
+               return -EINVAL;
+
        ret = strict_strtoul(buf, 10, &val);
        if (ret)
                return ret;
@@ -961,10 +964,9 @@ static int iio_device_register_eventset(struct iio_dev *indio_dev)
        }
 
        indio_dev->event_interface->group.name = iio_event_group_name;
-       indio_dev->event_interface->group.attrs =
-               kzalloc(sizeof(indio_dev->event_interface->group.attrs[0])
-                       *(attrcount + 1),
-                       GFP_KERNEL);
+       indio_dev->event_interface->group.attrs = kcalloc(attrcount + 1,
+                                                         sizeof(indio_dev->event_interface->group.attrs[0]),
+                                                         GFP_KERNEL);
        if (indio_dev->event_interface->group.attrs == NULL) {
                ret = -ENOMEM;
                goto error_free_setup_event_lines;