Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1390388 > unrolled thread

[RFC] iio: Release irq if set_trigger_state fails

Started byCrestez Dan Leonard <leonard.crestez@intel.com>
First post2016-04-28 18:50 +0200
Last post2016-05-03 14:30 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [RFC] iio: Release irq if set_trigger_state fails Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-04-28 18:50 +0200
    Re: [RFC] iio: Release irq if set_trigger_state fails Jonathan Cameron <jic23@kernel.org> - 2016-05-01 23:30 +0200
      Re: [RFC] iio: Release irq if set_trigger_state fails Crestez Dan Leonard <leonard.crestez@intel.com> - 2016-05-03 14:30 +0200

#1390388 — [RFC] iio: Release irq if set_trigger_state fails

FromCrestez Dan Leonard <leonard.crestez@intel.com>
Date2016-04-28 18:50 +0200
Subject[RFC] iio: Release irq if set_trigger_state fails
Message-ID<rsXiz-6Zu-19@gated-at.bofh.it>
When attaching a pollfunc iio_trigger_attach_poll_func will allocate a
virtual irq and call the driver's set_trigger_state function. Fix error
handling to release the irq if set_trigger_state fails.

Otherwise when using triggered buffers and the driver's
set_trigger_state fails once then the buffer becomes unusable.

It is not possible to handle this sort of error by calling
iio_trigger_detach_poll_func externally somehow. That function should
only be called if attach is successful.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
---

I ran into this while adding some validation in driver's set_trigger_state
function. It's much better to use buffer_ops->predisable for that kind of stuff
but the iio core should still handle set_trigger_state errors correctly.

 drivers/iio/industrialio-trigger.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index ae2806a..cf2be3e 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -214,18 +214,23 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
 	ret = request_threaded_irq(pf->irq, pf->h, pf->thread,
 				   pf->type, pf->name,
 				   pf);
-	if (ret < 0) {
-		module_put(pf->indio_dev->info->driver_module);
-		return ret;
-	}
+	if (ret < 0)
+		goto out_put_module;
 
 	if (trig->ops && trig->ops->set_trigger_state && notinuse) {
 		ret = trig->ops->set_trigger_state(trig, true);
 		if (ret < 0)
-			module_put(pf->indio_dev->info->driver_module);
+			goto out_put_irq;
 	}
 
 	return ret;
+
+out_put_irq:
+	iio_trigger_put_irq(trig, pf->irq);
+	free_irq(pf->irq, pf);
+out_put_module:
+	module_put(pf->indio_dev->info->driver_module);
+	return ret;
 }
 
 static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
-- 
2.5.5

[toc] | [next] | [standalone]


#1391899

FromJonathan Cameron <jic23@kernel.org>
Date2016-05-01 23:30 +0200
Message-ID<ru76b-86o-35@gated-at.bofh.it>
In reply to#1390388
On 28/04/16 17:40, Crestez Dan Leonard wrote:
> When attaching a pollfunc iio_trigger_attach_poll_func will allocate a
> virtual irq and call the driver's set_trigger_state function. Fix error
> handling to release the irq if set_trigger_state fails.
> 
> Otherwise when using triggered buffers and the driver's
> set_trigger_state fails once then the buffer becomes unusable.
> 
> It is not possible to handle this sort of error by calling
> iio_trigger_detach_poll_func externally somehow. That function should
> only be called if attach is successful.
> 
> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
I'm embarrassed :(  good find! Not sure why you made such an obvious
bug fix an RFC though! 

Slight issue in the new error handling though I think..

Jonathan
> ---
> 
> I ran into this while adding some validation in driver's set_trigger_state
> function. It's much better to use buffer_ops->predisable for that kind of stuff
> but the iio core should still handle set_trigger_state errors correctly.
> 
>  drivers/iio/industrialio-trigger.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> index ae2806a..cf2be3e 100644
> --- a/drivers/iio/industrialio-trigger.c
> +++ b/drivers/iio/industrialio-trigger.c
> @@ -214,18 +214,23 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
>  	ret = request_threaded_irq(pf->irq, pf->h, pf->thread,
>  				   pf->type, pf->name,
>  				   pf);
> -	if (ret < 0) {
> -		module_put(pf->indio_dev->info->driver_module);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		goto out_put_module;
>  
>  	if (trig->ops && trig->ops->set_trigger_state && notinuse) {
>  		ret = trig->ops->set_trigger_state(trig, true);
>  		if (ret < 0)
> -			module_put(pf->indio_dev->info->driver_module);
> +			goto out_put_irq;
>  	}
>  
>  	return ret;
> +
> +out_put_irq:
> +	iio_trigger_put_irq(trig, pf->irq);
> +	free_irq(pf->irq, pf);
> +out_put_module:
I think the iio_trigger_put_irq should be here as it will have been gotten before the 
request_threaded_irq call and hence should always be unwound on error not just in the
case above.
> +	module_put(pf->indio_dev->info->driver_module);
> +	return ret;
>  }
>  
>  static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
> 

[toc] | [prev] | [next] | [standalone]


#1393381

FromCrestez Dan Leonard <leonard.crestez@intel.com>
Date2016-05-03 14:30 +0200
Message-ID<ruHCF-86V-7@gated-at.bofh.it>
In reply to#1391899
On 05/01/2016 10:11 PM, Jonathan Cameron wrote:
> On 28/04/16 17:40, Crestez Dan Leonard wrote:
>> When attaching a pollfunc iio_trigger_attach_poll_func will allocate a
>> virtual irq and call the driver's set_trigger_state function. Fix error
>> handling to release the irq if set_trigger_state fails.
>>
>> Otherwise when using triggered buffers and the driver's
>> set_trigger_state fails once then the buffer becomes unusable.
>>
>> It is not possible to handle this sort of error by calling
>> iio_trigger_detach_poll_func externally somehow. That function should
>> only be called if attach is successful.
>>
>> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
> I'm embarrassed :(  good find! Not sure why you made such an obvious
> bug fix an RFC though! 
> 
> Slight issue in the new error handling though I think..
> 
>> +
>> +out_put_irq:
>> +	iio_trigger_put_irq(trig, pf->irq);
>> +	free_irq(pf->irq, pf);
>> +out_put_module:
> I think the iio_trigger_put_irq should be here as it will have been gotten before the 
> request_threaded_irq call and hence should always be unwound on error not just in the
> case above.
>
Yes. I sent V2 which should properly handle errors from
iio_trigger_get_irq and request_threaded_irq separately.

-- 
Regards,
Leonard

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web