Skip to contentSkip to conversation

Introduce block device LED trigger

PATCH Superseded Ian Pilcher 4 participants 10 messages Sep 16, 2021 – Oct 5, 2021

Subsystems (2)

v4 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v4 cover Introduce block device LED trigger

Changes from v3:
================

* Use blkdev_get_by_path() to "resolve" block devices (struct block_device). With this change, there are now no changes required to the block subsystem, so there are only 2 patches in this series.

* link_device and unlink_device attributes now take paths to block device special files (e.g. /dev/sda), rather than kernel names. Symbolic links also work.

If the path written to the attribute doesn't exist (-ENOENT), we re-try with /dev/ prepended, so "simple" names like sda will still work as long as the corresponding special file exists in /dev.

* Fixed a bug that could cause "phantom" blinks because of old device activity that was not recognized at the correct time.

* (Slightly) more detailed commit message for the patch that adds the trigger code. As with v3, the real details are found in the comments in the source file.

Changes from v2:
================

* Allow LEDs to be "linked" to partitions, as well as whole devices. Internally, the trigger now works with block_device structs, rather than gendisk structs.

(Investigating the lifecycle of block_device structs led me to discover the device resource API, so ...)

* Use the device resource API to manage the trigger's per-block device data structure (struct led_bdev_bdi). The trigger now uses a release function to remove references to block devices that have been removed.

Because the release function is automatically called by the driver core, there is no longer any need for the block layer to explictly call the trigger's cleanup function.

* Since there is no need to provide a built-in "stub" cleanup function when the trigger is built as a module, I have removed the always built-in "core" portion of the trigger.

* Without a built-in component, the module does need access to the block_class symbol. The second patch in this series exports the symbol to the LEDTRIG_BLKDEV namespace and explains the reason for doing so.

* Changed the interval sysfs attribute from a device attribute to a class attribute. It's single value that applies to all LEDs, so it didn't make sense as a device atribute.

* As requested, I am posting the trigger code (ledtrig-blkdev.c) as a single patch. This eliminates the commit messages that would otherwise describe sections of the code, so I have added fairly extensive comments to each function.

Changes from v1:
================

* Use correct address for LKML.

* Renamed the sysfs attributes used to manage and view the set of block devices associated ("linked") with an LED.

- /sys/class/leds/<LED>/link_device to create associations

- /sys/class/leds/<LED>/unlink_device to remove associations

- /sys/class/leds/<LED>/linked_devices/ contains symlinks to all block devices associated with the LED

- /sys/block/<DEVICE>/linked_leds (which only exists when the device is associated with at least one LED) contains symlinks to all LEDs with which the device is associated

link_device and unlink_device are write-only attributes, each of which represents a single action, rather than any state. (The current state is shown by the symbolic links in the <LED>/linked_devices/ and <DEVICE>/linked_leds/ directories.)

* Simplified sysfs attribute store functions. link_device and unlink_device no longer accept multiple devices at once, but this was really just an artifact of the way that sysfs repeatedly calls the store function when it doesn't "consume" all of its input, and it seemed to be confusing and unpopular anyway.

* Use DEVICE_ATTR_* macros (rather than __ATTR) for the sysfs attributes.

* Removed all pr_info() "system administrator error" messages.

* Different minimum values for LED blink time (10 ms) and activity check interval (25 ms).

v1 summary:
===========

This patch series adds a new "blkdev" LED trigger for disk (or other block device) activity LEDs.

It has the following functionality.

* Supports all types of block devices, including virtual devices (unlike the existing disk trigger which only works with ATA devices).

* LEDs can be configured to show read activity, write activity, or both.

* Supports multiple devices and multiple LEDs in arbitrary many-to-many configurations. For example, it is possible to configure multiple devices with device-specific read activity LEDs and a shared write activity LED. (See Documentation/leds/ledtrig-blkdev.rst in the first patch.)

* Doesn't add any overhead in the I/O path. Like the netdev LED trigger, it periodically checks the configured devices for activity and blinks its LEDs as appropriate.

* Blink duration (per LED) and interval between activity checks (global) are configurable.

* Requires minimal changes to the block subsystem.

- Adds 1 pointer to struct gendisk,

- Adds (inline function) call in device_add_disk() to ensure that the pointer is initialized to NULL (as protection against any drivers that allocate a gendisk themselves and don't use kzalloc()), and

- Adds call in del_gendisk() to remove a device from the trigger when that device is being removed.

These changes are all in patch #4, "block: Add block device LED trigger integrations."

* The trigger can be mostly built as a module.

When the trigger is modular, a small portion is built in to provide a "stub" function which can be called from del_gendisk(). The stub calls into the modular code via a function pointer when needed. The trigger also needs the ability to find gendisk's by name, which requires access to the un-exported block_class and disk_type symbols.

Ian Pilcher (2):
docs: Add block device (blkdev) LED trigger documentation
leds: trigger: Add block device LED trigger

 Documentation/ABI/testing/sysfs-block         |   9 +
 .../testing/sysfs-class-led-trigger-blkdev    |  50 +
 Documentation/leds/index.rst                  |   1 +
 Documentation/leds/ledtrig-blkdev.rst         | 149 +++
 drivers/leds/trigger/Kconfig                  |   9 +
 drivers/leds/trigger/Makefile                 |   1 +
 drivers/leds/trigger/ledtrig-blkdev.c         | 981 ++++++++++++++++++
 7 files changed, 1200 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-blkdev
 create mode 100644 Documentation/leds/ledtrig-blkdev.rst
 create mode 100644 drivers/leds/trigger/ledtrig-blkdev.c

base-commit: ff1ffd71d5f0612cf194f5705c671d6b64bf5f91

Signature · 1 line
2.31.1
#1 lore raw

PATCH v4 1/2 docs: Add block device (blkdev) LED trigger documentation

Add Documentation/ABI/testing/sysfs-class-led-trigger-blkdev to document:

* /sys/class/leds/<led>/blink_time
* /sys/class/leds/<led>/mode
* /sys/class/leds/<led>/link_device
* /sys/class/leds/<led>/unlink_device
* /sys/class/leds/<led>/linked_devices
* /sys/class/ledtrig_blkdev/interval

Add /sys/block/<disk>/linked_leds to
Documentation/ABI/testing/sysfs-block.

Add overview in Documentation/leds/ledtrig-blkdev.rst.

---
 Documentation/ABI/testing/sysfs-block         |   9 ++
 .../testing/sysfs-class-led-trigger-blkdev    |  50 ++++++
 Documentation/leds/index.rst                  |   1 +
 Documentation/leds/ledtrig-blkdev.rst         | 149 ++++++++++++++++++
 4 files changed, 209 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-blkdev
 create mode 100644 Documentation/leds/ledtrig-blkdev.rst
Documentation/ABI/testing/sysfs-block +9 -0
index a0ed87386639..80d4becc4e6d 100644
@@ -328,3 +328,12 @@ Description:
 		does not complete in this time then the block driver timeout
 		handler is invoked. That timeout handler can decide to retry
 		the request, to fail it or to start a device recovery strategy.
+
+What:		/sys/block/<disk>/linked_leds
+Date:		September 2021
+Contact:	Ian Pilcher <[email protected]>
+Description:
+		Directory containing links to all LEDs that are associated
+		with this block device through the blkdev LED trigger.  Only
+		present when at least one LED is associated.  (See
+		Documentation/leds/ledtrig-blkdev.rst.)
Documentation/ABI/testing/sysfs-class-led-trigger-blkdev new file +50 -0

50 lines not on this page · raw message

Documentation/leds/index.rst +1 -0
index e5d63b940045..e3c24e468cbc 100644
@@ -10,6 +10,7 @@ LEDs
    leds-class
    leds-class-flash
    leds-class-multicolor
+   ledtrig-blkdev
    ledtrig-oneshot
    ledtrig-transient
    ledtrig-usbport
Documentation/leds/ledtrig-blkdev.rst new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH v4 1/2] docs: Add block device (blkdev) LED trigger documentation

Documentation/ABI/testing/sysfs-class-led-trigger-blkdev line 24

Quoted 8 lines · Ian Pilcher
Documentation/ABI/testing/sysfs-class-led-trigger-blkdev new file +8 -0
+What:		/sys/class/leds/<led>/link_device
+Date:		September 2021
+Contact:	Ian Pilcher <[email protected]>
+Description:
+		Associate a block device with this LED by writing the path to
+		the device special file (e.g. /dev/sda) to this attribute.
+		Symbolic links are followed.  Optionally, the leading "/dev/"
+		may be omitted.

No, please don't follow symlinks, stick with kernel names here, otherwise you have a mismatch between that and the list of devices in this file:

Quoted 1 line

+What: /sys/class/leds/<led>/linked_devices

thanks,

greg k-h

#3 lore raw

Re: [PATCH v4 1/2] docs: Add block device (blkdev) LED trigger documentation

Combining 2 related threads ...

Quoted 15 lines · Greg KH

Documentation/ABI/testing/sysfs-class-led-trigger-blkdev line 24

Quoted 8 lines · Ian Pilcher
Documentation/ABI/testing/sysfs-class-led-trigger-blkdev new file +8 -0
+What:		/sys/class/leds/<led>/link_device
+Date:		September 2021
+Contact:	Ian Pilcher <[email protected]>
+Description:
+		Associate a block device with this LED by writing the path to
+		the device special file (e.g. /dev/sda) to this attribute.
+		Symbolic links are followed.  Optionally, the leading "/dev/"
+		may be omitted.

No, please don't follow symlinks, stick with kernel names here, otherwise you have a mismatch between that and the list of devices in this file:

Quoted 1 line

+What: /sys/class/leds/<led>/linked_devices

I did update the documentation to mention that fact.

Following symlinks is the behavior of blkdev_get_by_path(), not some- thing that my code is doing.

As far as using kernel names, that would be my preference, but I simply don't know of any way to do so with the existing block API. To my knowledge, there simply isn't anything like a blkdev_get_by_name() API.

This the reason that I added the "retry" logic to led_bdev_get(). It doesn't prevent the system administrator from using a symbolic link (or an oddly named special file), but it does make an unqualified name like "sda" work if the expected special file exists in /dev.

However ...

Quoted 24 lines · Christoph Hellwig
Quoted 23 lines · Ian Pilcher
(quoted diff) +23 -0
+static struct block_device *led_bdev_get(const char *const buf,
+					 const size_t count, fmode_t mode)
+{
+	static const char dev[] = "/dev/";
+	struct block_device *bdev;
+	char *dev_path, *path;
+
+	/* sizeof(dev) includes terminating null */
+	dev_path = kmalloc(sizeof(dev) + count, GFP_KERNEL);
+	if (dev_path == NULL)
+		return ERR_PTR(-ENOMEM);
+
+	/* sizeof(dev) - 1 is compile-time equivalent of strlen(dev) */
+	memcpy(dev_path, dev, sizeof(dev) - 1);
+	path = dev_path + sizeof(dev) - 1;
+	memcpy(path, buf, count + 1);  /* include terminating null */
+	strim(path);
+
+try_blkdev_get:
+	bdev = blkdev_get_by_path(path, mode, THIS_MODULE);
+	if (IS_ERR(bdev) && PTR_ERR(bdev) == -ENOENT && path != dev_path) {
+		path = dev_path;
+		goto try_blkdev_get;
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	}
+
+	kfree(dev_path);
+	return bdev;

Please just required the user to put in the whole path and remove all this garbage. There is no need to build your own broken wrappers around the VFS path resolution.

Please be specific about what is broken.

If you see an actual bug in the code, please tell me what it is.

If (as I suspect) you disagree with the basic idea of retrying with "/dev/" prepended to the supplied path, please say that.

Honestly, I wasn't particularly enthusiastic about it in the first place; it feels like something that should be done in user space. I wouldn't have included it if I didn't have to make a writable copy of the buffer anyway, in order to trim a trailing newline.

I can certainly remove the re-check logic. The end result will be an API that is slightly less "user friendly" in return for saving a bit of pointer arithmetic and a 5-byte memcpy().

Signature · 3 lines
========================================================================
                 In Soviet Russia, Google searches you!
========================================================================
#4 lore raw

Re: [PATCH v4 1/2] docs: Add block device (blkdev) LED trigger documentation

Quoted 76 lines · Ian Pilcher

Combining 2 related threads ...

Quoted 15 lines · Greg KH

Documentation/ABI/testing/sysfs-class-led-trigger-blkdev line 24

Quoted 8 lines · Ian Pilcher
Documentation/ABI/testing/sysfs-class-led-trigger-blkdev new file +8 -0
+What:		/sys/class/leds/<led>/link_device
+Date:		September 2021
+Contact:	Ian Pilcher <[email protected]>
+Description:
+		Associate a block device with this LED by writing the path to
+		the device special file (e.g. /dev/sda) to this attribute.
+		Symbolic links are followed.  Optionally, the leading "/dev/"
+		may be omitted.

No, please don't follow symlinks, stick with kernel names here, otherwise you have a mismatch between that and the list of devices in this file:

Quoted 1 line

+What: /sys/class/leds/<led>/linked_devices

I did update the documentation to mention that fact.

Following symlinks is the behavior of blkdev_get_by_path(), not some- thing that my code is doing.

As far as using kernel names, that would be my preference, but I simply don't know of any way to do so with the existing block API. To my knowledge, there simply isn't anything like a blkdev_get_by_name() API.

This the reason that I added the "retry" logic to led_bdev_get(). It doesn't prevent the system administrator from using a symbolic link (or an oddly named special file), but it does make an unqualified name like "sda" work if the expected special file exists in /dev.

However ...

Quoted 24 lines · Christoph Hellwig
Quoted 23 lines · Ian Pilcher
(quoted diff) +23 -0
+static struct block_device *led_bdev_get(const char *const buf,
+					 const size_t count, fmode_t mode)
+{
+	static const char dev[] = "/dev/";
+	struct block_device *bdev;
+	char *dev_path, *path;
+
+	/* sizeof(dev) includes terminating null */
+	dev_path = kmalloc(sizeof(dev) + count, GFP_KERNEL);
+	if (dev_path == NULL)
+		return ERR_PTR(-ENOMEM);
+
+	/* sizeof(dev) - 1 is compile-time equivalent of strlen(dev) */
+	memcpy(dev_path, dev, sizeof(dev) - 1);
+	path = dev_path + sizeof(dev) - 1;
+	memcpy(path, buf, count + 1);  /* include terminating null */
+	strim(path);
+
+try_blkdev_get:
+	bdev = blkdev_get_by_path(path, mode, THIS_MODULE);
+	if (IS_ERR(bdev) && PTR_ERR(bdev) == -ENOENT && path != dev_path) {
+		path = dev_path;
+		goto try_blkdev_get;
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	}
+
+	kfree(dev_path);
+	return bdev;

Please just required the user to put in the whole path and remove all this garbage. There is no need to build your own broken wrappers around the VFS path resolution.

Please be specific about what is broken.

If you see an actual bug in the code, please tell me what it is.

If (as I suspect) you disagree with the basic idea of retrying with "/dev/" prepended to the supplied path, please say that.

Quoted 8 lines

Honestly, I wasn't particularly enthusiastic about it in the first place; it feels like something that should be done in user space. I wouldn't have included it if I didn't have to make a writable copy of the buffer anyway, in order to trim a trailing newline.

I can certainly remove the re-check logic. The end result will be an API that is slightly less "user friendly" in return for saving a bit of pointer arithmetic and a 5-byte memcpy().

Just use the kernel block device name and that way you do not have to parse anything as it is unique and no paths are having to be followed.

That's the way that other LED apis are working, right?

thanks,

greg k-h

#5 lore raw

Re: [PATCH v4 1/2] docs: Add block device (blkdev) LED trigger documentation

Quoted 4 lines · Greg KH
Quoted 3 lines · Ian Pilcher

As far as using kernel names, that would be my preference, but I simply don't know of any way to do so with the existing block API. To my knowledge, there simply isn't anything like a blkdev_get_by_name() API.

...

Quoted 4 lines

Just use the kernel block device name and that way you do not have to parse anything as it is unique and no paths are having to be followed.

That's the way that other LED apis are working, right?

Greg -

There are 2 existing LED triggers that have similar functionality (i.e. they allow LEDs to be "associated" with devices by name), and they both use subsystem-specific APIs to "resolve" those names to the actual kernel objects on which they operate.

* The *netdev* trigger uses dev_get_by_name(), which is specific to network devices (despite its name).

* The *tty* trigger uses tty_dev_name_to_number() and

    tty_kopen_shared().

As I've been saying, I simply don't know of any similar API for block devices. The block API provides blkdev_get_by_path(), which I am using, and blkdev_get_by_dev(), which takes the device number (dev_t).

If you know of an API that will allow me to resolve a block device (or dev_t) by its kernel name, please share that information.

Thanks!

Signature · 3 lines
========================================================================
                 In Soviet Russia, Google searches you!
========================================================================
#6 lore raw

Re: [PATCH v4 1/2] docs: Add block device (blkdev) LED trigger documentation

In reply to Greg KH
Quoted 5 lines · Greg KH
Quoted 5 lines

Honestly, I wasn't particularly enthusiastic about it in the first place; it feels like something that should be done in user space. I wouldn't have included it if I didn't have to make a writable copy of the buffer anyway, in order to trim a trailing newline.

Quoted 8 lines
Quoted 3 lines

I can certainly remove the re-check logic. The end result will be an API that is slightly less "user friendly" in return for saving a bit of pointer arithmetic and a 5-byte memcpy().

Just use the kernel block device name and that way you do not have to parse anything as it is unique and no paths are having to be followed.

That's the way that other LED apis are working, right?

The "kernel block device name" is the a block device special path that a normal VFS path lookup is done on. This is the preferred block device API used by everyone. And yes, this includes resolving symlinks. The only other API is by dev_t, but it is highly discouraged and should really not grow any new users.

#7 lore raw

Re: [PATCH v4 1/2] docs: Add block device (blkdev) LED trigger documentation

Quoted 14 lines · On Mon, 20 Sep 2021 07:43:52 +0100 Christoph Hellwig <[email protected]> wrote:
Quoted 13 lines · Greg KH
Quoted 8 lines

Honestly, I wasn't particularly enthusiastic about it in the first place; it feels like something that should be done in user space.
I wouldn't have included it if I didn't have to make a writable
copy of the buffer anyway, in order to trim a trailing newline.

I can certainly remove the re-check logic. The end result will be an API that is slightly less "user friendly" in return for saving a bit of pointer arithmetic and a 5-byte memcpy().

Just use the kernel block device name and that way you do not have to parse anything as it is unique and no paths are having to be followed.

Quoted 7 lines
Quoted 1 line

That's the way that other LED apis are working, right?

The "kernel block device name" is the a block device special path that a normal VFS path lookup is done on. This is the preferred block device API used by everyone. And yes, this includes resolving symlinks. The only other API is by dev_t, but it is highly discouraged and should really not grow any new users.

Christoph,

/sys/class/block lists block devices' kernel object names.
I don't understand why can't blk API provide a function returns a block device given such name as seen in /sys/class/block directory.

Can you elaborate on this?

It seems really strange to me to not be able to do
cd /sys/class/leds/<LED>
echo blkdev >trigger
echo sda1 >block_device
and instead having to do (as the last command)
echo /dev/sda1 >block_device

And whas should we show when /dev/sda1 is paried to the trigger, and userspace reads the block_device sysfs file? Should we show the full path which was given when pairing, even if it may not be valid anymore? (Such as when the device file is removed from /dev.)

Marek

#8 lore raw

PATCH v4 2/2 leds: trigger: Add block device LED trigger

In reply to Ian Pilcher

Add "blkdev" LED trigger to blink LEDs in response to block device activity.

Add LEDS_TRIGGER_BLKDEV (tristate) config option to control building of the trigger.

---
 drivers/leds/trigger/Kconfig          |   9 +
 drivers/leds/trigger/Makefile         |   1 +
 drivers/leds/trigger/ledtrig-blkdev.c | 981 ++++++++++++++++++++++++++
 3 files changed, 991 insertions(+)
 create mode 100644 drivers/leds/trigger/ledtrig-blkdev.c
drivers/leds/trigger/Kconfig +9 -0
index 1f1d57288085..219d15c046d7 100644
@@ -153,4 +153,13 @@ config LEDS_TRIGGER_TTY
 
 	  When build as a module this driver will be called ledtrig-tty.
 
+config LEDS_TRIGGER_BLKDEV
+	tristate "LED Trigger for block devices"
+	depends on BLOCK
+	help
+	  The blkdev LED trigger allows LEDs to be controlled by block device
+	  activity (reads and writes).
+
+	  See Documentation/leds/ledtrig-blkdev.rst.
+
 endif # LEDS_TRIGGERS
drivers/leds/trigger/Makefile +1 -0
index 25c4db97cdd4..d53bab5d93f1 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_LEDS_TRIGGER_NETDEV)	+= ledtrig-netdev.o
 obj-$(CONFIG_LEDS_TRIGGER_PATTERN)	+= ledtrig-pattern.o
 obj-$(CONFIG_LEDS_TRIGGER_AUDIO)	+= ledtrig-audio.o
 obj-$(CONFIG_LEDS_TRIGGER_TTY)		+= ledtrig-tty.o
+obj-$(CONFIG_LEDS_TRIGGER_BLKDEV)	+= ledtrig-blkdev.o
drivers/leds/trigger/ledtrig-blkdev.c new file +981 -0

981 lines not on this page · raw message

Signature · 1 line
2.31.1
#9 lore raw

Re: [PATCH v4 2/2] leds: trigger: Add block device LED trigger

drivers/leds/trigger/ledtrig-blkdev.c line 30

Quoted 2 lines · Ian Pilcher
drivers/leds/trigger/ledtrig-blkdev.c new file +2 -0
+/* Block device information (BDI) - 1 per blkdev linked to at least 1 LED */
+struct led_bdev_bdi {

It might be a good idea to pick a differene name. BDI is a commonly used shortcut for the backing device information used all over the block layer and writeback code.

drivers/leds/trigger/ledtrig-blkdev.c line 46

Quoted 7 lines
drivers/leds/trigger/ledtrig-blkdev.c new file +7 -0
+/* For many-to-many relationships between block devices and LEDs */
+struct led_bdev_link {
+	struct hlist_node	bdi_leds_node;
+	struct hlist_node	led_bdis_node;
+	struct led_bdev_bdi	*bdi;
+	struct led_bdev_led	*led;
+};

Why not just use a xarray to link them which due to the non-invasive nature gets you n:m links "for free".

Quoted 4 lines
drivers/leds/trigger/ledtrig-blkdev.c new file +4 -0
+/* Forward declarations to make this file compile in a reasonable order */
+static void led_bdev_process(struct work_struct *work);
+static struct led_bdev_bdi *led_bdev_get_bdi(const char *buf, size_t size);
+static struct block_device *led_bdev_get(const char *buf, size_t size,

drivers/leds/trigger/ledtrig-blkdev.c line 70

Quoted 10 lines
drivers/leds/trigger/ledtrig-blkdev.c new file +10 -0
+					 fmode_t mode);
+static int led_bdev_link(struct led_bdev_led *led, struct led_bdev_bdi *bdi);
+static void led_bdev_put_bdi(struct led_bdev_bdi *bdi);
+static void led_bdev_bdi_release(struct device *dev, void *res);
+static void led_bdev_unlink(struct led_bdev_led *led,
+			    struct led_bdev_link *link,
+			    struct led_bdev_bdi *bdi, bool releasing);
+static void led_bdev_update_bdi(struct led_bdev_bdi *bdi);
+static bool led_bdev_blink(const struct led_bdev_led *led,
+			   const struct led_bdev_bdi *bdi);

I seriously question the "reasonable" above if you need that many forward declarations in brand new code.

Quoted 17 lines
drivers/leds/trigger/ledtrig-blkdev.c new file +17 -0
+static struct block_device *led_bdev_get(const char *const buf,
+					 const size_t count, fmode_t mode)
+{
+	static const char dev[] = "/dev/";
+	struct block_device *bdev;
+	char *dev_path, *path;
+
+	/* sizeof(dev) includes terminating null */
+	dev_path = kmalloc(sizeof(dev) + count, GFP_KERNEL);
+	if (dev_path == NULL)
+		return ERR_PTR(-ENOMEM);
+
+	/* sizeof(dev) - 1 is compile-time equivalent of strlen(dev) */
+	memcpy(dev_path, dev, sizeof(dev) - 1);
+	path = dev_path + sizeof(dev) - 1;
+	memcpy(path, buf, count + 1);  /* include terminating null */
+	strim(path);

drivers/leds/trigger/ledtrig-blkdev.c line 362

Quoted 10 lines
drivers/leds/trigger/ledtrig-blkdev.c new file +10 -0
+
+try_blkdev_get:
+	bdev = blkdev_get_by_path(path, mode, THIS_MODULE);
+	if (IS_ERR(bdev) && PTR_ERR(bdev) == -ENOENT && path != dev_path) {
+		path = dev_path;
+		goto try_blkdev_get;
+	}
+
+	kfree(dev_path);
+	return bdev;

Please just required the user to put in the whole path and remove all this garbage. There is no need to build your own broken wrappers around the VFS path resolution.