pktcdvd : add kobject_put when kobject register fails
PATCH 1/1 pktcdvd : add kobject_put when kobject register fails
Kobject_put should be called when kobject register functioin fails, so the the kobj ref count touch zero and then the proper cleanup routines will be called.
---drivers/block/pktcdvd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/pktcdvd.c +3 -1
@@ -117,8 +117,10 @@ static struct pktcdvd_kobj* pkt_kobj_cre p->kobj.parent = parent; p->kobj.ktype = ktype; p->pd = pd; -if (kobject_register (&p->kobj) !=0 ) +if (kobject_register (&p->kobj) !=0 ) { +kobject_put (&p->kobj);return NULL ; + }return p; }/*
Hi Dave,
Quoted 3 lines · Dave Young
Kobject_putshould be called when kobject register functioin fails, so the the kobj ref count touch zero and then the proper cleanup routines will be called.
[snip]
drivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800 static struct pktcdvd_kobj* pkt_kobj_cre · line 122
Quoted 11 lines
diff -upr
linux/drivers/block/pktcdvd.clinux.new/drivers/block/pktcdvd.cdrivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800 renamed from drivers/block/pktcdvd.c 2007-11-30 13:13:44.000000000 +0800 +2
-1@@ -117,8 +117,10 @@ static struct pktcdvd_kobj* pkt_kobj_cre p->kobj.parent = parent; p->kobj.ktype = ktype; p->pd = pd; - if (kobject_register(&p->kobj) != 0) + if (kobject_register(&p->kobj) != 0) { + kobject_put(&p->kobj); return NULL;
This looks wrong to me. AFAICT the only thing that can fail kobject_register() is kobject_add() and it cleans up after itself. Am I missing something here?
Pekka
Quoted 9 lines · Pekka Enberg
Hi Dave,
Quoted 3 lines · Dave Young
Kobject_putshould be called when kobject register functioin fails, so the the kobj ref count touch zero and then the proper cleanup routines will be called.[snip]
Quoted 15 lines
drivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800 static struct pktcdvd_kobj* pkt_kobj_cre · line 122
Quoted 11 lines
diff -upr
linux/drivers/block/pktcdvd.clinux.new/drivers/block/pktcdvd.cdrivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800 renamed from drivers/block/pktcdvd.c 2007-11-30 13:13:44.000000000 +0800 +2
-1@@ -117,8 +117,10 @@ static struct pktcdvd_kobj* pkt_kobj_cre p->kobj.parent = parent; p->kobj.ktype = ktype; p->pd = pd; - if (kobject_register(&p->kobj) != 0) + if (kobject_register(&p->kobj) != 0) { + kobject_put(&p->kobj); return NULL;This looks wrong to me. AFAICT the only thing that can fail
kobject_register()iskobject_add()and it cleans up after itself. Am I missing something here?
Hi,
the kobject reference is get in kobject_init, and then kobject_add, if kobject_add fail, it will only cleanup the reference got by itsself.
This topic is discussed in:
http://lkml.org/lkml/2007/11/30/9
Regards
dave
Quoted 3 lines
Pekka
Pekka J Enberg
Reviewed-byHi Dave,
Quoted 5 lines · Dave Young
the kobject reference is get in
kobject_init, and thenkobject_add, ifkobject_addfail, it will only cleanup the reference got by itsself.This topic is discussed in:
http://lkml.org/lkml/2007/11/30/9
Ok, thanks! Please the explanation to the changelog too.
Pekka
Dave Young
Reviewed-by Pekka EnbergQuoted 11 lines · Pekka J Enberg
Hi Dave,
Quoted 5 lines · Dave Young
the kobject reference is get in
kobject_init, and thenkobject_add, ifkobject_addfail, it will only cleanup the reference got by itsself.This topic is discussed in:
http://lkml.org/lkml/2007/11/30/9Ok, thanks! Please the explanation to the changelog too.
Ok, lets add some explanation.
------------------------------
kobject_put should be called when kobject register functioin fails.
In kobject_register, the kobject reference is get in kobject_init, and then kobject_add. If kobject_add fail, it will only cleanup the reference got by itself.
---drivers/block/pktcdvd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/pktcdvd.c +3 -1
@@ -117,8 +117,10 @@ static struct pktcdvd_kobj* pkt_kobj_cre p->kobj.parent = parent; p->kobj.ktype = ktype; p->pd = pd; -if (kobject_register (&p->kobj) !=0 ) +if (kobject_register (&p->kobj) !=0 ) { +kobject_put (&p->kobj);return NULL ; + }return p; }/*