Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] iio: dln2-adc: fix iio_triggered_buffer_postenable() position
@ 2019-10-23  8:26 Alexandru Ardelean
  2019-10-27 16:56 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandru Ardelean @ 2019-10-23  8:26 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Ardelean

The iio_triggered_buffer_postenable() hook should be called first to
attach the poll function. The iio_triggered_buffer_predisable() hook is
called last (as is it should).

This change moves iio_triggered_buffer_postenable() to be called first. It
adds iio_triggered_buffer_predisable() on the error paths of the postenable
hook.
For the predisable hook, some code-paths have been changed to make sure
that the iio_triggered_buffer_predisable() hook gets called in case there
is an error before it.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/dln2-adc.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
index 5fa78c273a25..65c7c9329b1c 100644
--- a/drivers/iio/adc/dln2-adc.c
+++ b/drivers/iio/adc/dln2-adc.c
@@ -524,6 +524,10 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
 	u16 conflict;
 	unsigned int trigger_chan;
 
+	ret = iio_triggered_buffer_postenable(indio_dev);
+	if (ret)
+		return ret;
+
 	mutex_lock(&dln2->mutex);
 
 	/* Enable ADC */
@@ -537,6 +541,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
 				(int)conflict);
 			ret = -EBUSY;
 		}
+		iio_triggered_buffer_predisable(indio_dev);
 		return ret;
 	}
 
@@ -550,6 +555,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
 		mutex_unlock(&dln2->mutex);
 		if (ret < 0) {
 			dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
+			iio_triggered_buffer_predisable(indio_dev);
 			return ret;
 		}
 	} else {
@@ -557,12 +563,12 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
 		mutex_unlock(&dln2->mutex);
 	}
 
-	return iio_triggered_buffer_postenable(indio_dev);
+	return 0;
 }
 
 static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
 {
-	int ret;
+	int ret, ret2;
 	struct dln2_adc *dln2 = iio_priv(indio_dev);
 
 	mutex_lock(&dln2->mutex);
@@ -577,12 +583,14 @@ static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
 	ret = dln2_adc_set_port_enabled(dln2, false, NULL);
 
 	mutex_unlock(&dln2->mutex);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
-		return ret;
-	}
 
-	return iio_triggered_buffer_predisable(indio_dev);
+	ret2 = iio_triggered_buffer_predisable(indio_dev);
+	if (ret == 0)
+		ret = ret2;
+
+	return ret;
 }
 
 static const struct iio_buffer_setup_ops dln2_adc_buffer_setup_ops = {
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: dln2-adc: fix iio_triggered_buffer_postenable() position
  2019-10-23  8:26 [PATCH] iio: dln2-adc: fix iio_triggered_buffer_postenable() position Alexandru Ardelean
@ 2019-10-27 16:56 ` Jonathan Cameron
  2019-10-29 21:58   ` Jack Andersen
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2019-10-27 16:56 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, linux-kernel, Jack Andersen

On Wed, 23 Oct 2019 11:26:34 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> The iio_triggered_buffer_postenable() hook should be called first to
> attach the poll function. The iio_triggered_buffer_predisable() hook is
> called last (as is it should).
> 
> This change moves iio_triggered_buffer_postenable() to be called first. It
> adds iio_triggered_buffer_predisable() on the error paths of the postenable
> hook.
> For the predisable hook, some code-paths have been changed to make sure
> that the iio_triggered_buffer_predisable() hook gets called in case there
> is an error before it.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
+CC Jack who wrote the driver.

Looks fine to me, but I always like these to sit for a while and ideally get
review from the authors / maintainers of the drivers.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/dln2-adc.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
> index 5fa78c273a25..65c7c9329b1c 100644
> --- a/drivers/iio/adc/dln2-adc.c
> +++ b/drivers/iio/adc/dln2-adc.c
> @@ -524,6 +524,10 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
>  	u16 conflict;
>  	unsigned int trigger_chan;
>  
> +	ret = iio_triggered_buffer_postenable(indio_dev);
> +	if (ret)
> +		return ret;
> +
>  	mutex_lock(&dln2->mutex);
>  
>  	/* Enable ADC */
> @@ -537,6 +541,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
>  				(int)conflict);
>  			ret = -EBUSY;
>  		}
> +		iio_triggered_buffer_predisable(indio_dev);
>  		return ret;
>  	}
>  
> @@ -550,6 +555,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
>  		mutex_unlock(&dln2->mutex);
>  		if (ret < 0) {
>  			dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
> +			iio_triggered_buffer_predisable(indio_dev);
>  			return ret;
>  		}
>  	} else {
> @@ -557,12 +563,12 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
>  		mutex_unlock(&dln2->mutex);
>  	}
>  
> -	return iio_triggered_buffer_postenable(indio_dev);
> +	return 0;
>  }
>  
>  static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
>  {
> -	int ret;
> +	int ret, ret2;
>  	struct dln2_adc *dln2 = iio_priv(indio_dev);
>  
>  	mutex_lock(&dln2->mutex);
> @@ -577,12 +583,14 @@ static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
>  	ret = dln2_adc_set_port_enabled(dln2, false, NULL);
>  
>  	mutex_unlock(&dln2->mutex);
> -	if (ret < 0) {
> +	if (ret < 0)
>  		dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
> -		return ret;
> -	}
>  
> -	return iio_triggered_buffer_predisable(indio_dev);
> +	ret2 = iio_triggered_buffer_predisable(indio_dev);
> +	if (ret == 0)
> +		ret = ret2;
> +
> +	return ret;
>  }
>  
>  static const struct iio_buffer_setup_ops dln2_adc_buffer_setup_ops = {


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: dln2-adc: fix iio_triggered_buffer_postenable() position
  2019-10-27 16:56 ` Jonathan Cameron
@ 2019-10-29 21:58   ` Jack Andersen
  2019-11-02 14:37     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Jack Andersen @ 2019-10-29 21:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Alexandru Ardelean, linux-iio, linux-kernel

These changes look fine to me as well.

I no longer have access to a DLN2 for empirical testing, but since this is
mainly integration improvements with the IIO side of things, it shouldn't make
a difference for the hardware.



On Sun, 27 Oct 2019 at 06:56, Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Wed, 23 Oct 2019 11:26:34 +0300
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
>
> > The iio_triggered_buffer_postenable() hook should be called first to
> > attach the poll function. The iio_triggered_buffer_predisable() hook is
> > called last (as is it should).
> >
> > This change moves iio_triggered_buffer_postenable() to be called first. It
> > adds iio_triggered_buffer_predisable() on the error paths of the postenable
> > hook.
> > For the predisable hook, some code-paths have been changed to make sure
> > that the iio_triggered_buffer_predisable() hook gets called in case there
> > is an error before it.
> >
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> +CC Jack who wrote the driver.
>
> Looks fine to me, but I always like these to sit for a while and ideally get
> review from the authors / maintainers of the drivers.
>
> Thanks,
>
> Jonathan
>
> > ---
> >  drivers/iio/adc/dln2-adc.c | 20 ++++++++++++++------
> >  1 file changed, 14 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
> > index 5fa78c273a25..65c7c9329b1c 100644
> > --- a/drivers/iio/adc/dln2-adc.c
> > +++ b/drivers/iio/adc/dln2-adc.c
> > @@ -524,6 +524,10 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> >       u16 conflict;
> >       unsigned int trigger_chan;
> >
> > +     ret = iio_triggered_buffer_postenable(indio_dev);
> > +     if (ret)
> > +             return ret;
> > +
> >       mutex_lock(&dln2->mutex);
> >
> >       /* Enable ADC */
> > @@ -537,6 +541,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> >                               (int)conflict);
> >                       ret = -EBUSY;
> >               }
> > +             iio_triggered_buffer_predisable(indio_dev);
> >               return ret;
> >       }
> >
> > @@ -550,6 +555,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> >               mutex_unlock(&dln2->mutex);
> >               if (ret < 0) {
> >                       dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
> > +                     iio_triggered_buffer_predisable(indio_dev);
> >                       return ret;
> >               }
> >       } else {
> > @@ -557,12 +563,12 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> >               mutex_unlock(&dln2->mutex);
> >       }
> >
> > -     return iio_triggered_buffer_postenable(indio_dev);
> > +     return 0;
> >  }
> >
> >  static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
> >  {
> > -     int ret;
> > +     int ret, ret2;
> >       struct dln2_adc *dln2 = iio_priv(indio_dev);
> >
> >       mutex_lock(&dln2->mutex);
> > @@ -577,12 +583,14 @@ static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
> >       ret = dln2_adc_set_port_enabled(dln2, false, NULL);
> >
> >       mutex_unlock(&dln2->mutex);
> > -     if (ret < 0) {
> > +     if (ret < 0)
> >               dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
> > -             return ret;
> > -     }
> >
> > -     return iio_triggered_buffer_predisable(indio_dev);
> > +     ret2 = iio_triggered_buffer_predisable(indio_dev);
> > +     if (ret == 0)
> > +             ret = ret2;
> > +
> > +     return ret;
> >  }
> >
> >  static const struct iio_buffer_setup_ops dln2_adc_buffer_setup_ops = {
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: dln2-adc: fix iio_triggered_buffer_postenable() position
  2019-10-29 21:58   ` Jack Andersen
@ 2019-11-02 14:37     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2019-11-02 14:37 UTC (permalink / raw)
  To: Jack Andersen; +Cc: Alexandru Ardelean, linux-iio, linux-kernel

On Tue, 29 Oct 2019 11:58:16 -1000
Jack Andersen <jackoalan@gmail.com> wrote:

> These changes look fine to me as well.
> 
> I no longer have access to a DLN2 for empirical testing, but since this is
> mainly integration improvements with the IIO side of things, it shouldn't make
> a difference for the hardware.

Whilst I have one of these, it'll will be a while before I'm in any position
to test it.  Hence let's gamble a tiny bit.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> 
> 
> 
> On Sun, 27 Oct 2019 at 06:56, Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Wed, 23 Oct 2019 11:26:34 +0300
> > Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> >  
> > > The iio_triggered_buffer_postenable() hook should be called first to
> > > attach the poll function. The iio_triggered_buffer_predisable() hook is
> > > called last (as is it should).
> > >
> > > This change moves iio_triggered_buffer_postenable() to be called first. It
> > > adds iio_triggered_buffer_predisable() on the error paths of the postenable
> > > hook.
> > > For the predisable hook, some code-paths have been changed to make sure
> > > that the iio_triggered_buffer_predisable() hook gets called in case there
> > > is an error before it.
> > >
> > > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>  
> > +CC Jack who wrote the driver.
> >
> > Looks fine to me, but I always like these to sit for a while and ideally get
> > review from the authors / maintainers of the drivers.
> >
> > Thanks,
> >
> > Jonathan
> >  
> > > ---
> > >  drivers/iio/adc/dln2-adc.c | 20 ++++++++++++++------
> > >  1 file changed, 14 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
> > > index 5fa78c273a25..65c7c9329b1c 100644
> > > --- a/drivers/iio/adc/dln2-adc.c
> > > +++ b/drivers/iio/adc/dln2-adc.c
> > > @@ -524,6 +524,10 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> > >       u16 conflict;
> > >       unsigned int trigger_chan;
> > >
> > > +     ret = iio_triggered_buffer_postenable(indio_dev);
> > > +     if (ret)
> > > +             return ret;
> > > +
> > >       mutex_lock(&dln2->mutex);
> > >
> > >       /* Enable ADC */
> > > @@ -537,6 +541,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> > >                               (int)conflict);
> > >                       ret = -EBUSY;
> > >               }
> > > +             iio_triggered_buffer_predisable(indio_dev);
> > >               return ret;
> > >       }
> > >
> > > @@ -550,6 +555,7 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> > >               mutex_unlock(&dln2->mutex);
> > >               if (ret < 0) {
> > >                       dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
> > > +                     iio_triggered_buffer_predisable(indio_dev);
> > >                       return ret;
> > >               }
> > >       } else {
> > > @@ -557,12 +563,12 @@ static int dln2_adc_triggered_buffer_postenable(struct iio_dev *indio_dev)
> > >               mutex_unlock(&dln2->mutex);
> > >       }
> > >
> > > -     return iio_triggered_buffer_postenable(indio_dev);
> > > +     return 0;
> > >  }
> > >
> > >  static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
> > >  {
> > > -     int ret;
> > > +     int ret, ret2;
> > >       struct dln2_adc *dln2 = iio_priv(indio_dev);
> > >
> > >       mutex_lock(&dln2->mutex);
> > > @@ -577,12 +583,14 @@ static int dln2_adc_triggered_buffer_predisable(struct iio_dev *indio_dev)
> > >       ret = dln2_adc_set_port_enabled(dln2, false, NULL);
> > >
> > >       mutex_unlock(&dln2->mutex);
> > > -     if (ret < 0) {
> > > +     if (ret < 0)
> > >               dev_dbg(&dln2->pdev->dev, "Problem in %s\n", __func__);
> > > -             return ret;
> > > -     }
> > >
> > > -     return iio_triggered_buffer_predisable(indio_dev);
> > > +     ret2 = iio_triggered_buffer_predisable(indio_dev);
> > > +     if (ret == 0)
> > > +             ret = ret2;
> > > +
> > > +     return ret;
> > >  }
> > >
> > >  static const struct iio_buffer_setup_ops dln2_adc_buffer_setup_ops = {  
> >  


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23  8:26 [PATCH] iio: dln2-adc: fix iio_triggered_buffer_postenable() position Alexandru Ardelean
2019-10-27 16:56 ` Jonathan Cameron
2019-10-29 21:58   ` Jack Andersen
2019-11-02 14:37     ` Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git