Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1405570

[RFC 6/7] iio: Refuse to register triggers with duplicate names

From Crestez Dan Leonard <leonard.crestez@intel.com>
Newsgroups linux.kernel
Subject [RFC 6/7] iio: Refuse to register triggers with duplicate names
Date 2016-05-23 20:50 +0200
Message-ID <rC35o-13f-11@gated-at.bofh.it> (permalink)
References <rC35n-13f-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


The trigger name is documented as unique but drivers are currently
allowed to register triggers with duplicate names. This should be
considered a bug since it makes the 'current_trigger' interface
unusable.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
---
 drivers/iio/industrialio-trigger.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index e79c64c..e77503c 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -64,6 +64,8 @@ static struct attribute *iio_trig_dev_attrs[] = {
 };
 ATTRIBUTE_GROUPS(iio_trig_dev);
 
+static struct iio_trigger *__iio_trigger_find_by_name(const char *name);
+
 int iio_trigger_register(struct iio_trigger *trig_info)
 {
 	int ret;
@@ -82,11 +84,18 @@ int iio_trigger_register(struct iio_trigger *trig_info)
 
 	/* Add to list of available triggers held by the IIO core */
 	mutex_lock(&iio_trigger_list_lock);
+	if (__iio_trigger_find_by_name(trig_info->name)) {
+		pr_err("Duplicate trigger name '%s'\n", trig_info->name);
+		ret = -EEXIST;
+		goto error_device_del;
+	}
 	list_add_tail(&trig_info->list, &iio_trigger_list);
 	mutex_unlock(&iio_trigger_list_lock);
 
 	return 0;
 
+error_device_del:
+	device_del(&trig_info->dev);
 error_unregister_id:
 	ida_simple_remove(&iio_trigger_ida, trig_info->id);
 	return ret;
@@ -105,6 +114,18 @@ void iio_trigger_unregister(struct iio_trigger *trig_info)
 }
 EXPORT_SYMBOL(iio_trigger_unregister);
 
+/* Search for trigger by name, assuming iio_trigger_list_lock held */
+static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
+{
+	struct iio_trigger *iter;
+
+	list_for_each_entry(iter, &iio_trigger_list, list)
+		if (!strcmp(iter->name, name))
+			return iter;
+
+	return NULL;
+}
+
 static struct iio_trigger *iio_trigger_find_by_name(const char *name,
 						    size_t len)
 {
-- 
2.5.5

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[RFC 6/7] iio: Refuse to register triggers with duplicate names Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-05-23 20:50 +0200
  Re: [RFC 6/7] iio: Refuse to register triggers with duplicate names Jonathan Cameron <jic23@kernel.org> - 2016-05-29 21:50 +0200
    Re: [RFC 6/7] iio: Refuse to register triggers with duplicate names Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-05-30 15:00 +0200

csiph-web