Thread (37 messages) 37 messages, 5 authors, 2021-09-14

Re: [PATCH v2 11/15] leds: trigger: blkdev: Enable linking block devices to LEDs

From: Ian Pilcher <hidden>
Date: 2021-09-10 16:25:19
Also in: linux-leds, lkml

On 9/10/21 1:48 AM, Greg KH wrote:
quoted
+/* 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?
That happens in blkdev_disk_unlink_locked() at line 399.  (Also in the
error path in blkdev_put_disk(), called at line 321.)

Looking at this now, blkdev_disk_unlink_locked() should be calling
blkdev_put_disk(), rather than calling kobject_put() directly.  I'll fix
that.
quoted
+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?
If you're referring to the kfree() call, it's freeing the
ledtrig_blkdev_disk structure, not the gendisk.  I use "gd" for gendisk
pointers and "disk" for ledtrig_blkdev_disk pointers.
Did you try this out with removable block devices yet?
Absolutely.  I've tested removing both block devices and (user space)
LEDs.

-- 
========================================================================
                  In Soviet Russia, Google searches you!
========================================================================
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help