All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Fabio.Estevam@freescale.com" <Fabio.Estevam@freescale.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	"lars@metafoo.de" <lars@metafoo.de>,
	"festevam@gmail.com" <festevam@gmail.com>
Subject: Re: [PATCH]  Input: pwm-beeper - Use devm functions
Date: Thu, 19 Feb 2015 18:40:49 +0000	[thread overview]
Message-ID: <1424371237805.59244@freescale.com> (raw)
In-Reply-To: <20150219171239.GA11113@dtor-glaptop>

Hi Dmitry,

[Sorry for the top posting. Not able to access a proper email client at the moment]

I didn't understand the problem in using devm_pwm_get(). Could you please explain?

Thanks

________________________________________
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Sent: Thursday, February 19, 2015 3:12 PM
To: Estevam Fabio-R49496
Cc: linux-input@vger.kernel.org; lars@metafoo.de
Subject: Re: [PATCH]  Input: pwm-beeper - Use devm functions

Hi Fabio,

On Thu, Feb 19, 2015 at 09:26:02AM -0200, Fabio Estevam wrote:
> By using devm functions the code can be simplified a bit.
>
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
>  drivers/input/misc/pwm-beeper.c | 18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
> index a28ee70..c5ccaee 100644
> --- a/drivers/input/misc/pwm-beeper.c
> +++ b/drivers/input/misc/pwm-beeper.c
> @@ -72,11 +72,11 @@ static int pwm_beeper_probe(struct platform_device *pdev)
>       struct pwm_beeper *beeper;
>       int error;
>
> -     beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
> +     beeper = devm_kzalloc(&pdev->dev, sizeof(*beeper), GFP_KERNEL);
>       if (!beeper)
>               return -ENOMEM;
>
> -     beeper->pwm = pwm_get(&pdev->dev, NULL);
> +     beeper->pwm = devm_pwm_get(&pdev->dev, NULL);
>       if (IS_ERR(beeper->pwm)) {
>               dev_dbg(&pdev->dev, "unable to request PWM, trying legacy API\n");
>               beeper->pwm = pwm_request(pwm_id, "pwm beeper");

This is not managed resource anymore, what will free it?

> @@ -85,14 +85,13 @@ static int pwm_beeper_probe(struct platform_device *pdev)
>       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;
> +             return error;
>       }
>
> -     beeper->input = input_allocate_device();
> +     beeper->input = devm_input_allocate_device(&pdev->dev);
>       if (!beeper->input) {
>               dev_err(&pdev->dev, "Failed to allocate input device\n");
> -             error = -ENOMEM;
> -             goto err_pwm_free;
> +             return -ENOMEM;
>       }
>       beeper->input->dev.parent = &pdev->dev;
>
> @@ -122,10 +121,6 @@ static int pwm_beeper_probe(struct platform_device *pdev)
>
>  err_input_free:
>       input_free_device(beeper->input);
> -err_pwm_free:
> -     pwm_free(beeper->pwm);
> -err_free:
> -     kfree(beeper);
>
>       return error;
>  }
> @@ -137,9 +132,6 @@ static int pwm_beeper_remove(struct platform_device *pdev)
>       input_unregister_device(beeper->input);
>
>       pwm_disable(beeper->pwm);

If you solve the issue above, then if you move pwm_disable() into new
pwm_beeper_close() then you can get rid of pwm_beeper_remove() altogether.

> -     pwm_free(beeper->pwm);
> -
> -     kfree(beeper);
>
>       return 0;
>  }
> --
> 1.9.1
>

Thanks.

--
Dmitry

  reply	other threads:[~2015-02-19 18:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-19 11:26 [PATCH] Input: pwm-beeper - Use devm functions Fabio Estevam
2015-02-19 17:12 ` Dmitry Torokhov
2015-02-19 18:40   ` Fabio.Estevam [this message]
2015-02-19 18:46     ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424371237805.59244@freescale.com \
    --to=fabio.estevam@freescale.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=festevam@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.