Commit 3c9bbf58 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging: iio: Use kasprintf to allocate and fill trig->name

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent cb46f472
...@@ -83,14 +83,13 @@ int adis16209_probe_trigger(struct iio_dev *indio_dev) ...@@ -83,14 +83,13 @@ int adis16209_probe_trigger(struct iio_dev *indio_dev)
struct adis16209_state *st = indio_dev->dev_data; struct adis16209_state *st = indio_dev->dev_data;
st->trig = iio_allocate_trigger(); 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) { if (!st->trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig; 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->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = st;
......
...@@ -83,14 +83,13 @@ int adis16240_probe_trigger(struct iio_dev *indio_dev) ...@@ -83,14 +83,13 @@ int adis16240_probe_trigger(struct iio_dev *indio_dev)
struct adis16240_state *st = indio_dev->dev_data; struct adis16240_state *st = indio_dev->dev_data;
st->trig = iio_allocate_trigger(); 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) { if (!st->trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig; 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->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = st;
......
...@@ -495,14 +495,14 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev) ...@@ -495,14 +495,14 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
if (!state->trig) if (!state->trig)
return -ENOMEM; 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) { if (!state->trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig; 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->dev.parent = &state->us->dev;
state->trig->owner = THIS_MODULE; state->trig->owner = THIS_MODULE;
state->trig->private_data = state; state->trig->private_data = state;
......
...@@ -83,14 +83,13 @@ int adis16260_probe_trigger(struct iio_dev *indio_dev) ...@@ -83,14 +83,13 @@ int adis16260_probe_trigger(struct iio_dev *indio_dev)
struct adis16260_state *st = indio_dev->dev_data; struct adis16260_state *st = indio_dev->dev_data;
st->trig = iio_allocate_trigger(); 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) { if (!st->trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig; 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->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = st;
......
...@@ -86,14 +86,13 @@ int adis16300_probe_trigger(struct iio_dev *indio_dev) ...@@ -86,14 +86,13 @@ int adis16300_probe_trigger(struct iio_dev *indio_dev)
struct adis16300_state *st = indio_dev->dev_data; struct adis16300_state *st = indio_dev->dev_data;
st->trig = iio_allocate_trigger(); 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) { if (!st->trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig; 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->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = st;
......
...@@ -86,14 +86,13 @@ int adis16350_probe_trigger(struct iio_dev *indio_dev) ...@@ -86,14 +86,13 @@ int adis16350_probe_trigger(struct iio_dev *indio_dev)
struct adis16350_state *st = indio_dev->dev_data; struct adis16350_state *st = indio_dev->dev_data;
st->trig = iio_allocate_trigger(); 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) { if (!st->trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig; 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->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = st;
......
...@@ -86,14 +86,13 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev) ...@@ -86,14 +86,13 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev)
struct adis16400_state *st = indio_dev->dev_data; struct adis16400_state *st = indio_dev->dev_data;
st->trig = iio_allocate_trigger(); 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) { if (!st->trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig; 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->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = st;
......
...@@ -295,10 +295,9 @@ static ssize_t iio_trigger_read_current(struct device *dev, ...@@ -295,10 +295,9 @@ static ssize_t iio_trigger_read_current(struct device *dev,
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
int len = 0; int len = 0;
if (dev_info->trig) if (dev_info->trig)
len = snprintf(buf, len = sprintf(buf,
IIO_TRIGGER_NAME_LENGTH, "%s\n",
"%s\n", dev_info->trig->name);
dev_info->trig->name);
return len; return len;
} }
...@@ -323,8 +322,6 @@ static ssize_t iio_trigger_write_current(struct device *dev, ...@@ -323,8 +322,6 @@ static ssize_t iio_trigger_write_current(struct device *dev,
} }
mutex_unlock(&dev_info->mlock); 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); dev_info->trig = iio_trigger_find_by_name(buf, len);
if (oldtrig && dev_info->trig != oldtrig) if (oldtrig && dev_info->trig != oldtrig)
iio_put_trigger(oldtrig); iio_put_trigger(oldtrig);
......
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
*/ */
#ifndef _IIO_TRIGGER_H_ #ifndef _IIO_TRIGGER_H_
#define _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 * struct iio_trigger - industrial I/O trigger device
......
...@@ -93,16 +93,11 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev) ...@@ -93,16 +93,11 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev)
trig->private_data = trig_info; trig->private_data = trig_info;
trig_info->irq = irq; trig_info->irq = irq;
trig->owner = THIS_MODULE; trig->owner = THIS_MODULE;
trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, trig->name = kasprintf(GFP_KERNEL, "irqtrig%d", irq);
GFP_KERNEL); if (trig->name == NULL) {
if (!trig->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig_info; goto error_free_trig_info;
} }
snprintf((char *)trig->name,
IIO_TRIGGER_NAME_LENGTH,
"irqtrig%d", irq);
ret = request_irq(irq, iio_gpio_trigger_poll, ret = request_irq(irq, iio_gpio_trigger_poll,
irqflags, trig->name, trig); irqflags, trig->name, trig);
if (ret) { if (ret) {
......
...@@ -25,7 +25,6 @@ static DEFINE_MUTEX(iio_prtc_trigger_list_lock); ...@@ -25,7 +25,6 @@ static DEFINE_MUTEX(iio_prtc_trigger_list_lock);
struct iio_prtc_trigger_info { struct iio_prtc_trigger_info {
struct rtc_device *rtc; struct rtc_device *rtc;
int frequency; int frequency;
char *name;
struct rtc_task task; struct rtc_task task;
}; };
...@@ -78,8 +77,7 @@ static ssize_t iio_trig_periodic_read_name(struct device *dev, ...@@ -78,8 +77,7 @@ static ssize_t iio_trig_periodic_read_name(struct device *dev,
char *buf) char *buf)
{ {
struct iio_trigger *trig = dev_get_drvdata(dev); struct iio_trigger *trig = dev_get_drvdata(dev);
struct iio_prtc_trigger_info *trig_info = trig->private_data; return sprintf(buf, "%s\n", trig->name);
return sprintf(buf, "%s\n", trig_info->name);
} }
static DEVICE_ATTR(name, S_IRUGO, static DEVICE_ATTR(name, S_IRUGO,
...@@ -129,16 +127,12 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev) ...@@ -129,16 +127,12 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
trig->private_data = trig_info; trig->private_data = trig_info;
trig->owner = THIS_MODULE; trig->owner = THIS_MODULE;
trig->set_trigger_state = &iio_trig_periodic_rtc_set_state; 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) { if (trig->name == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_trig_info; 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 */ /* RTC access */
trig_info->rtc trig_info->rtc
= rtc_class_open(pdata[i]); = rtc_class_open(pdata[i]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment