mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Crestez Dan Leonard <leonard.crestez@intel.com>,
	linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Daniel Baluta <daniel.baluta@intel.com>
Subject: Re: [RFC 6/7] iio: Refuse to register triggers with duplicate names
Date: Sun, 29 May 2016 20:48:57 +0100	[thread overview]
Message-ID: <08913c84-b83f-8163-c766-5935a202b3c2@kernel.org> (raw)
In-Reply-To: <643ac0601a74fadc842ccb83c8f3741293ef7299.1464027859.git.leonard.crestez@intel.com>

On 23/05/16 19:40, Crestez Dan Leonard wrote:
> 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>
This feels like the right approach to my mind (and should have been there
all along - oops).

However, we do need to avoid breaking userspace. It's ugly but for those 3 drivers
can we assume that using more than one on a board was impossible before this series
and as such play a slight game in which we don't change the trigger name they
are exporting, unless that name is already in use?

It's ugly but it gets us the nicest solution for all drivers for a bit of ugly in
3 of them...

Jonathan
> ---
>  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)
>  {
> 

  reply	other threads:[~2016-05-29 19:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23 18:39 [RFC 0/7] Deal with iio trigger names Crestez Dan Leonard
2016-05-23 18:39 ` [PATCHv3 1/7] iio: generic_buffer: Cleanup when receiving signals Crestez Dan Leonard
2016-05-29 19:38   ` Jonathan Cameron
2016-05-23 18:39 ` [PATCHv3 2/7] iio: generic_buffer: Add --device-num option Crestez Dan Leonard
2016-05-29 19:41   ` Jonathan Cameron
2016-05-23 18:39 ` [PATCHv3 3/7] iio: generic_buffer: Add --trigger-num option Crestez Dan Leonard
2016-05-29 19:43   ` Jonathan Cameron
2016-05-23 18:39 ` [RFC 4/7] iio: Add current_trigger_id alternative Crestez Dan Leonard
2016-05-31 14:11   ` Lars-Peter Clausen
2016-05-23 18:40 ` [RFC 5/7] iio: generic_buffer: Use current_trigger_id Crestez Dan Leonard
2016-05-23 18:40 ` [RFC 6/7] iio: Refuse to register triggers with duplicate names Crestez Dan Leonard
2016-05-29 19:48   ` Jonathan Cameron [this message]
2016-05-30 12:49     ` Crestez Dan Leonard
2016-05-31 14:03       ` Lars-Peter Clausen
2016-06-11 16:55         ` Jonathan Cameron
2016-05-23 18:40 ` [RFC 7/7] iio: Make trigger names unique Crestez Dan Leonard
2016-05-29 19:44 ` [RFC 0/7] Deal with iio trigger names Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08913c84-b83f-8163-c766-5935a202b3c2@kernel.org \
    --to=jic23@kernel.org \
    --cc=daniel.baluta@intel.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=leonard.crestez@intel.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®