[PATCH] block: rnbd: add .release to rnbd_dev_ktype

Salah Triki posted 1 patch 7 months, 3 weeks ago
There is a newer version of this series
drivers/block/rnbd/rnbd-clt-sysfs.c | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH] block: rnbd: add .release to rnbd_dev_ktype
Posted by Salah Triki 7 months, 3 weeks ago
Every ktype must provides a .release function that will be called after
the last kobject_put.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/block/rnbd/rnbd-clt-sysfs.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
index 6ea7c12e3a87..144aea1466a4 100644
--- a/drivers/block/rnbd/rnbd-clt-sysfs.c
+++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
@@ -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
Re: [PATCH] block: rnbd: add .release to rnbd_dev_ktype
Posted by Jinpu Wang 7 months, 3 weeks ago
Hi,

On Sun, Apr 27, 2025 at 5:48 PM Salah Triki <salah.triki@gmail.com> wrote:
>
> Every ktype must provides a .release function that will be called after
> the last kobject_put.
>
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
This change cause crashing during unmap device.
We already have rnbd_client_release from rnbd_client_ops, so no memleak.

Nacked.

Thx!
> ---
>  drivers/block/rnbd/rnbd-clt-sysfs.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
> index 6ea7c12e3a87..144aea1466a4 100644
> --- a/drivers/block/rnbd/rnbd-clt-sysfs.c
> +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
> @@ -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
>
Re: [PATCH] block: rnbd: add .release to rnbd_dev_ktype
Posted by Bart Van Assche 7 months, 2 weeks ago
On 4/28/25 2:58 AM, Jinpu Wang wrote:
> 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.
Re: [PATCH] block: rnbd: add .release to rnbd_dev_ktype
Posted by Jens Axboe 7 months, 3 weeks ago
On 4/27/25 9:48 AM, Salah Triki wrote:
> 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

-- 
Jens Axboe
Re: [PATCH] block: rnbd: add .release to rnbd_dev_ktype
Posted by John Garry 7 months, 3 weeks ago
On 27/04/2025 23:03, Jens Axboe wrote:
> On 4/27/25 9:48 AM, Salah Triki wrote:
>> 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().

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