From: Mark Brown broonie@linaro.org
Saves code in the unwind path.
Signed-off-by: Mark Brown broonie@linaro.org --- drivers/regulator/wm831x-dcdc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c index 11861cb..8f62750 100644 --- a/drivers/regulator/wm831x-dcdc.c +++ b/drivers/regulator/wm831x-dcdc.c @@ -387,8 +387,9 @@ static struct regulator_ops wm831x_buckv_ops = { * Set up DVS control. We just log errors since we can still run * (with reduced performance) if we fail. */ -static void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc, - struct wm831x_buckv_pdata *pdata) +static void wm831x_buckv_dvs_init(struct platform_device *pdev, + struct wm831x_dcdc *dcdc, + struct wm831x_buckv_pdata *pdata) { struct wm831x *wm831x = dcdc->wm831x; int ret; @@ -402,9 +403,9 @@ static void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc, */ dcdc->dvs_gpio_state = pdata->dvs_init_state;
- ret = gpio_request_one(pdata->dvs_gpio, - dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, - "DCDC DVS"); + ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio, + dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, + "DCDC DVS"); if (ret < 0) { dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", dcdc->name, ret); @@ -513,7 +514,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev) dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK;
if (pdata && pdata->dcdc[id]) - wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data); + wm831x_buckv_dvs_init(pdev, dcdc, + pdata->dcdc[id]->driver_data);
config.dev = pdev->dev.parent; if (pdata) @@ -557,8 +559,6 @@ err_uv: err_regulator: regulator_unregister(dcdc->regulator); err: - if (dcdc->dvs_gpio) - gpio_free(dcdc->dvs_gpio); return ret; }
@@ -572,8 +572,6 @@ static int wm831x_buckv_remove(struct platform_device *pdev) free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")), dcdc); regulator_unregister(dcdc->regulator); - if (dcdc->dvs_gpio) - gpio_free(dcdc->dvs_gpio);
return 0; }
From: Mark Brown broonie@linaro.org
devm guarantees that resources are freed in the opposite order to that in which they are registered.
Signed-off-by: Mark Brown broonie@linaro.org --- drivers/regulator/wm831x-dcdc.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c index 8f62750..aca2fcb 100644 --- a/drivers/regulator/wm831x-dcdc.c +++ b/drivers/regulator/wm831x-dcdc.c @@ -532,8 +532,9 @@ static int wm831x_buckv_probe(struct platform_device *pdev) }
irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); - ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, - IRQF_TRIGGER_RISING, dcdc->name, dcdc); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + wm831x_dcdc_uv_irq, + IRQF_TRIGGER_RISING, dcdc->name, dcdc); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); @@ -541,21 +542,19 @@ static int wm831x_buckv_probe(struct platform_device *pdev) }
irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")); - ret = request_threaded_irq(irq, NULL, wm831x_dcdc_oc_irq, - IRQF_TRIGGER_RISING, dcdc->name, dcdc); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + wm831x_dcdc_oc_irq, + IRQF_TRIGGER_RISING, dcdc->name, dcdc); if (ret != 0) { dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n", irq, ret); - goto err_uv; + goto err_regulator; }
platform_set_drvdata(pdev, dcdc);
return 0;
-err_uv: - free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")), - dcdc); err_regulator: regulator_unregister(dcdc->regulator); err: @@ -565,12 +564,7 @@ err: static int wm831x_buckv_remove(struct platform_device *pdev) { struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); - struct wm831x *wm831x = dcdc->wm831x;
- free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")), - dcdc); - free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")), - dcdc); regulator_unregister(dcdc->regulator);
return 0; @@ -688,8 +682,9 @@ static int wm831x_buckp_probe(struct platform_device *pdev) }
irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); - ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, - IRQF_TRIGGER_RISING, dcdc->name, dcdc); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + wm831x_dcdc_uv_irq, + IRQF_TRIGGER_RISING, dcdc->name, dcdc); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); @@ -710,8 +705,6 @@ static int wm831x_buckp_remove(struct platform_device *pdev) { struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
- free_irq(wm831x_irq(dcdc->wm831x, platform_get_irq_byname(pdev, "UV")), - dcdc); regulator_unregister(dcdc->regulator);
return 0; @@ -820,9 +813,10 @@ static int wm831x_boostp_probe(struct platform_device *pdev) }
irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); - ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, - IRQF_TRIGGER_RISING, dcdc->name, - dcdc); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + wm831x_dcdc_uv_irq, + IRQF_TRIGGER_RISING, dcdc->name, + dcdc); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); @@ -843,8 +837,6 @@ static int wm831x_boostp_remove(struct platform_device *pdev) { struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
- free_irq(wm831x_irq(dcdc->wm831x, platform_get_irq_byname(pdev, "UV")), - dcdc); regulator_unregister(dcdc->regulator);
return 0;
From: Mark Brown broonie@linaro.org
devm guarantees that resources are freed in the opposite order to that in which they are allocated.
Signed-off-by: Mark Brown broonie@linaro.org --- drivers/regulator/wm831x-isink.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index 4eb373d..841cb52 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c @@ -203,8 +203,10 @@ static int wm831x_isink_probe(struct platform_device *pdev) }
irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0)); - ret = request_threaded_irq(irq, NULL, wm831x_isink_irq, - IRQF_TRIGGER_RISING, isink->name, isink); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + wm831x_isink_irq, + IRQF_TRIGGER_RISING, isink->name, + isink); if (ret != 0) { dev_err(&pdev->dev, "Failed to request ISINK IRQ %d: %d\n", irq, ret); @@ -225,8 +227,6 @@ static int wm831x_isink_remove(struct platform_device *pdev) { struct wm831x_isink *isink = platform_get_drvdata(pdev);
- free_irq(wm831x_irq(isink->wm831x, platform_get_irq(pdev, 0)), isink); - regulator_unregister(isink->regulator);
return 0;
From: Mark Brown broonie@linaro.org
devm guarantees that resources are freed in the oposite order to that in which they are allocated.
Signed-off-by: Mark Brown broonie@linaro.org --- drivers/regulator/wm831x-ldo.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index 1432b26..5570f3e 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c @@ -288,9 +288,10 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev) }
irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); - ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, - IRQF_TRIGGER_RISING, ldo->name, - ldo); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + wm831x_ldo_uv_irq, + IRQF_TRIGGER_RISING, ldo->name, + ldo); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); @@ -311,8 +312,6 @@ static int wm831x_gp_ldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
- free_irq(wm831x_irq(ldo->wm831x, - platform_get_irq_byname(pdev, "UV")), ldo); regulator_unregister(ldo->regulator);
return 0; @@ -514,8 +513,9 @@ static int wm831x_aldo_probe(struct platform_device *pdev) }
irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); - ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, - IRQF_TRIGGER_RISING, ldo->name, ldo); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + wm831x_ldo_uv_irq, + IRQF_TRIGGER_RISING, ldo->name, ldo); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); @@ -536,8 +536,6 @@ static int wm831x_aldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
- free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")), - ldo); regulator_unregister(ldo->regulator);
return 0;
linaro-kernel@lists.linaro.org