linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]  Input: colibri-vf50-ts - call iio_channel_release_all() in all error paths
@ 2016-02-14 14:10 Fabio Estevam
  2016-02-15  5:02 ` maitysanchayan
  0 siblings, 1 reply; 3+ messages in thread
From: Fabio Estevam @ 2016-02-14 14:10 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: maitysanchayan, linux-input, Fabio Estevam

From: Fabio Estevam <fabio.estevam@nxp.com>

We need to make sure to call iio_channel_release_all() in all error
paths of the probe function.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
Build-tested only.

 drivers/input/touchscreen/colibri-vf50-ts.c | 39 ++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/input/touchscreen/colibri-vf50-ts.c b/drivers/input/touchscreen/colibri-vf50-ts.c
index 69828d0..67f8a17 100644
--- a/drivers/input/touchscreen/colibri-vf50-ts.c
+++ b/drivers/input/touchscreen/colibri-vf50-ts.c
@@ -279,9 +279,8 @@ static int vf50_ts_probe(struct platform_device *pdev)
 
 	error = devm_add_action(dev, vf50_ts_channel_release, channels);
 	if (error) {
-		iio_channel_release_all(channels);
 		dev_err(dev, "Failed to register iio channel release action");
-		return error;
+		goto channel_release;
 	}
 
 	num_adc_channels = 0;
@@ -290,12 +289,15 @@ static int vf50_ts_probe(struct platform_device *pdev)
 
 	if (num_adc_channels != COLI_TOUCH_REQ_ADC_CHAN) {
 		dev_err(dev, "Inadequate ADC channels specified\n");
-		return -EINVAL;
+		error = -EINVAL;
+		goto channel_release;
 	}
 
 	touchdev = devm_kzalloc(dev, sizeof(*touchdev), GFP_KERNEL);
-	if (!touchdev)
-		return -ENOMEM;
+	if (!touchdev) {
+		error = -ENOMEM;
+		goto channel_release;
+	}
 
 	touchdev->pdev = pdev;
 	touchdev->channels = channels;
@@ -303,12 +305,13 @@ static int vf50_ts_probe(struct platform_device *pdev)
 	error = of_property_read_u32(dev->of_node, "vf50-ts-min-pressure",
 				 &touchdev->min_pressure);
 	if (error)
-		return error;
+		goto channel_release;
 
 	input = devm_input_allocate_device(dev);
 	if (!input) {
 		dev_err(dev, "Failed to allocate TS input device\n");
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto channel_release;
 	}
 
 	platform_set_drvdata(pdev, touchdev);
@@ -330,29 +333,31 @@ static int vf50_ts_probe(struct platform_device *pdev)
 	error = input_register_device(input);
 	if (error) {
 		dev_err(dev, "Failed to register input device\n");
-		return error;
+		goto channel_release;
 	}
 
 	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xp, "xp", GPIOD_OUT_LOW);
 	if (error)
-		return error;
+		goto channel_release;
 
 	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xm,
 				"xm", GPIOD_OUT_LOW);
 	if (error)
-		return error;
+		goto channel_release;
 
 	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_yp, "yp", GPIOD_OUT_LOW);
 	if (error)
-		return error;
+		goto channel_release;
 
 	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_ym, "ym", GPIOD_OUT_LOW);
 	if (error)
-		return error;
+		goto channel_release;
 
 	touchdev->pen_irq = platform_get_irq(pdev, 0);
-	if (touchdev->pen_irq < 0)
-		return touchdev->pen_irq;
+	if (touchdev->pen_irq < 0) {
+		error = touchdev->pen_irq;
+		goto channel_release;
+	}
 
 	error = devm_request_threaded_irq(dev, touchdev->pen_irq,
 					  NULL, vf50_ts_irq_bh, IRQF_ONESHOT,
@@ -360,10 +365,14 @@ static int vf50_ts_probe(struct platform_device *pdev)
 	if (error) {
 		dev_err(dev, "Failed to request IRQ %d: %d\n",
 			touchdev->pen_irq, error);
-		return error;
+		goto channel_release;
 	}
 
 	return 0;
+
+channel_release:
+	iio_channel_release_all(channels);
+	return error;
 }
 
 static const struct of_device_id vf50_touch_of_match[] = {
-- 
1.9.1


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

* Re: [PATCH]  Input: colibri-vf50-ts - call iio_channel_release_all() in all error paths
  2016-02-14 14:10 [PATCH] Input: colibri-vf50-ts - call iio_channel_release_all() in all error paths Fabio Estevam
@ 2016-02-15  5:02 ` maitysanchayan
  2016-02-22 19:39   ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: maitysanchayan @ 2016-02-15  5:02 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: dmitry.torokhov, linux-input, Fabio Estevam

Hello Fabio,

On 16-02-14 12:10:49, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> We need to make sure to call iio_channel_release_all() in all error
> paths of the probe function.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
> ---
> Build-tested only.
> 
>  drivers/input/touchscreen/colibri-vf50-ts.c | 39 ++++++++++++++++++-----------
>  1 file changed, 24 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/colibri-vf50-ts.c b/drivers/input/touchscreen/colibri-vf50-ts.c
> index 69828d0..67f8a17 100644
> --- a/drivers/input/touchscreen/colibri-vf50-ts.c
> +++ b/drivers/input/touchscreen/colibri-vf50-ts.c
> @@ -279,9 +279,8 @@ static int vf50_ts_probe(struct platform_device *pdev)
>  
>  	error = devm_add_action(dev, vf50_ts_channel_release, channels);
>  	if (error) {
> -		iio_channel_release_all(channels);
>  		dev_err(dev, "Failed to register iio channel release action");
> -		return error;
> +		goto channel_release;
>  	}

As far as my understanding goes, from the discussion which happened during the
submission of the patchset for this driver, the channel release gets taken care
by the vf50_ts_channel_release function. Once it is successfully registered with
devm_add_action, any further error returns in probe, will result in this function
being called and the channels getting released.

Sorry if I understood it wrongly. Thanks for looking into this.

Regards,
Sanchayan.

>  
>  	num_adc_channels = 0;
> @@ -290,12 +289,15 @@ static int vf50_ts_probe(struct platform_device *pdev)
>  
>  	if (num_adc_channels != COLI_TOUCH_REQ_ADC_CHAN) {
>  		dev_err(dev, "Inadequate ADC channels specified\n");
> -		return -EINVAL;
> +		error = -EINVAL;
> +		goto channel_release;
>  	}
>  
>  	touchdev = devm_kzalloc(dev, sizeof(*touchdev), GFP_KERNEL);
> -	if (!touchdev)
> -		return -ENOMEM;
> +	if (!touchdev) {
> +		error = -ENOMEM;
> +		goto channel_release;
> +	}
>  
>  	touchdev->pdev = pdev;
>  	touchdev->channels = channels;
> @@ -303,12 +305,13 @@ static int vf50_ts_probe(struct platform_device *pdev)
>  	error = of_property_read_u32(dev->of_node, "vf50-ts-min-pressure",
>  				 &touchdev->min_pressure);
>  	if (error)
> -		return error;
> +		goto channel_release;
>  
>  	input = devm_input_allocate_device(dev);
>  	if (!input) {
>  		dev_err(dev, "Failed to allocate TS input device\n");
> -		return -ENOMEM;
> +		error = -ENOMEM;
> +		goto channel_release;
>  	}
>  
>  	platform_set_drvdata(pdev, touchdev);
> @@ -330,29 +333,31 @@ static int vf50_ts_probe(struct platform_device *pdev)
>  	error = input_register_device(input);
>  	if (error) {
>  		dev_err(dev, "Failed to register input device\n");
> -		return error;
> +		goto channel_release;
>  	}
>  
>  	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xp, "xp", GPIOD_OUT_LOW);
>  	if (error)
> -		return error;
> +		goto channel_release;
>  
>  	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_xm,
>  				"xm", GPIOD_OUT_LOW);
>  	if (error)
> -		return error;
> +		goto channel_release;
>  
>  	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_yp, "yp", GPIOD_OUT_LOW);
>  	if (error)
> -		return error;
> +		goto channel_release;
>  
>  	error = vf50_ts_get_gpiod(dev, &touchdev->gpio_ym, "ym", GPIOD_OUT_LOW);
>  	if (error)
> -		return error;
> +		goto channel_release;
>  
>  	touchdev->pen_irq = platform_get_irq(pdev, 0);
> -	if (touchdev->pen_irq < 0)
> -		return touchdev->pen_irq;
> +	if (touchdev->pen_irq < 0) {
> +		error = touchdev->pen_irq;
> +		goto channel_release;
> +	}
>  
>  	error = devm_request_threaded_irq(dev, touchdev->pen_irq,
>  					  NULL, vf50_ts_irq_bh, IRQF_ONESHOT,
> @@ -360,10 +365,14 @@ static int vf50_ts_probe(struct platform_device *pdev)
>  	if (error) {
>  		dev_err(dev, "Failed to request IRQ %d: %d\n",
>  			touchdev->pen_irq, error);
> -		return error;
> +		goto channel_release;
>  	}
>  
>  	return 0;
> +
> +channel_release:
> +	iio_channel_release_all(channels);
> +	return error;
>  }
>  
>  static const struct of_device_id vf50_touch_of_match[] = {
> -- 
> 1.9.1
> 

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

* Re: [PATCH]  Input: colibri-vf50-ts - call iio_channel_release_all() in all error paths
  2016-02-15  5:02 ` maitysanchayan
@ 2016-02-22 19:39   ` Dmitry Torokhov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2016-02-22 19:39 UTC (permalink / raw)
  To: maitysanchayan; +Cc: Fabio Estevam, linux-input, Fabio Estevam

On Mon, Feb 15, 2016 at 10:32:47AM +0530, maitysanchayan@gmail.com wrote:
> Hello Fabio,
> 
> On 16-02-14 12:10:49, Fabio Estevam wrote:
> > From: Fabio Estevam <fabio.estevam@nxp.com>
> > 
> > We need to make sure to call iio_channel_release_all() in all error
> > paths of the probe function.
> > 
> > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
> > ---
> > Build-tested only.
> > 
> >  drivers/input/touchscreen/colibri-vf50-ts.c | 39 ++++++++++++++++++-----------
> >  1 file changed, 24 insertions(+), 15 deletions(-)
> > 
> > diff --git a/drivers/input/touchscreen/colibri-vf50-ts.c b/drivers/input/touchscreen/colibri-vf50-ts.c
> > index 69828d0..67f8a17 100644
> > --- a/drivers/input/touchscreen/colibri-vf50-ts.c
> > +++ b/drivers/input/touchscreen/colibri-vf50-ts.c
> > @@ -279,9 +279,8 @@ static int vf50_ts_probe(struct platform_device *pdev)
> >  
> >  	error = devm_add_action(dev, vf50_ts_channel_release, channels);
> >  	if (error) {
> > -		iio_channel_release_all(channels);
> >  		dev_err(dev, "Failed to register iio channel release action");
> > -		return error;
> > +		goto channel_release;
> >  	}
> 
> As far as my understanding goes, from the discussion which happened during the
> submission of the patchset for this driver, the channel release gets taken care
> by the vf50_ts_channel_release function. Once it is successfully registered with
> devm_add_action, any further error returns in probe, will result in this function
> being called and the channels getting released.

That is correct, devm_add_action injects a custom action into devm
release sequence, so we should be releasing all channels when bailing
out due to an error.

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2016-02-22 19:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-14 14:10 [PATCH] Input: colibri-vf50-ts - call iio_channel_release_all() in all error paths Fabio Estevam
2016-02-15  5:02 ` maitysanchayan
2016-02-22 19:39   ` Dmitry Torokhov

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).