[PATCH] node: put_device after failing to device_register

Zhi Song posted 1 patch 3 years, 10 months ago
There is a newer version of this series
drivers/base/node.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] node: put_device after failing to device_register
Posted by Zhi Song 3 years, 10 months ago
device_register() is used to register a device with the system.

We cannot directly free dev after calling this function,
even if it returns an error.

We should use put_device() to give up the reference
initialized in this function instead.

Signed-off-by: Zhi Song <zhi.song@bytedance.com>
---
 drivers/base/node.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index 0ac6376ef7a1..88a3337c546e 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -154,6 +154,7 @@ static struct node_access_nodes *node_init_node_access(struct node *node,
 	list_add_tail(&access_node->list_node, &node->access_list);
 	return access_node;
 free_name:
+	put_device(dev);
 	kfree_const(dev->kobj.name);
 free:
 	kfree(access_node);
-- 
2.30.2
Re: [PATCH] node: put_device after failing to device_register
Posted by Greg KH 3 years, 10 months ago
On Tue, Jun 14, 2022 at 10:30:07PM +0800, Zhi Song wrote:
> device_register() is used to register a device with the system.
> 
> We cannot directly free dev after calling this function,
> even if it returns an error.

the device is not being freed, why say this?

And you do have a full 72 columns to use :)

> 
> We should use put_device() to give up the reference
> initialized in this function instead.

There is no "instead" happening here.  The patch looks correct, but this
changelog text does not.  Please fix up.

thanks,

greg k-h
Re: [External] [PATCH] node: put_device after failing to device_register
Posted by Zhi Song 3 years, 10 months ago
> On Jun 14, 2022, at 22:37, Greg KH <gregkh@linuxfoundation.org> wrote:
> 
> On Tue, Jun 14, 2022 at 10:30:07PM +0800, Zhi Song wrote:
>> device_register() is used to register a device with the system.
>> 
>> We cannot directly free dev after calling this function,
>> even if it returns an error.
> 
> the device is not being freed, why say this?
> 
> And you do have a full 72 columns to use :)
> 
>> 
>> We should use put_device() to give up the reference
>> initialized in this function instead.
> 
> There is no "instead" happening here.  The patch looks correct, but this
> changelog text does not.  Please fix up.
> 
> thanks,
> 
> greg k-h

Hi Greg,

I have submitted this fixed patch here:
https://lore.kernel.org/all/20220621171623.1959231-1-zhi.song@bytedance
.com/
take a look if there's anything wrong. :)

Thanks,

Zhi