iio: accel: bma400: Fix the scale min and max macro values
[platform/kernel/linux-rpi.git] / drivers / iio / industrialio-core.c
index 2dbb37e..a7f5d43 100644 (file)
@@ -818,7 +818,23 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals,
 
 static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
 {
-       return iio_format_list(buf, vals, type, 3, "[", "]");
+       int length;
+
+       /*
+        * length refers to the array size , not the number of elements.
+        * The purpose is to print the range [min , step ,max] so length should
+        * be 3 in case of int, and 6 for other types.
+        */
+       switch (type) {
+       case IIO_VAL_INT:
+               length = 3;
+               break;
+       default:
+               length = 6;
+               break;
+       }
+
+       return iio_format_list(buf, vals, type, length, "[", "]");
 }
 
 static ssize_t iio_read_channel_info_avail(struct device *dev,
@@ -1600,6 +1616,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
        kfree(iio_dev_opaque->chan_attr_group.attrs);
        iio_dev_opaque->chan_attr_group.attrs = NULL;
        kfree(iio_dev_opaque->groups);
+       iio_dev_opaque->groups = NULL;
 }
 
 static void iio_dev_release(struct device *device)
@@ -1664,7 +1681,13 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
                kfree(iio_dev_opaque);
                return NULL;
        }
-       dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id);
+
+       if (dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id)) {
+               ida_simple_remove(&iio_ida, iio_dev_opaque->id);
+               kfree(iio_dev_opaque);
+               return NULL;
+       }
+
        INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
        INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers);