eisa: call put_device if device_register fails
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Levente Kurusa
We need to give up the last reference to
edev->dev, so we need to callput_device().Cc Bjorn Helgaas <[email protected]>Signed-off-by Levente Kurusa <[email protected]>
I applied this and will push it through my PCI tree, since I don't think anybody really takes care of EISA these days.
I looked at other callers of device_register(), and most of them look like they have the same problem. Can you fix the others, too? This patch says "2/4", so maybe you already are, but I can't find the other patches in the series.
Bjorn
Quoted 23 lines
--- drivers/eisa/eisa-bus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/eisa/eisa-bus.c +3
-1@@ -232,8 +232,10 @@ static int __init eisa_init_device(struct eisa_root_device *root,static int __init eisa_register_device (struct eisa_device *edev) {int rc =device_register (&edev->dev); -if (rc) +if (rc) { +put_device (&edev->dev);return rc; + } rc =device_create_file (&edev->dev, &dev_attr_signature);if (rc)Signature · 1 line
1.8.3.1
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Levente Kurusa
We need to give up the last reference to
edev->dev, so we need to callput_device().Cc Bjorn Helgaas <[email protected]>Signed-off-by Levente Kurusa <[email protected]>
Quoted 7 lines
I applied this and will push it through my PCI tree, since I don't think anybody really takes care of EISA these days.
I looked at other callers of
device_register(), and most of them look like they have the same problem. Can you fix the others, too? This patch says "2/4", so maybe you already are, but I can't find the other patches in the series.
Yes, the patchset didn't hit LKML due to me being a noob with git-send-email. :-(
I will fix them, just sent this to verify that I am doing it right. :-)
Thanks for applying!
Signature · 2 lines
Regards, Levente Kurusa
A message that is not in the archive (sent off-list or not yet received): [email protected]
Greg Kroah-Hartman
Acked-byRe: [PATCH 1/4] net: phy: call put_device on device_register() failure
Quoted 7 lines · Levente Kurusa
It is required to call
put_device()ifdevice_register()fails, so that we give up the last reference to the device. Callingput_deviceallows formdiobus_releaseto be executed, kfreeing the bus.Cc Greg Kroah-Hartman <[email protected]>Cc Grant Likely <[email protected]>Signed-off-by Levente Kurusa <[email protected]>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jingoo Han
Acked-byRe: [PATCH 3/4] backlight: lcd: call put_device if device_register fails
Quoted 8 lines · Levente Kurusa
Currently we kfree the container of the device which failed to register. This is wrong as the last reference is not given up with a
put_devicecall. Also, now that we haveput_device()callen, we no longer need the kfree as thenew_ld->dev.releasefunction will take care of kfreeing the associated memory.Signed-off-by Levente Kurusa <[email protected]>
(+cc Andrew Morton)
It looks good.
According to the comment of device_register, put_device() should be used, instead of directly freeing.
./drivers/base/core.c
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always use put_device() to give up the
* reference initialized in this function instead.
*/
int device_register(struct device *dev)
{
device_initialize(dev);
return device_add(dev);
}EXPORT_SYMBOL_GPL(device_register);
Levente Kurusa,
By the way, don't send the same mails three times, without any reason. It is the waste of traffic. :-(
Best regards,
Jingoo Han
Quoted 19 lines
--- drivers/video/backlight/lcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/video/backlight/lcd.c +1
-2@@ -228,7 +228,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent, rc =device_register (&new_ld->dev);if (rc) { -kfree (new_ld); +put_device (&new_ld->dev);return ERR_PTR (rc); } --1.8.3.1
Re: [PATCH 3/4] backlight: lcd: call put_device if device_register fails
Quoted 10 lines · Jingoo Han
Quoted 8 lines · Levente Kurusa
Currently we kfree the container of the device which failed to register. This is wrong as the last reference is not given up with a
put_devicecall. Also, now that we haveput_device()callen, we no longer need the kfree as thenew_ld->dev.releasefunction will take care of kfreeing the associated memory.Signed-off-by Levente Kurusa <[email protected]>
Quoted 7 lines
(+cc Andrew Morton)
Acked-by Jingoo Han <[email protected]>It looks good.
According to the comment ofdevice_register,put_device()should be used, instead of directly freeing.
Indeed, this is also mostly explained in [0/4]. Thanks for the Ack!
Quoted 1 line
[...]
Quoted 5 lines
Levente Kurusa,
By the way, don't send the same mails three times, without any reason. It is the waste of traffic. :-(
Yea, sorry about that I messed up my git's smtp config and hence most of the messages bounced off. It didn't even reach LKML. Sorry once more.
Signature · 2 lines
Regards, Levente Kurusa
Re: [PATCH 3/4] backlight: lcd: call put_device if device_register fails
In reply to a message not in the archiveQuoted 17 lines · Levente Kurusa
Currently we kfree the container of the device which failed to register. This is wrong as the last reference is not given up with a
put_devicecall. Also, now that we haveput_device()callen, we no longer need the kfree as thenew_ld->dev.releasefunction will take care of kfreeing the associated memory.Signed-off-by Levente Kurusa <[email protected]>--- drivers/video/backlight/lcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/video/backlight/lcd.c +0
-0
drivers/video/backlight/lcd.c struct lcd_device *lcd_device_register(const char *name, struct device *parent, · line 233
Quoted 7 lines
drivers/video/backlight/lcd.c +1
-1@@ -228,7 +228,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent, rc =device_register (&new_ld->dev);if (rc) { -kfree (new_ld); +put_device (&new_ld->dev);return ERR_PTR (rc); }
(+cc Andrew Morton)
Hi Levente Kurusa,
Would you fix the same thing for 'backlight.c' file?
./drivers/video/backlight/backlight.c
struct backlight_device *backlight_device_register(const char *name,
.....
rc = device_register(&new_bd->dev);
if (rc) {
kfree(new_bd);
return ERR_PTR(rc);
}Best regards,
Jingoo Han