diff mbox series

[RFC,v3,09/18] ledtrig-blkdev: Add function to disassociate a device from all LEDs

Message ID 20210819025053.222710-10-arequipeno@gmail.com
State New
Headers show
Series Add block device LED trigger | expand

Commit Message

Ian Pilcher Aug. 19, 2021, 2:50 a.m. UTC
Called when block device is being removed

Signed-off-by: Ian Pilcher <arequipeno@gmail.com>
---
 drivers/leds/trigger/ledtrig-blkdev.c | 31 +++++++++++++++++++++++++++
 include/linux/leds.h                  |  4 ++++
 2 files changed, 35 insertions(+)
diff mbox series

Patch

diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c
index 447fc81ae0c5..2072cc904616 100644
--- a/drivers/leds/trigger/ledtrig-blkdev.c
+++ b/drivers/leds/trigger/ledtrig-blkdev.c
@@ -281,3 +281,34 @@  static void blkdev_disk_delete(struct ledtrig_blkdev_led *const led,
 exit_unlock:
 	mutex_unlock(&ledtrig_blkdev_mutex);
 }
+
+
+/*
+ *
+ *	Disassociate all LEDs from a block device (because it's going away)
+ *
+ */
+
+/**
+ * ledtrig_blkdev_disk_cleanup - remove a block device from the blkdev LED
+ * trigger
+ * @disk:	the disk to be removed
+ */
+void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd)
+{
+	struct ledtrig_blkdev_link *link;
+	struct hlist_node *next;
+
+	mutex_lock(&ledtrig_blkdev_mutex);
+
+	if (gd->ledtrig != NULL) {
+
+		hlist_for_each_entry_safe(link, next,
+					  &gd->ledtrig->leds, disk_leds_node) {
+			blkdev_disk_del_locked(link->led, link, gd->ledtrig);
+		}
+	}
+
+	mutex_unlock(&ledtrig_blkdev_mutex);
+}
+EXPORT_SYMBOL_GPL(ledtrig_blkdev_disk_cleanup);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 6b67650d8797..98c479814988 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -609,10 +609,14 @@  static inline void ledtrig_blkdev_disk_init(struct gendisk *const gd)
 {
 	gd->ledtrig = NULL;
 }
+void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd);
 #else	/* CONFIG_LEDS_TRIGGER_BLKDEV */
 static inline void ledtrig_blkdev_disk_init(const struct gendisk *gd)
 {
 }
+static inline void ledtrig_blkdev_disk_cleanup(const struct gendisk *gd)
+{
+}
 #endif	/* CONFIG_LEDS_TRIGGER_BLKDEV */
 
 #endif		/* __LINUX_LEDS_H_INCLUDED */