Message ID | 20240828121353.3696414-1-lihongbo22@huawei.com |
---|---|
State | New |
Headers | show |
Series | [-next] leds: gpio: make use of dev_err_cast_probe() | expand |
Hi! > Using dev_err_cast_probe() to simplify the code. > > Signed-off-by: Hongbo Li <lihongbo22@huawei.com> > --- > drivers/leds/leds-gpio.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c > index 83fcd7b6afff..d323c2954234 100644 > --- a/drivers/leds/leds-gpio.c > +++ b/drivers/leds/leds-gpio.c > @@ -172,10 +172,9 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev) > led.gpiod = devm_fwnode_gpiod_get(dev, child, NULL, GPIOD_ASIS, > NULL); > if (IS_ERR(led.gpiod)) { > - dev_err_probe(dev, PTR_ERR(led.gpiod), "Failed to get GPIO '%pfw'\n", > - child); > fwnode_handle_put(child); > - return ERR_CAST(led.gpiod); > + return dev_err_cast_probe(dev, led.gpiod, > + "Failed to get GPIO '%pfw'\n", child); > } Is that correct? child should not be used after put(child) would be my first guess. BR, Pavel
On 2024/8/28 20:48, Pavel Machek wrote: > Hi! > >> Using dev_err_cast_probe() to simplify the code. >> >> Signed-off-by: Hongbo Li <lihongbo22@huawei.com> >> --- >> drivers/leds/leds-gpio.c | 5 ++--- >> 1 file changed, 2 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c >> index 83fcd7b6afff..d323c2954234 100644 >> --- a/drivers/leds/leds-gpio.c >> +++ b/drivers/leds/leds-gpio.c >> @@ -172,10 +172,9 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev) >> led.gpiod = devm_fwnode_gpiod_get(dev, child, NULL, GPIOD_ASIS, >> NULL); >> if (IS_ERR(led.gpiod)) { >> - dev_err_probe(dev, PTR_ERR(led.gpiod), "Failed to get GPIO '%pfw'\n", >> - child); >> fwnode_handle_put(child); >> - return ERR_CAST(led.gpiod); >> + return dev_err_cast_probe(dev, led.gpiod, >> + "Failed to get GPIO '%pfw'\n", child); >> } > > Is that correct? child should not be used after put(child) would be my > first guess. > oh, that's wrong. My mistake. It seems cannot be simplified due to the printed child variable. Thanks, Hongbo > BR, > Pavel
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 83fcd7b6afff..d323c2954234 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -172,10 +172,9 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev) led.gpiod = devm_fwnode_gpiod_get(dev, child, NULL, GPIOD_ASIS, NULL); if (IS_ERR(led.gpiod)) { - dev_err_probe(dev, PTR_ERR(led.gpiod), "Failed to get GPIO '%pfw'\n", - child); fwnode_handle_put(child); - return ERR_CAST(led.gpiod); + return dev_err_cast_probe(dev, led.gpiod, + "Failed to get GPIO '%pfw'\n", child); } led_dat->gpiod = led.gpiod;
Using dev_err_cast_probe() to simplify the code. Signed-off-by: Hongbo Li <lihongbo22@huawei.com> --- drivers/leds/leds-gpio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)