Skip to contentSkip to conversation

block: rnbd: add .release to rnbd_dev_ktype

PATCH Superseded Salah Triki 5 participants 5 messages Apr 27, 2025 – May 4, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: rnbd: add .release to rnbd_dev_ktype

Every ktype must provides a .release function that will be called after the last kobject_put.

---
 drivers/block/rnbd/rnbd-clt-sysfs.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/block/rnbd/rnbd-clt-sysfs.c +8 -0
index 6ea7c12e3a87..144aea1466a4 100644
@@ -475,9 +475,17 @@ void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev)
 	}
 }
 
+static void rnbd_dev_release(struct kobject *kobj)
+{
+	struct rnbd_clt_dev *dev = container_of(kobj, struct rnbd_clt_dev, kobj);
+
+	kfree(dev);
+}
+
 static const struct kobj_type rnbd_dev_ktype = {
 	.sysfs_ops      = &kobj_sysfs_ops,
 	.default_groups = rnbd_dev_groups,
+	.release	= rnbd_dev_release,
 };
 
 static int rnbd_clt_add_dev_kobj(struct rnbd_clt_dev *dev)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 2 lines · Salah Triki

Every ktype must provides a .release function that will be called after the last kobject_put.

This commit needs:

1) A description of the problem. There's just a vague statement in there.
2) A Fixes tag

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 3 lines · Jens Axboe
Quoted 2 lines · Salah Triki

Every ktype must provides a .release function that will be called after the last kobject_put.

You could mention Documentation/core-api/kobject.rst?h=v6.15-rc3#n279, which tells us this. As does the check in kobject_cleanup().

Quoted 7 lines

This commit needs:

1) A description of the problem. There's just a vague statement in there.
2) A Fixes tag

maintainer NAK
#3 lore raw
In reply to Salah Triki

Hi,

Quoted 5 lines · Salah Triki

Every ktype must provides a .release function that will be called after the last kobject_put.

This change cause crashing during unmap device.
We already have rnbd_client_release from rnbd_client_ops, so no memleak.

Nacked.

Thx!

Quoted 29 lines
---
 drivers/block/rnbd/rnbd-clt-sysfs.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/block/rnbd/rnbd-clt-sysfs.c +8 -1
index 6ea7c12e3a87..144aea1466a4 100644
@@ -475,9 +475,17 @@ void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev)
        }
 }
 
+static void rnbd_dev_release(struct kobject *kobj)
+{
+       struct rnbd_clt_dev *dev = container_of(kobj, struct rnbd_clt_dev, kobj);
+
+       kfree(dev);
+}
+
 static const struct kobj_type rnbd_dev_ktype = {
        .sysfs_ops      = &kobj_sysfs_ops,
        .default_groups = rnbd_dev_groups,
+       .release        = rnbd_dev_release,
 };
 
 static int rnbd_clt_add_dev_kobj(struct rnbd_clt_dev *dev)
--

2.43.0

#4 lore raw
Quoted 1 line · Jinpu Wang

Nacked.

Instead of NAK-ing this patch, please rework the rnbd driver such that rnbd_dev_ktype has a .release method and the driver keeps working fine.

Bart.