Re: [PATCH 4/5] leds: flash: Add devm_* functions to the flash class
From: Jacek Anaszewski
Date: Wed Oct 02 2019 - 15:55:34 EST
Dan,
On 10/2/19 2:04 PM, Dan Murphy wrote:
> Jacek
>
> On 10/1/19 4:06 PM, Jacek Anaszewski wrote:
>> Dan,
>>
>> Thank you for the patch. One funny omission caught my
>> eye here and in led-class.c when making visual comparison.
>> Please refer below.
>>
>> On 10/1/19 8:04 PM, Dan Murphy wrote:
>>> Add the missing device managed API for registration and
>>> unregistration for the LED flash class.
>>>
>>> Signed-off-by: Dan Murphy <dmurphy@xxxxxx>
>>> ---
>>>  drivers/leds/led-class-flash.c | 50 +++++++++++++++++++++++++++++++++
>>> Â include/linux/led-class-flash.h | 14 +++++++++
>>> Â 2 files changed, 64 insertions(+)
>>>
>>> diff --git a/drivers/leds/led-class-flash.c
>>> b/drivers/leds/led-class-flash.c
>>> index 60c3de5c6b9f..c2b4fd02a1bc 100644
>>> --- a/drivers/leds/led-class-flash.c
>>> +++ b/drivers/leds/led-class-flash.c
>>> @@ -327,6 +327,56 @@ void led_classdev_flash_unregister(struct
>>> led_classdev_flash *fled_cdev)
>>> Â }
>>> Â EXPORT_SYMBOL_GPL(led_classdev_flash_unregister);
>>> Â +static void devm_led_classdev_flash_release(struct device *dev,
>>> void *res)
>>> +{
>>> +ÂÂÂ led_classdev_flash_unregister(*(struct led_classdev_flash **)res);
>>> +}
>>> +
>>> +int devm_led_classdev_flash_register_ext(struct device *parent,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct led_classdev_flash *fled_cdev,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct led_init_data *init_data)
>>> +{
>>> +ÂÂÂ struct led_classdev_flash **dr;
>>> +ÂÂÂ int ret;
>>> +
>>> +ÂÂÂ dr = devres_alloc(devm_led_classdev_flash_release, sizeof(*dr),
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
>>> +ÂÂÂ if (!dr)
>>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>>> +
>>> +ÂÂÂ ret = led_classdev_flash_register_ext(parent, fled_cdev,
>>> init_data);
>>> +ÂÂÂ if (ret) {
>>> +ÂÂÂÂÂÂÂ devres_free(dr);
>>> +ÂÂÂÂÂÂÂ return ret;
>>> +ÂÂÂ }
>>> +
>>> +ÂÂÂ *dr = fled_cdev;
>>> +ÂÂÂ devres_add(parent, dr);
>>> +
>>> +ÂÂÂ return 0;
>>> +}
>>> +EXPORT_SYMBOL_GPL(devm_led_classdev_flash_register_ext);
>>> +
>>> +static int devm_led_classdev_flash_match(struct device *dev,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ void *res, void *data)
>>> +{
>>> +ÂÂÂ struct fled_cdev **p = res;
>> We don't have struct fled_cdev. This name is used for variables
>> of struct led_clssdev_flash type in drivers.
>>
>> We don't get even compiler warning here because this is cast
>> from void pointer.
>>
>> Funny thing is that you seem to have followed similar flaw in
>> devm_led_classdev_match() where struct led_cdev has been
>> introduced.
>>
>> We need to fix both cases.
>
> OK I will fix the leds-class in a separate patch in case it causes issues.
It doesn't cause issues now but is misleading.
--
Best regards,
Jacek Anaszewski