diff mbox series

[01/10] md: fix mddev->kobj lifetime

Message ID 20220718063410.338626-2-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/10] md: fix mddev->kobj lifetime | expand

Commit Message

Christoph Hellwig July 18, 2022, 6:34 a.m. UTC
Once a kobject is initialized, the containing object should not be
directly freed.  So delay initialization until it is added.  Also
remove the kobject_del call as the last put will remove the kobject as
well.  The explicitly delete isn't needed here, and dropping it will
simplify further fixes.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/md.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Hannes Reinecke July 18, 2022, 6:55 a.m. UTC | #1
On 7/18/22 08:34, Christoph Hellwig wrote:
> Once a kobject is initialized, the containing object should not be
> directly freed.  So delay initialization until it is added.  Also
> remove the kobject_del call as the last put will remove the kobject as
> well.  The explicitly delete isn't needed here, and dropping it will
> simplify further fixes.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/md/md.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index b64de313838f2..a49ddc9454ff6 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -678,7 +678,6 @@ static void md_safemode_timeout(struct timer_list *t);
>   
>   void mddev_init(struct mddev *mddev)
>   {
> -	kobject_init(&mddev->kobj, &md_ktype);
>   	mutex_init(&mddev->open_mutex);
>   	mutex_init(&mddev->reconfig_mutex);
>   	mutex_init(&mddev->bitmap_info.mutex);
> @@ -5617,7 +5616,6 @@ static void mddev_delayed_delete(struct work_struct *ws)
>   {
>   	struct mddev *mddev = container_of(ws, struct mddev, del_work);
>   
> -	kobject_del(&mddev->kobj);
>   	kobject_put(&mddev->kobj);
>   }
>   
> @@ -5719,6 +5717,7 @@ int md_alloc(dev_t dev, char *name)
>   	if (error)
>   		goto out_cleanup_disk;
>   
> +	kobject_init(&mddev->kobj, &md_ktype);
>   	error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md");
>   	if (error)
>   		goto out_del_gendisk;
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Logan Gunthorpe July 18, 2022, 7:48 p.m. UTC | #2
On 2022-07-18 00:34, Christoph Hellwig wrote:
> Once a kobject is initialized, the containing object should not be
> directly freed.  So delay initialization until it is added.  Also
> remove the kobject_del call as the last put will remove the kobject as
> well.  The explicitly delete isn't needed here, and dropping it will
> simplify further fixes.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Logan Gunthorpe <logang@deltatee.com>

Logan
diff mbox series

Patch

diff --git a/drivers/md/md.c b/drivers/md/md.c
index b64de313838f2..a49ddc9454ff6 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -678,7 +678,6 @@  static void md_safemode_timeout(struct timer_list *t);
 
 void mddev_init(struct mddev *mddev)
 {
-	kobject_init(&mddev->kobj, &md_ktype);
 	mutex_init(&mddev->open_mutex);
 	mutex_init(&mddev->reconfig_mutex);
 	mutex_init(&mddev->bitmap_info.mutex);
@@ -5617,7 +5616,6 @@  static void mddev_delayed_delete(struct work_struct *ws)
 {
 	struct mddev *mddev = container_of(ws, struct mddev, del_work);
 
-	kobject_del(&mddev->kobj);
 	kobject_put(&mddev->kobj);
 }
 
@@ -5719,6 +5717,7 @@  int md_alloc(dev_t dev, char *name)
 	if (error)
 		goto out_cleanup_disk;
 
+	kobject_init(&mddev->kobj, &md_ktype);
 	error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md");
 	if (error)
 		goto out_del_gendisk;