Message ID | 20230119130053.111344-4-hdegoede@redhat.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | leds: lookup-table support + int3472/media privacy LED support | expand |
On Thu, Jan 19, 2023 at 3:01 PM Hans de Goede <hdegoede@redhat.com> wrote: > > Add a __devm_led_get() helper which registers a passed in led_classdev > with devm for unregistration. > > This is a preparation patch for adding a generic (non devicetree specific) > devm_led_get() function. It's just a move of the existing code... Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> ...but I would expect that someone converts this to use devm_add_action_or_reset(). > Signed-off-by: Hans de Goede <hdegoede@redhat.com> > --- > drivers/leds/led-class.c | 29 +++++++++++++++++------------ > 1 file changed, 17 insertions(+), 12 deletions(-) > > diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c > index 743d97b082dc..4904d140a560 100644 > --- a/drivers/leds/led-class.c > +++ b/drivers/leds/led-class.c > @@ -274,6 +274,22 @@ static void devm_led_release(struct device *dev, void *res) > led_put(*p); > } > > +static struct led_classdev *__devm_led_get(struct device *dev, struct led_classdev *led) > +{ > + struct led_classdev **dr; > + > + dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *), GFP_KERNEL); > + if (!dr) { > + led_put(led); > + return ERR_PTR(-ENOMEM); > + } > + > + *dr = led; > + devres_add(dev, dr); > + > + return led; > +} > + > /** > * devm_of_led_get - Resource-managed request of a LED device > * @dev: LED consumer > @@ -289,7 +305,6 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev, > int index) > { > struct led_classdev *led; > - struct led_classdev **dr; > > if (!dev) > return ERR_PTR(-EINVAL); > @@ -298,17 +313,7 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev, > if (IS_ERR(led)) > return led; > > - dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *), > - GFP_KERNEL); > - if (!dr) { > - led_put(led); > - return ERR_PTR(-ENOMEM); > - } > - > - *dr = led; > - devres_add(dev, dr); > - > - return led; > + return __devm_led_get(dev, led); > } > EXPORT_SYMBOL_GPL(devm_of_led_get); > > -- > 2.39.0 >
On Thu, Jan 19, 2023 at 2:01 PM Hans de Goede <hdegoede@redhat.com> wrote: > Add a __devm_led_get() helper which registers a passed in led_classdev > with devm for unregistration. > > This is a preparation patch for adding a generic (non devicetree specific) > devm_led_get() function. > > Signed-off-by: Hans de Goede <hdegoede@redhat.com> I'm not a fan of __inner_functions because they are easy to confuse with the namespace for __compiler_directives but no big deal so: Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 743d97b082dc..4904d140a560 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -274,6 +274,22 @@ static void devm_led_release(struct device *dev, void *res) led_put(*p); } +static struct led_classdev *__devm_led_get(struct device *dev, struct led_classdev *led) +{ + struct led_classdev **dr; + + dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *), GFP_KERNEL); + if (!dr) { + led_put(led); + return ERR_PTR(-ENOMEM); + } + + *dr = led; + devres_add(dev, dr); + + return led; +} + /** * devm_of_led_get - Resource-managed request of a LED device * @dev: LED consumer @@ -289,7 +305,6 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev, int index) { struct led_classdev *led; - struct led_classdev **dr; if (!dev) return ERR_PTR(-EINVAL); @@ -298,17 +313,7 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev, if (IS_ERR(led)) return led; - dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *), - GFP_KERNEL); - if (!dr) { - led_put(led); - return ERR_PTR(-ENOMEM); - } - - *dr = led; - devres_add(dev, dr); - - return led; + return __devm_led_get(dev, led); } EXPORT_SYMBOL_GPL(devm_of_led_get);
Add a __devm_led_get() helper which registers a passed in led_classdev with devm for unregistration. This is a preparation patch for adding a generic (non devicetree specific) devm_led_get() function. Signed-off-by: Hans de Goede <hdegoede@redhat.com> --- drivers/leds/led-class.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)