All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH 08/11] iio: buffer: Move iio_buffer_alloc_sysfs and iio_buffer_free_sysfs
Date: Fri, 12 Dec 2014 10:57:30 +0000	[thread overview]
Message-ID: <548ACA1A.7050209@kernel.org> (raw)
In-Reply-To: <1417024517-7564-9-git-send-email-lars@metafoo.de>

On 26/11/14 17:55, Lars-Peter Clausen wrote:
> The next patch will introduce new dependencies in iio_buffer_alloc_sysfs()
> to functions which are currently defined after iio_buffer_alloc_sysfs(). To
> avoid forward declarations move both iio_buffer_alloc_sysfs() and
> iio_buffer_free_sysfs() after those function.
> 
> This is split into two patches one moving the functions and one adding the
> dependencies to make review of the actual changes easier.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied though naturally I'm now kind of regretting renaming those functions earlier
as I had to chase that change through here. Not exactly challenging but I could
have been lazy and renamed them as a follow up patch ;)

J
> ---
>  drivers/iio/industrialio-buffer.c | 184 +++++++++++++++++++-------------------
>  1 file changed, 91 insertions(+), 93 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index e1906ad..cdc2482 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -383,99 +383,6 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
>  	return ret;
>  }
>  
> -static const char * const iio_scan_elements_group_name = "scan_elements";
> -
> -int iio_buffer_alloc_sysfs(struct iio_dev *indio_dev)
> -{
> -	struct iio_dev_attr *p;
> -	struct attribute **attr;
> -	struct iio_buffer *buffer = indio_dev->buffer;
> -	int ret, i, attrn, attrcount, attrcount_orig = 0;
> -	const struct iio_chan_spec *channels;
> -
> -	if (!buffer)
> -		return 0;
> -
> -	if (buffer->attrs)
> -		indio_dev->groups[indio_dev->groupcounter++] = buffer->attrs;
> -
> -	if (buffer->scan_el_attrs != NULL) {
> -		attr = buffer->scan_el_attrs->attrs;
> -		while (*attr++ != NULL)
> -			attrcount_orig++;
> -	}
> -	attrcount = attrcount_orig;
> -	INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list);
> -	channels = indio_dev->channels;
> -	if (channels) {
> -		/* new magic */
> -		for (i = 0; i < indio_dev->num_channels; i++) {
> -			if (channels[i].scan_index < 0)
> -				continue;
> -
> -			/* Establish necessary mask length */
> -			if (channels[i].scan_index >
> -			    (int)indio_dev->masklength - 1)
> -				indio_dev->masklength
> -					= channels[i].scan_index + 1;
> -
> -			ret = iio_buffer_add_channel_sysfs(indio_dev,
> -							 &channels[i]);
> -			if (ret < 0)
> -				goto error_cleanup_dynamic;
> -			attrcount += ret;
> -			if (channels[i].type == IIO_TIMESTAMP)
> -				indio_dev->scan_index_timestamp =
> -					channels[i].scan_index;
> -		}
> -		if (indio_dev->masklength && buffer->scan_mask == NULL) {
> -			buffer->scan_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
> -						    sizeof(*buffer->scan_mask),
> -						    GFP_KERNEL);
> -			if (buffer->scan_mask == NULL) {
> -				ret = -ENOMEM;
> -				goto error_cleanup_dynamic;
> -			}
> -		}
> -	}
> -
> -	buffer->scan_el_group.name = iio_scan_elements_group_name;
> -
> -	buffer->scan_el_group.attrs = kcalloc(attrcount + 1,
> -					      sizeof(buffer->scan_el_group.attrs[0]),
> -					      GFP_KERNEL);
> -	if (buffer->scan_el_group.attrs == NULL) {
> -		ret = -ENOMEM;
> -		goto error_free_scan_mask;
> -	}
> -	if (buffer->scan_el_attrs)
> -		memcpy(buffer->scan_el_group.attrs, buffer->scan_el_attrs,
> -		       sizeof(buffer->scan_el_group.attrs[0])*attrcount_orig);
> -	attrn = attrcount_orig;
> -
> -	list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l)
> -		buffer->scan_el_group.attrs[attrn++] = &p->dev_attr.attr;
> -	indio_dev->groups[indio_dev->groupcounter++] = &buffer->scan_el_group;
> -
> -	return 0;
> -
> -error_free_scan_mask:
> -	kfree(buffer->scan_mask);
> -error_cleanup_dynamic:
> -	iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
> -
> -	return ret;
> -}
> -
> -void iio_buffer_free_sysfs(struct iio_dev *indio_dev)
> -{
> -	if (!indio_dev->buffer)
> -		return;
> -
> -	kfree(indio_dev->buffer->scan_mask);
> -	kfree(indio_dev->buffer->scan_el_group.attrs);
> -	iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list);
> -}
>  
>  ssize_t iio_buffer_read_length(struct device *dev,
>  			       struct device_attribute *attr,
> @@ -855,6 +762,97 @@ done:
>  }
>  EXPORT_SYMBOL(iio_buffer_store_enable);
>  
> +static const char * const iio_scan_elements_group_name = "scan_elements";
> +
> +int iio_buffer_alloc_sysfs(struct iio_dev *indio_dev)
> +{
> +	struct iio_dev_attr *p;
> +	struct attribute **attr;
> +	struct iio_buffer *buffer = indio_dev->buffer;
> +	int ret, i, attrn, attrcount, attrcount_orig = 0;
> +	const struct iio_chan_spec *channels;
> +
> +	if (!buffer)
> +		return 0;
> +
> +	if (buffer->scan_el_attrs != NULL) {
> +		attr = buffer->scan_el_attrs->attrs;
> +		while (*attr++ != NULL)
> +			attrcount_orig++;
> +	}
> +	attrcount = attrcount_orig;
> +	INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list);
> +	channels = indio_dev->channels;
> +	if (channels) {
> +		/* new magic */
> +		for (i = 0; i < indio_dev->num_channels; i++) {
> +			if (channels[i].scan_index < 0)
> +				continue;
> +
> +			/* Establish necessary mask length */
> +			if (channels[i].scan_index >
> +			    (int)indio_dev->masklength - 1)
> +				indio_dev->masklength
> +					= channels[i].scan_index + 1;
> +
> +			ret = iio_buffer_add_channel_sysfs(indio_dev,
> +							 &channels[i]);
> +			if (ret < 0)
> +				goto error_cleanup_dynamic;
> +			attrcount += ret;
> +			if (channels[i].type == IIO_TIMESTAMP)
> +				indio_dev->scan_index_timestamp =
> +					channels[i].scan_index;
> +		}
> +		if (indio_dev->masklength && buffer->scan_mask == NULL) {
> +			buffer->scan_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength),
> +						    sizeof(*buffer->scan_mask),
> +						    GFP_KERNEL);
> +			if (buffer->scan_mask == NULL) {
> +				ret = -ENOMEM;
> +				goto error_cleanup_dynamic;
> +			}
> +		}
> +	}
> +
> +	buffer->scan_el_group.name = iio_scan_elements_group_name;
> +
> +	buffer->scan_el_group.attrs = kcalloc(attrcount + 1,
> +					      sizeof(buffer->scan_el_group.attrs[0]),
> +					      GFP_KERNEL);
> +	if (buffer->scan_el_group.attrs == NULL) {
> +		ret = -ENOMEM;
> +		goto error_free_scan_mask;
> +	}
> +	if (buffer->scan_el_attrs)
> +		memcpy(buffer->scan_el_group.attrs, buffer->scan_el_attrs,
> +		       sizeof(buffer->scan_el_group.attrs[0])*attrcount_orig);
> +	attrn = attrcount_orig;
> +
> +	list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l)
> +		buffer->scan_el_group.attrs[attrn++] = &p->dev_attr.attr;
> +	indio_dev->groups[indio_dev->groupcounter++] = &buffer->scan_el_group;
> +
> +	return 0;
> +
> +error_free_scan_mask:
> +	kfree(buffer->scan_mask);
> +error_cleanup_dynamic:
> +	iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
> +
> +	return ret;
> +}
> +
> +void iio_buffer_free_sysfs(struct iio_dev *indio_dev)
> +{
> +	if (!indio_dev->buffer)
> +		return;
> +
> +	kfree(indio_dev->buffer->scan_mask);
> +	kfree(indio_dev->buffer->scan_el_group.attrs);
> +	iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list);
> +}
> +
>  /**
>   * iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected
>   * @indio_dev: the iio device
> 


  reply	other threads:[~2014-12-12 10:57 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 17:55 [PATCH 00/11] iio: Buffer cleanups and consolidations Lars-Peter Clausen
2014-11-26 17:55 ` [PATCH 01/11] staging:iio:ad5933: Don't enable channels by default Lars-Peter Clausen
2014-12-04 22:51   ` Daniel Baluta
2014-12-12 10:21     ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 02/11] staging:iio:sca3000: " Lars-Peter Clausen
2014-12-04 22:51   ` Daniel Baluta
2014-12-12 10:22     ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 03/11] iio: Unexport iio_scan_mask_set() Lars-Peter Clausen
2014-12-05  9:53   ` Daniel Baluta
2014-12-12 10:23     ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 04/11] staging:iio:sca3000: Register same channels for device and buffer Lars-Peter Clausen
2014-12-04 22:56   ` Daniel Baluta
2014-12-12 10:28     ` Jonathan Cameron
2014-12-10 22:35   ` Hartmut Knaack
2014-12-12 10:29     ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 05/11] staging:iio:dummy: " Lars-Peter Clausen
2014-12-04 14:27   ` Daniel Baluta
2014-12-12 10:30     ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 06/11] iio: Move buffer registration to the core Lars-Peter Clausen
2014-12-04 14:23   ` Daniel Baluta
2014-12-12 10:49     ` Jonathan Cameron
2014-12-12 10:48   ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 07/11] iio: Remove get_bytes_per_datum() from iio_buffer_access_funcs Lars-Peter Clausen
2014-12-12 10:51   ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 08/11] iio: buffer: Move iio_buffer_alloc_sysfs and iio_buffer_free_sysfs Lars-Peter Clausen
2014-12-12 10:57   ` Jonathan Cameron [this message]
2014-11-26 17:55 ` [PATCH 09/11] iio: buffer: Allocate standard attributes in the core Lars-Peter Clausen
2014-12-10 22:42   ` Hartmut Knaack
2014-12-12 11:06     ` Jonathan Cameron
2014-11-26 17:55 ` [PATCH 10/11] iio: buffer: Make length attribute read only for buffers without set_length Lars-Peter Clausen
2014-12-12 11:08   ` Jonathan Cameron
2014-12-12 11:11     ` Jonathan Cameron
2014-12-18 16:35       ` Lars-Peter Clausen
2014-11-26 17:55 ` [PATCH 11/11] iio: buffer: Drop get_length callback Lars-Peter Clausen
2014-12-12 11:13   ` 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=548ACA1A.7050209@kernel.org \
    --to=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.