Re: [PATCH v2 2/7] Input: pwm-beeper - switch to using managed resources

From: Thierry Reding
Date: Fri Jan 20 2017 - 05:17:36 EST


On Thu, Jan 19, 2017 at 02:40:52PM -0800, Dmitry Torokhov wrote:
> Use of managed resources (devm) simplifies error handling and tear down
> of the driver.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
> ---
> drivers/input/misc/pwm-beeper.c | 44 ++++++++++-------------------------------
> 1 file changed, 10 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
> index cb87e475bd23..14c52054f5b7 100644
> --- a/drivers/input/misc/pwm-beeper.c
> +++ b/drivers/input/misc/pwm-beeper.c
> @@ -95,18 +95,19 @@ static void pwm_beeper_close(struct input_dev *input)
>
> static int pwm_beeper_probe(struct platform_device *pdev)
> {
> + struct device *dev = &pdev->dev;
> struct pwm_beeper *beeper;
> int error;
>
> - beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
> + beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL);
> if (!beeper)
> return -ENOMEM;
>
> - beeper->pwm = pwm_get(&pdev->dev, NULL);
> + beeper->pwm = devm_pwm_get(dev, NULL);
> if (IS_ERR(beeper->pwm)) {
> error = PTR_ERR(beeper->pwm);
> - dev_err(&pdev->dev, "Failed to request pwm device: %d\n", error);
> - goto err_free;
> + dev_err(dev, "Failed to request pwm device: %d\n", error);

While at it, could you do a "pwm" -> "PWM" in the above. It's an
abbreviation.

Otherwise this looks like great cleanup:

Reviewed-by: Thierry Reding <thierry.reding@xxxxxxxxx>

Attachment: signature.asc
Description: PGP signature