mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] leds: blinkm: Clean up sysfs group on LED registration failure
@ 2026-09-26  0:03 Myeonghun Pak
  2026-10-15 11:54 ` Lee Jones
  0 siblings, 1 reply; 3+ messages in thread
From: Myeonghun Pak @ 2026-09-26  0:03 UTC (permalink / raw)
  To: Jan-Simon Moeller
  Cc: Lee Jones, Pavel Machek, Joseph Strauss, linux-leds,
	linux-kernel, stable

blinkm_probe() creates the BlinkM sysfs group before registering the LED
class devices. If multicolor sub-LED allocation fails, probe returns
without removing the group. If multicolor LED registration fails, the
helper removes the group but returns success, leaving the device bound
without an LED class device.

Keep LED class device rollback in the registration helpers, but remove
the BlinkM sysfs group in blinkm_probe() when either registration mode
fails. Propagate the multicolor registration error so probe can perform
this cleanup and report the failure.

Fixes: 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
Changes in v2:
- Move sysfs group cleanup to blinkm_probe() for both LED registration modes.
- Propagate multicolor LED registration errors to blinkm_probe().

 drivers/leds/leds-blinkm.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c
--- a/drivers/leds/leds-blinkm.c
+++ b/drivers/leds/leds-blinkm.c
@@ -671,7 +671,6 @@ failblue:
 failgreen:
 	led_classdev_unregister(&leds[RED]->cdev.led_cdev);
 failred:
-	sysfs_remove_group(&client->dev.kobj, &blinkm_group);
 
 	return err;
 }
@@ -714,9 +713,8 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da
 	if (err < 0) {
 		dev_err(&client->dev, "couldn't register LED %s\n",
 				mc_led->cdev.led_cdev.name);
-		sysfs_remove_group(&client->dev.kobj, &blinkm_group);
 	}
-	return 0;
+	return err;
 }
 
 static int blinkm_probe(struct i2c_client *client)
@@ -749,13 +747,12 @@ static int blinkm_probe(struct i2c_client *client)
 	}
 
-	if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR)) {
+	if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR))
 		err = register_separate_colors(client, data);
-		if (err < 0)
-			return err;
-	} else {
+	else
 		err = register_multicolor(client, data);
-		if (err < 0)
-			return err;
+	if (err < 0) {
+		sysfs_remove_group(&client->dev.kobj, &blinkm_group);
+		return err;
 	}
 
 	blinkm_init_hw(client);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] leds: blinkm: Clean up sysfs group on LED registration failure
  2026-09-26  0:03 [PATCH v2] leds: blinkm: Clean up sysfs group on LED registration failure Myeonghun Pak
@ 2026-10-15 11:54 ` Lee Jones
  2026-10-15 12:51   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2026-10-15 11:54 UTC (permalink / raw)
  To: Myeonghun Pak
  Cc: Jan-Simon Moeller, Pavel Machek, Joseph Strauss, linux-leds,
	linux-kernel, stable

On Fri, 25 Sep 2026, Myeonghun Pak wrote:

> blinkm_probe() creates the BlinkM sysfs group before registering the LED
> class devices. If multicolor sub-LED allocation fails, probe returns
> without removing the group. If multicolor LED registration fails, the
> helper removes the group but returns success, leaving the device bound
> without an LED class device.
>
> Keep LED class device rollback in the registration helpers, but remove
> the BlinkM sysfs group in blinkm_probe() when either registration mode
> fails. Propagate the multicolor registration error so probe can perform
> this cleanup and report the failure.
>
> Fixes: 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Co-developed-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
> ---
> Changes in v2:
> - Move sysfs group cleanup to blinkm_probe() for both LED registration modes.
> - Propagate multicolor LED registration errors to blinkm_probe().
>
>  drivers/leds/leds-blinkm.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c
> --- a/drivers/leds/leds-blinkm.c
> +++ b/drivers/leds/leds-blinkm.c
> @@ -671,7 +671,6 @@ failblue:
>  failgreen:
>  	led_classdev_unregister(&leds[RED]->cdev.led_cdev);
>  failred:
> -	sysfs_remove_group(&client->dev.kobj, &blinkm_group);
>
>  	return err;
>  }
> @@ -714,9 +713,8 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da
>  	if (err < 0) {
>  		dev_err(&client->dev, "couldn't register LED %s\n",
>  				mc_led->cdev.led_cdev.name);
> -		sysfs_remove_group(&client->dev.kobj, &blinkm_group);
>  	}
> -	return 0;
> +	return err;
>  }
>
>  static int blinkm_probe(struct i2c_client *client)
> @@ -749,13 +747,12 @@ static int blinkm_probe(struct i2c_client *client)
>  	}
>
> -	if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR)) {
> +	if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR))
>  		err = register_separate_colors(client, data);
> -		if (err < 0)
> -			return err;
> -	} else {
> +	else
>  		err = register_multicolor(client, data);

Please add a newline after the 'if-else' block.

> -		if (err < 0)
> -			return err;
> +	if (err < 0) {
> +		sysfs_remove_group(&client->dev.kobj, &blinkm_group);

How about using 'devm_device_add_group() to automate clean-up?

> +		return err;
>  	}
>
>  	blinkm_init_hw(client);

-- 
Lee Jones

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] leds: blinkm: Clean up sysfs group on LED registration failure
  2026-10-15 11:54 ` Lee Jones
@ 2026-10-15 12:51   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-10-15 12:51 UTC (permalink / raw)
  To: Lee Jones
  Cc: Myeonghun Pak, Jan-Simon Moeller, Pavel Machek, Joseph Strauss,
	linux-leds, linux-kernel, stable

On Thu, Oct 15, 2026 at 12:54:33PM +0100, Lee Jones wrote:
> On Fri, 25 Sep 2026, Myeonghun Pak wrote:
> 
> > blinkm_probe() creates the BlinkM sysfs group before registering the LED
> > class devices. If multicolor sub-LED allocation fails, probe returns
> > without removing the group. If multicolor LED registration fails, the
> > helper removes the group but returns success, leaving the device bound
> > without an LED class device.
> >
> > Keep LED class device rollback in the registration helpers, but remove
> > the BlinkM sysfs group in blinkm_probe() when either registration mode
> > fails. Propagate the multicolor registration error so probe can perform
> > this cleanup and report the failure.
> >
> > Fixes: 56e8c56c9af0 ("leds: Add multicolor support to BlinkM LED driver")
> > Cc: stable@vger.kernel.org
> > Assisted-by: LLM
> > Co-developed-by: Ijae Kim <ae878000@gmail.com>
> > Signed-off-by: Ijae Kim <ae878000@gmail.com>
> > Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
> > ---
> > Changes in v2:
> > - Move sysfs group cleanup to blinkm_probe() for both LED registration modes.
> > - Propagate multicolor LED registration errors to blinkm_probe().
> >
> >  drivers/leds/leds-blinkm.c | 15 ++++++---------
> >  1 file changed, 6 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c
> > --- a/drivers/leds/leds-blinkm.c
> > +++ b/drivers/leds/leds-blinkm.c
> > @@ -671,7 +671,6 @@ failblue:
> >  failgreen:
> >  	led_classdev_unregister(&leds[RED]->cdev.led_cdev);
> >  failred:
> > -	sysfs_remove_group(&client->dev.kobj, &blinkm_group);
> >
> >  	return err;
> >  }
> > @@ -714,9 +713,8 @@ static int register_multicolor(struct i2c_client *client, struct blinkm_data *da
> >  	if (err < 0) {
> >  		dev_err(&client->dev, "couldn't register LED %s\n",
> >  				mc_led->cdev.led_cdev.name);
> > -		sysfs_remove_group(&client->dev.kobj, &blinkm_group);
> >  	}
> > -	return 0;
> > +	return err;
> >  }
> >
> >  static int blinkm_probe(struct i2c_client *client)
> > @@ -749,13 +747,12 @@ static int blinkm_probe(struct i2c_client *client)
> >  	}
> >
> > -	if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR)) {
> > +	if (!IS_ENABLED(CONFIG_LEDS_BLINKM_MULTICOLOR))
> >  		err = register_separate_colors(client, data);
> > -		if (err < 0)
> > -			return err;
> > -	} else {
> > +	else
> >  		err = register_multicolor(client, data);
> 
> Please add a newline after the 'if-else' block.
> 
> > -		if (err < 0)
> > -			return err;
> > +	if (err < 0) {
> > +		sysfs_remove_group(&client->dev.kobj, &blinkm_group);
> 
> How about using 'devm_device_add_group() to automate clean-up?

Wait, why is a driver manually adding sysfs files at all?  Shouldn't
this "just work" if it's a default group for the driver?  This way (or
with the devm_device_add_group() call) will race with userspace and
loose.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-15 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26  0:03 [PATCH v2] leds: blinkm: Clean up sysfs group on LED registration failure Myeonghun Pak
2026-10-15 11:54 ` Lee Jones
2026-10-15 12:51   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®