Re: [bug report] scsi: core: Fix possible memory leak if device_add() fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 10, 2023 at 08:05:21PM +0800, wangzhu wrote:
> Hello Dan Carpenter:
> 
> 
> Sorry for the patch 04b5b5cb0136 I submitted, I thought put_dev(&rc->dev) is
> not the same as kfree(rc).
> 
> Then should I submit a revert patch again, or you can fix it yourself?
> please let me know what I can do.
> 
> Sorry for the inconvenience again.
> 

It's easy enough for fix this...  Although instead of calling
list_add_tail() and then list_del() I probably would have prefered to
move the list_add_tail() right before the "return 0;"

-	list_add_tail(&rc->node, &rd->component_list);
	rc->dev.class = &raid_class.class;
	if (err)
		goto err_out;

+	list_add_tail(&rc->node, &rd->component_list);
	return 0;

But the diff I sent you is the more conservative option.

regards,
dan carpenter

diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c
index 711252e52d8e..86ed1f66d749 100644
--- a/drivers/scsi/raid_class.c
+++ b/drivers/scsi/raid_class.c
@@ -248,11 +248,9 @@ int raid_component_add(struct raid_template *r,struct device *raid_dev,
 	return 0;
 
 err_out:
-	put_device(&rc->dev);
 	list_del(&rc->node);
 	rd->component_count--;
-	put_device(component_dev);
-	kfree(rc);
+	put_device(&rc->dev);
 	return err;
 }
 EXPORT_SYMBOL(raid_component_add);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux