lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YTr/2bflThomjHqL@kroah.com>
Date:   Fri, 10 Sep 2021 08:48:57 +0200
From:   Greg KH <gregkh@...uxfoundation.org>
To:     Ian Pilcher <arequipeno@...il.com>
Cc:     axboe@...nel.dk, pavel@....cz, linux-leds@...r.kernel.org,
        linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
        kabel@...nel.org
Subject: Re: [PATCH v2 11/15] leds: trigger: blkdev: Enable linking block
 devices to LEDs

On Thu, Sep 09, 2021 at 05:25:09PM -0500, Ian Pilcher wrote:
> Add /sys/class/leds/<led>/link_device sysfs attribute
> 
> If this is the first LED associated with the device, create the
> /sys/block/<disk>/blkdev_leds directory.  Otherwise, increment its
> reference count.
> 
> Create symlinks in /sys/class/leds/<led>/block_devices and
> /sys/block/<disk>/blkdev_leds
> 
> If this the first device associated with *any* LED, schedule delayed work
> to periodically check associated devices and blink LEDs
> 
> Signed-off-by: Ian Pilcher <arequipeno@...il.com>
> ---
>  drivers/leds/trigger/ledtrig-blkdev.c | 160 ++++++++++++++++++++++++++
>  1 file changed, 160 insertions(+)
> 
> diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c
> index 6f78a9515976..26509837f037 100644
> --- a/drivers/leds/trigger/ledtrig-blkdev.c
> +++ b/drivers/leds/trigger/ledtrig-blkdev.c
> @@ -71,6 +71,9 @@ static unsigned int ledtrig_blkdev_interval;
>  static void blkdev_process(struct work_struct *const work);
>  static DECLARE_DELAYED_WORK(ledtrig_blkdev_work, blkdev_process);
>  
> +/* Total number of device-to-LED associations */
> +static unsigned int ledtrig_blkdev_count;
> +
>  
>  /*
>   *
> @@ -220,6 +223,162 @@ static int blkdev_activate(struct led_classdev *const led_dev)
>  }
>  
>  
> +/*
> + *
> + *	link_device sysfs attribute - assocate a block device with this LED
> + *
> + */
> +
> +/* Gets or allocs & initializes the blkdev disk for a gendisk */
> +static int blkdev_get_disk(struct gendisk *const gd)
> +{
> +	struct ledtrig_blkdev_disk *disk;
> +	struct kobject *dir;
> +
> +	if (gd->ledtrig != NULL) {
> +		kobject_get(gd->ledtrig->dir);

When do you decrement this kobject?

> +		return 0;
> +	}
> +
> +	disk = kmalloc(sizeof(*disk), GFP_KERNEL);
> +	if (disk == NULL)
> +		return -ENOMEM;
> +
> +	dir = kobject_create_and_add("linked_leds", &disk_to_dev(gd)->kobj);
> +	if (dir == NULL) {
> +		kfree(disk);
> +		return -ENOMEM;
> +	}
> +
> +	INIT_HLIST_HEAD(&disk->leds);
> +	disk->gd = gd;
> +	disk->dir = dir;
> +	disk->read_ios = 0;
> +	disk->write_ios = 0;
> +
> +	gd->ledtrig = disk;
> +
> +	return 0;
> +}
> +
> +static void blkdev_put_disk(struct ledtrig_blkdev_disk *const disk)
> +{
> +	kobject_put(disk->dir);
> +
> +	if (hlist_empty(&disk->leds)) {
> +		disk->gd->ledtrig = NULL;
> +		kfree(disk);

This should happen in the kobject release function, not here, right?

Did you try this out with removable block devices yet?

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ