Re: [PATCH] Input: pwm-beeper - Use devm functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On February 19, 2015 10:40:49 AM PST, "Fabio.Estevam@xxxxxxxxxxxxx" <Fabio.Estevam@xxxxxxxxxxxxx> wrote:
>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?
>

Please take a closer look - if devm_pwm_get fails we are trying to use an alternative API to get pwm which is not managed.

>Thanks
>
>________________________________________
>From: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
>Sent: Thursday, February 19, 2015 3:12 PM
>To: Estevam Fabio-R49496
>Cc: linux-input@xxxxxxxxxxxxxxx; lars@xxxxxxxxxx
>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@xxxxxxxxxxxxx>
>> ---
>>  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


Thanks.

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux