linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Ian Pilcher <arequipeno@gmail.com>
Cc: axboe@kernel.dk, pavel@ucw.cz, linux-leds@vger.kernel.org,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	kabel@kernel.org
Subject: Re: [PATCH v2 10/15] leds: trigger: blkdev: Add LED trigger activate function
Date: Fri, 10 Sep 2021 08:47:37 +0200	[thread overview]
Message-ID: <YTr/iQBYclqjFri2@kroah.com> (raw)
In-Reply-To: <20210909222513.2184795-11-arequipeno@gmail.com>

On Thu, Sep 09, 2021 at 05:25:08PM -0500, Ian Pilcher wrote:
> Allocate per-LED data structure and initialize with default values
> 
> Create /sys/class/leds/<led>/block_devices directory
> 
> Increment module reference count.  Module can only be removed when no LEDs
> are associated with the trigger.
> 
> Signed-off-by: Ian Pilcher <arequipeno@gmail.com>
> ---
>  drivers/leds/trigger/ledtrig-blkdev.c | 57 +++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
> 
> diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c
> index 40dc55e5d4f3..6f78a9515976 100644
> --- a/drivers/leds/trigger/ledtrig-blkdev.c
> +++ b/drivers/leds/trigger/ledtrig-blkdev.c
> @@ -164,6 +164,62 @@ static void blkdev_process(struct work_struct *const work)
>  }
>  
>  
> +/*
> + *
> + *	Associate an LED with the blkdev trigger
> + *
> + */
> +
> +static int blkdev_activate(struct led_classdev *const led_dev)
> +{
> +	struct ledtrig_blkdev_led *led;
> +	int ret;
> +
> +	/* Don't allow module to be removed while any LEDs are linked */
> +	if (WARN_ON(!try_module_get(THIS_MODULE))) {

That pattern is racy and broken and never ever ever add it to the kernel
again please.  All existing in-kernel users of it are also wrong, we
have been removing them for decades now.

> +		ret = -ENODEV;		/* Shouldn't ever happen */
> +		goto exit_return;
> +	}
> +
> +	led = kmalloc(sizeof(*led), GFP_KERNEL);
> +	if (led == NULL) {
> +		ret = -ENOMEM;
> +		goto exit_put_module;
> +	}
> +
> +	led->led_dev = led_dev;
> +	led->blink_msec = LEDTRIG_BLKDEV_BLINK_MSEC;
> +	led->mode = LEDTRIG_BLKDEV_MODE_RW;
> +	INIT_HLIST_HEAD(&led->disks);
> +
> +	ret = mutex_lock_interruptible(&ledtrig_blkdev_mutex);
> +	if (ret != 0)
> +		goto exit_free;
> +
> +	led->dir = kobject_create_and_add("linked_devices",
> +					  &led_dev->dev->kobj);

You have created a "raw" kobject in the device tree now, which means
that userspace will not be notified of it and will have a "hole" in it's
knowledge.  Why not just create a named attribute group to this device
instead?

> +	if (led->dir == NULL) {
> +		ret = -ENOMEM;
> +		goto exit_unlock;
> +	}
> +
> +	hlist_add_head(&led->leds_node, &ledtrig_blkdev_leds);
> +	led_set_trigger_data(led_dev, led);
> +	ret = 0;
> +
> +exit_unlock:
> +	mutex_unlock(&ledtrig_blkdev_mutex);
> +exit_free:
> +	if (ret != 0)
> +		kfree(led);
> +exit_put_module:
> +	if (ret != 0)
> +		module_put(THIS_MODULE);

Again, racy and broken, please do not do this.

thanks,

greg k-h

  reply	other threads:[~2021-09-10  6:47 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 22:24 [PATCH v2 00/15] Introduce block device LED trigger Ian Pilcher
2021-09-09 22:24 ` [PATCH v2 01/15] docs: Add block device (blkdev) LED trigger documentation Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 02/15] leds: trigger: blkdev: Add build infrastructure Ian Pilcher
2021-09-10  1:32   ` Marek Behún
2021-09-09 22:25 ` [PATCH v2 03/15] leds: trigger: blkdev: Add functions needed by block changes Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 04/15] block: Add block device LED trigger integrations Ian Pilcher
2021-09-09 23:27   ` Chaitanya Kulkarni
2021-09-10  1:23   ` Marek Behún
2021-09-10 15:00     ` Ian Pilcher
2021-09-10  1:38   ` Marek Behún
2021-09-09 22:25 ` [PATCH v2 05/15] leds: trigger: blkdev: Complete functions called by block subsys Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 06/15] leds: trigger: blkdev: Add function to get gendisk by name Ian Pilcher
2021-09-10  6:45   ` Greg KH
2021-09-10 15:17     ` Ian Pilcher
2021-09-10 15:23       ` Greg KH
2021-09-10 16:28     ` Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 07/15] leds: trigger: blkdev: Add constants and types Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 08/15] leds: trigger: blkdev: Add stub LED trigger structure Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 09/15] leds: trigger: blkdev: Check devices for activity and blink LEDs Ian Pilcher
2021-09-10  1:48   ` Marek Behún
2021-09-10  2:17   ` Marek Behún
2021-09-10 15:09     ` Ian Pilcher
2021-09-10 15:12       ` Marek Behún
2021-09-10 21:23         ` Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 10/15] leds: trigger: blkdev: Add LED trigger activate function Ian Pilcher
2021-09-10  6:47   ` Greg KH [this message]
2021-09-10 16:10     ` Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 11/15] leds: trigger: blkdev: Enable linking block devices to LEDs Ian Pilcher
2021-09-10  6:48   ` Greg KH
2021-09-10 16:25     ` Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 12/15] leds: trigger: blkdev: Enable unlinking block devices from LEDs Ian Pilcher
2021-09-14  9:58   ` Dan Carpenter
2021-09-09 22:25 ` [PATCH v2 13/15] leds: trigger: blkdev: Add LED trigger deactivate function Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 14/15] leds: trigger: blkdev: Add remaining sysfs attributes Ian Pilcher
2021-09-09 22:25 ` [PATCH v2 15/15] leds: trigger: blkdev: Add disk cleanup and init/exit functions Ian Pilcher
2021-09-10  2:09 ` [PATCH v2 00/15] Introduce block device LED trigger Marek Behún
2021-09-10 14:04   ` Ian Pilcher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YTr/iQBYclqjFri2@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=arequipeno@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=kabel@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).