diff mbox series

[RFC,09/14] iio: buffer: split buffer sysfs creation to take buffer as primary arg

Message ID 20200508135348.15229-10-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: buffer: add support for multiple buffers | expand

Commit Message

Alexandru Ardelean May 8, 2020, 1:53 p.m. UTC
Currently the iio_buffer_{alloc,free}_sysfs_and_mask() take 'indio_dev' as
primary argument. This change converts to take an IIO buffer as a primary
argument.

That will allow the functions to get called for multiple buffers.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/industrialio-buffer.c | 46 ++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 16 deletions(-)

Comments

Jonathan Cameron May 24, 2020, 4:49 p.m. UTC | #1
On Fri, 8 May 2020 16:53:43 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> Currently the iio_buffer_{alloc,free}_sysfs_and_mask() take 'indio_dev' as
> primary argument. This change converts to take an IIO buffer as a primary
> argument.
> 
> That will allow the functions to get called for multiple buffers.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

Looks good to me.  We'll need this whatever the interface ends up being as
need the separate control infrastructure.

Jonathan

> ---
>  drivers/iio/industrialio-buffer.c | 46 ++++++++++++++++++++-----------
>  1 file changed, 30 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index e7a847e7b103..6b1b5d5387bd 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1312,26 +1312,14 @@ static struct attribute *iio_buffer_attrs[] = {
>  	&dev_attr_data_available.attr,
>  };
>  
> -int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
> +static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer)
>  {
> +	struct iio_dev *indio_dev = buffer->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;
>  
> -	channels = indio_dev->channels;
> -	if (channels) {
> -		int ml = indio_dev->masklength;
> -
> -		for (i = 0; i < indio_dev->num_channels; i++)
> -			ml = max(ml, channels[i].scan_index + 1);
> -		indio_dev->masklength = ml;
> -	}
> -
> -	if (!buffer)
> -		return 0;
> -
>  	attrcount = 0;
>  	if (buffer->attrs) {
>  		while (buffer->attrs[attrcount] != NULL)
> @@ -1411,19 +1399,45 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
>  	return ret;
>  }
>  
> -void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
> +int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
>  {
>  	struct iio_buffer *buffer = indio_dev->buffer;
> +	const struct iio_chan_spec *channels;
> +	int i;
> +
> +	channels = indio_dev->channels;
> +	if (channels) {
> +		int ml = indio_dev->masklength;
> +
> +		for (i = 0; i < indio_dev->num_channels; i++)
> +			ml = max(ml, channels[i].scan_index + 1);
> +		indio_dev->masklength = ml;
> +	}
>  
>  	if (!buffer)
> -		return;
> +		return 0;
> +
> +	return __iio_buffer_alloc_sysfs_and_mask(buffer);
> +}
>  
> +static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer)
> +{
>  	iio_buffer_free_scanmask(buffer);
>  	kfree(buffer->buffer_group.attrs);
>  	kfree(buffer->scan_el_group.attrs);
>  	iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
>  }
>  
> +void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
> +{
> +	struct iio_buffer *buffer = indio_dev->buffer;
> +
> +	if (!buffer)
> +		return;
> +
> +	__iio_buffer_free_sysfs_and_mask(buffer);
> +}
> +
>  static const struct file_operations iio_buffer_fileops = {
>  	.read = iio_buffer_read_outer,
>  	.release = iio_buffer_chrdev_release,
Alexandru Ardelean May 25, 2020, 7:28 a.m. UTC | #2
On Sun, 2020-05-24 at 17:49 +0100, Jonathan Cameron wrote:
> [External]
> 
> On Fri, 8 May 2020 16:53:43 +0300
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> 
> > Currently the iio_buffer_{alloc,free}_sysfs_and_mask() take 'indio_dev' as
> > primary argument. This change converts to take an IIO buffer as a primary
> > argument.
> > 
> > That will allow the functions to get called for multiple buffers.
> > 
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> 
> Looks good to me.  We'll need this whatever the interface ends up being as
> need the separate control infrastructure.

I was wanting to split this into it's own patch at some point and send it now.
I'll probably do it.

> 
> Jonathan
> 
> > ---
> >  drivers/iio/industrialio-buffer.c | 46 ++++++++++++++++++++-----------
> >  1 file changed, 30 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-
> > buffer.c
> > index e7a847e7b103..6b1b5d5387bd 100644
> > --- a/drivers/iio/industrialio-buffer.c
> > +++ b/drivers/iio/industrialio-buffer.c
> > @@ -1312,26 +1312,14 @@ static struct attribute *iio_buffer_attrs[] = {
> >  	&dev_attr_data_available.attr,
> >  };
> >  
> > -int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
> > +static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer)
> >  {
> > +	struct iio_dev *indio_dev = buffer->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;
> >  
> > -	channels = indio_dev->channels;
> > -	if (channels) {
> > -		int ml = indio_dev->masklength;
> > -
> > -		for (i = 0; i < indio_dev->num_channels; i++)
> > -			ml = max(ml, channels[i].scan_index + 1);
> > -		indio_dev->masklength = ml;
> > -	}
> > -
> > -	if (!buffer)
> > -		return 0;
> > -
> >  	attrcount = 0;
> >  	if (buffer->attrs) {
> >  		while (buffer->attrs[attrcount] != NULL)
> > @@ -1411,19 +1399,45 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev
> > *indio_dev)
> >  	return ret;
> >  }
> >  
> > -void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
> > +int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
> >  {
> >  	struct iio_buffer *buffer = indio_dev->buffer;
> > +	const struct iio_chan_spec *channels;
> > +	int i;
> > +
> > +	channels = indio_dev->channels;
> > +	if (channels) {
> > +		int ml = indio_dev->masklength;
> > +
> > +		for (i = 0; i < indio_dev->num_channels; i++)
> > +			ml = max(ml, channels[i].scan_index + 1);
> > +		indio_dev->masklength = ml;
> > +	}
> >  
> >  	if (!buffer)
> > -		return;
> > +		return 0;
> > +
> > +	return __iio_buffer_alloc_sysfs_and_mask(buffer);
> > +}
> >  
> > +static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer)
> > +{
> >  	iio_buffer_free_scanmask(buffer);
> >  	kfree(buffer->buffer_group.attrs);
> >  	kfree(buffer->scan_el_group.attrs);
> >  	iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
> >  }
> >  
> > +void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
> > +{
> > +	struct iio_buffer *buffer = indio_dev->buffer;
> > +
> > +	if (!buffer)
> > +		return;
> > +
> > +	__iio_buffer_free_sysfs_and_mask(buffer);
> > +}
> > +
> >  static const struct file_operations iio_buffer_fileops = {
> >  	.read = iio_buffer_read_outer,
> >  	.release = iio_buffer_chrdev_release,
Jonathan Cameron May 31, 2020, 3:21 p.m. UTC | #3
On Mon, 25 May 2020 07:28:18 +0000
"Ardelean, Alexandru" <alexandru.Ardelean@analog.com> wrote:

> On Sun, 2020-05-24 at 17:49 +0100, Jonathan Cameron wrote:
> > [External]
> > 
> > On Fri, 8 May 2020 16:53:43 +0300
> > Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> >   
> > > Currently the iio_buffer_{alloc,free}_sysfs_and_mask() take 'indio_dev' as
> > > primary argument. This change converts to take an IIO buffer as a primary
> > > argument.
> > > 
> > > That will allow the functions to get called for multiple buffers.
> > > 
> > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>  
> > 
> > Looks good to me.  We'll need this whatever the interface ends up being as
> > need the separate control infrastructure.  
> 
> I was wanting to split this into it's own patch at some point and send it now.
> I'll probably do it.

Great.
> 
> > 
> > Jonathan
> >   
> > > ---
> > >  drivers/iio/industrialio-buffer.c | 46 ++++++++++++++++++++-----------
> > >  1 file changed, 30 insertions(+), 16 deletions(-)
> > > 
> > > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-
> > > buffer.c
> > > index e7a847e7b103..6b1b5d5387bd 100644
> > > --- a/drivers/iio/industrialio-buffer.c
> > > +++ b/drivers/iio/industrialio-buffer.c
> > > @@ -1312,26 +1312,14 @@ static struct attribute *iio_buffer_attrs[] = {
> > >  	&dev_attr_data_available.attr,
> > >  };
> > >  
> > > -int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
> > > +static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer)
> > >  {
> > > +	struct iio_dev *indio_dev = buffer->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;
> > >  
> > > -	channels = indio_dev->channels;
> > > -	if (channels) {
> > > -		int ml = indio_dev->masklength;
> > > -
> > > -		for (i = 0; i < indio_dev->num_channels; i++)
> > > -			ml = max(ml, channels[i].scan_index + 1);
> > > -		indio_dev->masklength = ml;
> > > -	}
> > > -
> > > -	if (!buffer)
> > > -		return 0;
> > > -
> > >  	attrcount = 0;
> > >  	if (buffer->attrs) {
> > >  		while (buffer->attrs[attrcount] != NULL)
> > > @@ -1411,19 +1399,45 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev
> > > *indio_dev)
> > >  	return ret;
> > >  }
> > >  
> > > -void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
> > > +int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
> > >  {
> > >  	struct iio_buffer *buffer = indio_dev->buffer;
> > > +	const struct iio_chan_spec *channels;
> > > +	int i;
> > > +
> > > +	channels = indio_dev->channels;
> > > +	if (channels) {
> > > +		int ml = indio_dev->masklength;
> > > +
> > > +		for (i = 0; i < indio_dev->num_channels; i++)
> > > +			ml = max(ml, channels[i].scan_index + 1);
> > > +		indio_dev->masklength = ml;
> > > +	}
> > >  
> > >  	if (!buffer)
> > > -		return;
> > > +		return 0;
> > > +
> > > +	return __iio_buffer_alloc_sysfs_and_mask(buffer);
> > > +}
> > >  
> > > +static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer)
> > > +{
> > >  	iio_buffer_free_scanmask(buffer);
> > >  	kfree(buffer->buffer_group.attrs);
> > >  	kfree(buffer->scan_el_group.attrs);
> > >  	iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
> > >  }
> > >  
> > > +void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
> > > +{
> > > +	struct iio_buffer *buffer = indio_dev->buffer;
> > > +
> > > +	if (!buffer)
> > > +		return;
> > > +
> > > +	__iio_buffer_free_sysfs_and_mask(buffer);
> > > +}
> > > +
> > >  static const struct file_operations iio_buffer_fileops = {
> > >  	.read = iio_buffer_read_outer,
> > >  	.release = iio_buffer_chrdev_release,
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index e7a847e7b103..6b1b5d5387bd 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1312,26 +1312,14 @@  static struct attribute *iio_buffer_attrs[] = {
 	&dev_attr_data_available.attr,
 };
 
-int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
+static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer)
 {
+	struct iio_dev *indio_dev = buffer->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;
 
-	channels = indio_dev->channels;
-	if (channels) {
-		int ml = indio_dev->masklength;
-
-		for (i = 0; i < indio_dev->num_channels; i++)
-			ml = max(ml, channels[i].scan_index + 1);
-		indio_dev->masklength = ml;
-	}
-
-	if (!buffer)
-		return 0;
-
 	attrcount = 0;
 	if (buffer->attrs) {
 		while (buffer->attrs[attrcount] != NULL)
@@ -1411,19 +1399,45 @@  int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
 	return ret;
 }
 
-void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
+int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
 {
 	struct iio_buffer *buffer = indio_dev->buffer;
+	const struct iio_chan_spec *channels;
+	int i;
+
+	channels = indio_dev->channels;
+	if (channels) {
+		int ml = indio_dev->masklength;
+
+		for (i = 0; i < indio_dev->num_channels; i++)
+			ml = max(ml, channels[i].scan_index + 1);
+		indio_dev->masklength = ml;
+	}
 
 	if (!buffer)
-		return;
+		return 0;
+
+	return __iio_buffer_alloc_sysfs_and_mask(buffer);
+}
 
+static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer)
+{
 	iio_buffer_free_scanmask(buffer);
 	kfree(buffer->buffer_group.attrs);
 	kfree(buffer->scan_el_group.attrs);
 	iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
 }
 
+void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buffer = indio_dev->buffer;
+
+	if (!buffer)
+		return;
+
+	__iio_buffer_free_sysfs_and_mask(buffer);
+}
+
 static const struct file_operations iio_buffer_fileops = {
 	.read = iio_buffer_read_outer,
 	.release = iio_buffer_chrdev_release,