linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <jic23@cam.ac.uk>, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio:trigger: Register sysfs file statically
Date: Sun, 08 Jul 2012 09:56:16 +0100	[thread overview]
Message-ID: <4FF94B30.5070401@kernel.org> (raw)
In-Reply-To: <1341478626-29167-1-git-send-email-lars@metafoo.de>

On 07/05/2012 09:57 AM, Lars-Peter Clausen wrote:
> The name sysfs attribute is the same for all triggers, so there is no need to
> register them dynamically at runtime. Create a attribute group for it and set it
> up for the bus attribute group. This also avoids a possible race condition
> where the uevent for the device is sent before the name sysfs attribute has been
> added.
Hmm. I thought this wouldn't work having run into problems before
with initializing sysfs groups twice. Afterall we poke the same group in
via the groups bit of device when creating these.  It appears this
particular combination is fine though as it doesn't have to create a
directory (which is where issues otherwise occur).  Nice clean up.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
merged.
> ---
>  drivers/iio/industrialio-trigger.c |   38 ++++++++++++------------------------
>  1 file changed, 13 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> index ec653fb..24ed31f 100644
> --- a/drivers/iio/industrialio-trigger.c
> +++ b/drivers/iio/industrialio-trigger.c
> @@ -51,25 +51,19 @@ static ssize_t iio_trigger_read_name(struct device *dev,
>  
>  static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
>  
> -/**
> - * iio_trigger_register_sysfs() - create a device for this trigger
> - * @trig_info:	the trigger
> - *
> - * Also adds any control attribute registered by the trigger driver
> - **/
> -static int iio_trigger_register_sysfs(struct iio_trigger *trig_info)
> -{
> -	return sysfs_add_file_to_group(&trig_info->dev.kobj,
> -				       &dev_attr_name.attr,
> -				       NULL);
> -}
> +static struct attribute *iio_trig_dev_attrs[] = {
> +	&dev_attr_name.attr,
> +	NULL,
> +};
>  
> -static void iio_trigger_unregister_sysfs(struct iio_trigger *trig_info)
> -{
> -	sysfs_remove_file_from_group(&trig_info->dev.kobj,
> -					   &dev_attr_name.attr,
> -					   NULL);
> -}
> +static struct attribute_group iio_trig_attr_group = {
> +	.attrs	= iio_trig_dev_attrs,
> +};
> +
> +static const struct attribute_group *iio_trig_attr_groups[] = {
> +	&iio_trig_attr_group,
> +	NULL
> +};
>  
>  int iio_trigger_register(struct iio_trigger *trig_info)
>  {
> @@ -88,10 +82,6 @@ int iio_trigger_register(struct iio_trigger *trig_info)
>  	if (ret)
>  		goto error_unregister_id;
>  
> -	ret = iio_trigger_register_sysfs(trig_info);
> -	if (ret)
> -		goto error_device_del;
> -
>  	/* Add to list of available triggers held by the IIO core */
>  	mutex_lock(&iio_trigger_list_lock);
>  	list_add_tail(&trig_info->list, &iio_trigger_list);
> @@ -99,8 +89,6 @@ int iio_trigger_register(struct iio_trigger *trig_info)
>  
>  	return 0;
>  
> -error_device_del:
> -	device_del(&trig_info->dev);
>  error_unregister_id:
>  	ida_simple_remove(&iio_trigger_ida, trig_info->id);
>  error_ret:
> @@ -114,7 +102,6 @@ void iio_trigger_unregister(struct iio_trigger *trig_info)
>  	list_del(&trig_info->list);
>  	mutex_unlock(&iio_trigger_list_lock);
>  
> -	iio_trigger_unregister_sysfs(trig_info);
>  	ida_simple_remove(&iio_trigger_ida, trig_info->id);
>  	/* Possible issue in here */
>  	device_unregister(&trig_info->dev);
> @@ -406,6 +393,7 @@ static void iio_trig_release(struct device *device)
>  
>  static struct device_type iio_trig_type = {
>  	.release = iio_trig_release,
> +	.groups = iio_trig_attr_groups,
>  };
>  
>  static void iio_trig_subirqmask(struct irq_data *d)
> 

      reply	other threads:[~2012-07-08  8:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05  8:57 [PATCH] iio:trigger: Register sysfs file statically Lars-Peter Clausen
2012-07-08  8:56 ` Jonathan Cameron [this message]

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=4FF94B30.5070401@kernel.org \
    --to=jic23@kernel.org \
    --cc=jic23@cam.ac.uk \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).