diff mbox series

iio: ssp_sensors: don't manually free devm managed resources

Message ID 20181005194830.9332-1-u.kleine-koenig@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series iio: ssp_sensors: don't manually free devm managed resources | expand

Commit Message

Uwe Kleine-König Oct. 5, 2018, 7:48 p.m. UTC
The charme of devm_* functions is that you don't need to care about them
in the error path. In this case it is valid to just return NULL which makes
the device fail to probe and then the two gpios and the allocated memory
are freed automatically by the driver core.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/iio/common/ssp_sensors/ssp_dev.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

Comments

Jonathan Cameron Oct. 7, 2018, 7:05 p.m. UTC | #1
On Fri,  5 Oct 2018 21:48:30 +0200
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> The charme of devm_* functions is that you don't need to care about them
> in the error path. In this case it is valid to just return NULL which makes
> the device fail to probe and then the two gpios and the allocated memory
> are freed automatically by the driver core.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

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

Thanks,

Jonathan

> ---
>  drivers/iio/common/ssp_sensors/ssp_dev.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/common/ssp_sensors/ssp_dev.c b/drivers/iio/common/ssp_sensors/ssp_dev.c
> index af3aa38f67cd..9e13be2c0cb9 100644
> --- a/drivers/iio/common/ssp_sensors/ssp_dev.c
> +++ b/drivers/iio/common/ssp_sensors/ssp_dev.c
> @@ -462,43 +462,35 @@ static struct ssp_data *ssp_parse_dt(struct device *dev)
>  
>  	data->mcu_ap_gpio = of_get_named_gpio(node, "mcu-ap-gpios", 0);
>  	if (data->mcu_ap_gpio < 0)
> -		goto err_free_pd;
> +		return NULL;
>  
>  	data->ap_mcu_gpio = of_get_named_gpio(node, "ap-mcu-gpios", 0);
>  	if (data->ap_mcu_gpio < 0)
> -		goto err_free_pd;
> +		return NULL;
>  
>  	data->mcu_reset_gpio = of_get_named_gpio(node, "mcu-reset-gpios", 0);
>  	if (data->mcu_reset_gpio < 0)
> -		goto err_free_pd;
> +		return NULL;
>  
>  	ret = devm_gpio_request_one(dev, data->ap_mcu_gpio, GPIOF_OUT_INIT_HIGH,
>  				    "ap-mcu-gpios");
>  	if (ret)
> -		goto err_free_pd;
> +		return NULL;
>  
>  	ret = devm_gpio_request_one(dev, data->mcu_reset_gpio,
>  				    GPIOF_OUT_INIT_HIGH, "mcu-reset-gpios");
>  	if (ret)
> -		goto err_ap_mcu;
> +		return NULL;
>  
>  	match = of_match_node(ssp_of_match, node);
>  	if (!match)
> -		goto err_mcu_reset_gpio;
> +		return NULL;
>  
>  	data->sensorhub_info = match->data;
>  
>  	dev_set_drvdata(dev, data);
>  
>  	return data;
> -
> -err_mcu_reset_gpio:
> -	devm_gpio_free(dev, data->mcu_reset_gpio);
> -err_ap_mcu:
> -	devm_gpio_free(dev, data->ap_mcu_gpio);
> -err_free_pd:
> -	devm_kfree(dev, data);
> -	return NULL;
>  }
>  #else
>  static struct ssp_data *ssp_parse_dt(struct device *pdev)
diff mbox series

Patch

diff --git a/drivers/iio/common/ssp_sensors/ssp_dev.c b/drivers/iio/common/ssp_sensors/ssp_dev.c
index af3aa38f67cd..9e13be2c0cb9 100644
--- a/drivers/iio/common/ssp_sensors/ssp_dev.c
+++ b/drivers/iio/common/ssp_sensors/ssp_dev.c
@@ -462,43 +462,35 @@  static struct ssp_data *ssp_parse_dt(struct device *dev)
 
 	data->mcu_ap_gpio = of_get_named_gpio(node, "mcu-ap-gpios", 0);
 	if (data->mcu_ap_gpio < 0)
-		goto err_free_pd;
+		return NULL;
 
 	data->ap_mcu_gpio = of_get_named_gpio(node, "ap-mcu-gpios", 0);
 	if (data->ap_mcu_gpio < 0)
-		goto err_free_pd;
+		return NULL;
 
 	data->mcu_reset_gpio = of_get_named_gpio(node, "mcu-reset-gpios", 0);
 	if (data->mcu_reset_gpio < 0)
-		goto err_free_pd;
+		return NULL;
 
 	ret = devm_gpio_request_one(dev, data->ap_mcu_gpio, GPIOF_OUT_INIT_HIGH,
 				    "ap-mcu-gpios");
 	if (ret)
-		goto err_free_pd;
+		return NULL;
 
 	ret = devm_gpio_request_one(dev, data->mcu_reset_gpio,
 				    GPIOF_OUT_INIT_HIGH, "mcu-reset-gpios");
 	if (ret)
-		goto err_ap_mcu;
+		return NULL;
 
 	match = of_match_node(ssp_of_match, node);
 	if (!match)
-		goto err_mcu_reset_gpio;
+		return NULL;
 
 	data->sensorhub_info = match->data;
 
 	dev_set_drvdata(dev, data);
 
 	return data;
-
-err_mcu_reset_gpio:
-	devm_gpio_free(dev, data->mcu_reset_gpio);
-err_ap_mcu:
-	devm_gpio_free(dev, data->ap_mcu_gpio);
-err_free_pd:
-	devm_kfree(dev, data);
-	return NULL;
 }
 #else
 static struct ssp_data *ssp_parse_dt(struct device *pdev)