@@ -10,6 +10,13 @@
#include "ledtrig-blkdev.h"
+DEFINE_MUTEX(ledtrig_blkdev_mutex);
+EXPORT_SYMBOL_NS_GPL(ledtrig_blkdev_mutex, LEDTRIG_BLKDEV);
+
+/* Set when module is loaded (or trigger is initialized) */
+void (*__ledtrig_blkdev_disk_cleanup)(struct gendisk *gd) = NULL;
+EXPORT_SYMBOL_NS_GPL(__ledtrig_blkdev_disk_cleanup, LEDTRIG_BLKDEV);
+
/**
* ledtrig_blkdev_disk_cleanup - remove a block device from the blkdev LED
* trigger
@@ -17,4 +24,12 @@
*/
void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd)
{
+ mutex_lock(&ledtrig_blkdev_mutex);
+
+ if (gd->ledtrig != NULL) {
+ if (!WARN_ON(__ledtrig_blkdev_disk_cleanup == NULL))
+ __ledtrig_blkdev_disk_cleanup(gd);
+ }
+
+ mutex_unlock(&ledtrig_blkdev_mutex);
}
@@ -6,6 +6,7 @@
* Copyright 2021 Ian Pilcher <arequipeno@gmail.com>
*/
+#include <linux/leds.h>
#include <linux/module.h>
#include "ledtrig-blkdev.h"
@@ -9,4 +9,7 @@
#ifndef __LEDTRIG_BLKDEV_H
#define __LEDTRIG_BLKDEV_H
+extern struct mutex ledtrig_blkdev_mutex;
+extern void (*__ledtrig_blkdev_disk_cleanup)(struct gendisk *gd);
+
#endif /* __LEDTRIG_BLKDEV_H */
@@ -613,6 +613,7 @@ static inline void ledtrig_audio_set(enum led_audio type,
*/
static inline void ledtrig_blkdev_disk_init(struct gendisk *const gd)
{
+ gd->ledtrig = NULL;
}
void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd);
#else /* IS_ENABLED(CONFIG_LEDS_TRIGGER_BLKDEV) */
Now that the ledtrig member has been added to struct gendisk, add the function bodies to ledtrig_blkdev_disk_init() and ledtrig_blkdev_disk_cleanup() Signed-off-by: Ian Pilcher <arequipeno@gmail.com> --- drivers/leds/trigger/ledtrig-blkdev-core.c | 15 +++++++++++++++ drivers/leds/trigger/ledtrig-blkdev.c | 1 + drivers/leds/trigger/ledtrig-blkdev.h | 3 +++ include/linux/leds.h | 1 + 4 files changed, 20 insertions(+)