staging: iio: Use kasprintf to allocate and fill trig->name
authorJonathan Cameron <jic23@cam.ac.uk>
Sun, 11 Jul 2010 15:39:08 +0000 (16:39 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 22 Jul 2010 18:38:27 +0000 (11:38 -0700)
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/iio/accel/adis16209_trigger.c
drivers/staging/iio/accel/adis16240_trigger.c
drivers/staging/iio/accel/lis3l02dq_ring.c
drivers/staging/iio/gyro/adis16260_trigger.c
drivers/staging/iio/imu/adis16300_trigger.c
drivers/staging/iio/imu/adis16350_trigger.c
drivers/staging/iio/imu/adis16400_trigger.c
drivers/staging/iio/industrialio-trigger.c
drivers/staging/iio/trigger.h
drivers/staging/iio/trigger/iio-trig-gpio.c
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c

index 4a0507c9a13b13af340dca673aad1e693b5eb3b8..cd901a4ca3ffb8afbeec0412753e780b4535ceb7 100644 (file)
@@ -83,14 +83,13 @@ int adis16209_probe_trigger(struct iio_dev *indio_dev)
        struct adis16209_state *st = indio_dev->dev_data;
 
        st->trig = iio_allocate_trigger();
-       st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+       st->trig->name = kasprintf(GFP_KERNEL,
+                                  "adis16209-dev%d",
+                                  indio_dev->id);
        if (!st->trig->name) {
                ret = -ENOMEM;
                goto error_free_trig;
        }
-       snprintf((char *)st->trig->name,
-                IIO_TRIGGER_NAME_LENGTH,
-                "adis16209-dev%d", indio_dev->id);
        st->trig->dev.parent = &st->us->dev;
        st->trig->owner = THIS_MODULE;
        st->trig->private_data = st;
index df1312e17f4b588e2247df98e4c42d02d4d4f5d5..d58b4058688c5196e61b35bc437ab3ff2af3b8dd 100644 (file)
@@ -83,14 +83,13 @@ int adis16240_probe_trigger(struct iio_dev *indio_dev)
        struct adis16240_state *st = indio_dev->dev_data;
 
        st->trig = iio_allocate_trigger();
-       st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+       st->trig->name = kasprintf(GFP_KERNEL,
+                                  "adis16240-dev%d",
+                                  indio_dev->id);
        if (!st->trig->name) {
                ret = -ENOMEM;
                goto error_free_trig;
        }
-       snprintf((char *)st->trig->name,
-                IIO_TRIGGER_NAME_LENGTH,
-                "adis16240-dev%d", indio_dev->id);
        st->trig->dev.parent = &st->us->dev;
        st->trig->owner = THIS_MODULE;
        st->trig->private_data = st;
index 6b0b124b11ce92ccd119c49399983a6caebfd993..a33599dddddd9297d4b95a5ad960ab027d48ad46 100644 (file)
@@ -495,14 +495,14 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
        if (!state->trig)
                return -ENOMEM;
 
-       state->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+       state->trig->name = kasprintf(GFP_KERNEL,
+                                     "lis3l02dq-dev%d",
+                                     indio_dev->id);
        if (!state->trig->name) {
                ret = -ENOMEM;
                goto error_free_trig;
        }
-       snprintf((char *)state->trig->name,
-                IIO_TRIGGER_NAME_LENGTH,
-                "lis3l02dq-dev%d", indio_dev->id);
+
        state->trig->dev.parent = &state->us->dev;
        state->trig->owner = THIS_MODULE;
        state->trig->private_data = state;
index b3c565942b8d3f5bd5206b121a7e3a319e2ac9bf..54afd9e047f3aa62dbbd0b5293a6c9cadcd9064d 100644 (file)
@@ -83,14 +83,13 @@ int adis16260_probe_trigger(struct iio_dev *indio_dev)
        struct adis16260_state *st = indio_dev->dev_data;
 
        st->trig = iio_allocate_trigger();
-       st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+       st->trig->name = kasprintf(GFP_KERNEL,
+                                  "adis16260-dev%d",
+                                  indio_dev->id);
        if (!st->trig->name) {
                ret = -ENOMEM;
                goto error_free_trig;
        }
-       snprintf((char *)st->trig->name,
-                IIO_TRIGGER_NAME_LENGTH,
-                "adis16260-dev%d", indio_dev->id);
        st->trig->dev.parent = &st->us->dev;
        st->trig->owner = THIS_MODULE;
        st->trig->private_data = st;
index 54edb20bf119d8739f117e08754b3adb86e30741..a55f383bea220529d3285aadb25270ce912639d9 100644 (file)
@@ -86,14 +86,13 @@ int adis16300_probe_trigger(struct iio_dev *indio_dev)
        struct adis16300_state *st = indio_dev->dev_data;
 
        st->trig = iio_allocate_trigger();
-       st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+       st->trig->name = kasprintf(GFP_KERNEL,
+                                  "adis16300-dev%d",
+                                  indio_dev->id);
        if (!st->trig->name) {
                ret = -ENOMEM;
                goto error_free_trig;
        }
-       snprintf((char *)st->trig->name,
-                IIO_TRIGGER_NAME_LENGTH,
-                "adis16300-dev%d", indio_dev->id);
        st->trig->dev.parent = &st->us->dev;
        st->trig->owner = THIS_MODULE;
        st->trig->private_data = st;
index 1ffa75d05fac31ef22945129a4f0ab09253ae5b7..fbe246a4cdb575ffb9876b51e18d1947e2814bab 100644 (file)
@@ -86,14 +86,13 @@ int adis16350_probe_trigger(struct iio_dev *indio_dev)
        struct adis16350_state *st = indio_dev->dev_data;
 
        st->trig = iio_allocate_trigger();
-       st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+       st->trig->name = kasprintf(GFP_KERNEL,
+                                  "adis16350-dev%d",
+                                  indio_dev->id);
        if (!st->trig->name) {
                ret = -ENOMEM;
                goto error_free_trig;
        }
-       snprintf((char *)st->trig->name,
-                IIO_TRIGGER_NAME_LENGTH,
-                "adis16350-dev%d", indio_dev->id);
        st->trig->dev.parent = &st->us->dev;
        st->trig->owner = THIS_MODULE;
        st->trig->private_data = st;
index 3b3250ac76804697f3e7a746e745fe09f8409f6d..bf7c60383dd3bbdc81c2c4f6c3c512e4948ac0ef 100644 (file)
@@ -86,14 +86,13 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev)
        struct adis16400_state *st = indio_dev->dev_data;
 
        st->trig = iio_allocate_trigger();
-       st->trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+       st->trig->name = kasprintf(GFP_KERNEL,
+                                  "adis16400-dev%d",
+                                  indio_dev->id);
        if (!st->trig->name) {
                ret = -ENOMEM;
                goto error_free_trig;
        }
-       snprintf((char *)st->trig->name,
-                IIO_TRIGGER_NAME_LENGTH,
-                "adis16400-dev%d", indio_dev->id);
        st->trig->dev.parent = &st->us->dev;
        st->trig->owner = THIS_MODULE;
        st->trig->private_data = st;
index ef088a4ce5b7c76ab271fea60f5a1dfdb9aa0c9a..92e6006622db7c265edadd319fdbac25b9154cd5 100644 (file)
@@ -295,10 +295,9 @@ static ssize_t iio_trigger_read_current(struct device *dev,
        struct iio_dev *dev_info = dev_get_drvdata(dev);
        int len = 0;
        if (dev_info->trig)
-               len = snprintf(buf,
-                              IIO_TRIGGER_NAME_LENGTH,
-                              "%s\n",
-                              dev_info->trig->name);
+               len = sprintf(buf,
+                             "%s\n",
+                             dev_info->trig->name);
        return len;
 }
 
@@ -323,8 +322,6 @@ static ssize_t iio_trigger_write_current(struct device *dev,
        }
        mutex_unlock(&dev_info->mlock);
 
-       len = len < IIO_TRIGGER_NAME_LENGTH ? len : IIO_TRIGGER_NAME_LENGTH;
-
        dev_info->trig = iio_trigger_find_by_name(buf, len);
        if (oldtrig && dev_info->trig != oldtrig)
                iio_put_trigger(oldtrig);
index 784e7b6fac1cc745157746ca632b288861296684..89610b54e114de67fa37f285c53fbf57a8780497 100644 (file)
@@ -8,10 +8,6 @@
  */
 #ifndef _IIO_TRIGGER_H_
 #define _IIO_TRIGGER_H_
-#define IIO_TRIGGER_NAME_LENGTH 20
-#define IIO_TRIGGER_ID_PREFIX "iio:trigger"
-#define IIO_TRIGGER_ID_FORMAT IIO_TRIGGER_ID_PREFIX "%d"
-
 
 /**
  * struct iio_trigger - industrial I/O trigger device
index 1da285d28632a611eb0a930f71c7aeeffae445f8..3c0614eff72c8c706d7c553889653f09d7ea1080 100644 (file)
@@ -93,16 +93,11 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev)
                        trig->private_data = trig_info;
                        trig_info->irq = irq;
                        trig->owner = THIS_MODULE;
-                       trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH,
-                                       GFP_KERNEL);
-                       if (!trig->name) {
+                       trig->name = kasprintf(GFP_KERNEL, "irqtrig%d", irq);
+                       if (trig->name == NULL) {
                                ret = -ENOMEM;
                                goto error_free_trig_info;
                        }
-                       snprintf((char *)trig->name,
-                                IIO_TRIGGER_NAME_LENGTH,
-                                "irqtrig%d", irq);
-
                        ret = request_irq(irq, iio_gpio_trigger_poll,
                                          irqflags, trig->name, trig);
                        if (ret) {
index 4ee3ae1ef8923a1ad1cbddc70e2693aa42870798..d8c58cbfce796b49f48ac485a24c56863bfe79ae 100644 (file)
@@ -25,7 +25,6 @@ static DEFINE_MUTEX(iio_prtc_trigger_list_lock);
 struct iio_prtc_trigger_info {
        struct rtc_device *rtc;
        int frequency;
-       char *name;
        struct rtc_task task;
 };
 
@@ -78,8 +77,7 @@ static ssize_t iio_trig_periodic_read_name(struct device *dev,
                                           char *buf)
 {
        struct iio_trigger *trig = dev_get_drvdata(dev);
-       struct iio_prtc_trigger_info *trig_info = trig->private_data;
-       return sprintf(buf, "%s\n", trig_info->name);
+       return sprintf(buf, "%s\n", trig->name);
 }
 
 static DEVICE_ATTR(name, S_IRUGO,
@@ -129,16 +127,12 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
                trig->private_data = trig_info;
                trig->owner = THIS_MODULE;
                trig->set_trigger_state = &iio_trig_periodic_rtc_set_state;
-               trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
+               trig->name = kasprintf(GFP_KERNEL, "periodic%s", pdata[i]);
                if (trig->name == NULL) {
                        ret = -ENOMEM;
                        goto error_free_trig_info;
                }
-               snprintf((char *)trig->name,
-                        IIO_TRIGGER_NAME_LENGTH,
-                        "periodic%s",
-                        pdata[i]);
-               trig_info->name = (char *)trig->name;
+
                /* RTC access */
                trig_info->rtc
                        = rtc_class_open(pdata[i]);