* [PATCH] pktcdvd : add kobject_put when kobject register fails
@ 2007-12-04 1:31 Dave Young
2007-12-04 7:45 ` Pekka Enberg
0 siblings, 1 reply; 5+ messages in thread
From: Dave Young @ 2007-12-04 1:31 UTC (permalink / raw)
To: petero2; +Cc: linux-kernel
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.
Signed-off-by: Dave Young <hidave.darkstar@gmail.com>
---
drivers/block/pktcdvd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff -upr linux/drivers/block/pktcdvd.c linux.new/drivers/block/pktcdvd.c
--- linux/drivers/block/pktcdvd.c 2007-11-30 13:13:44.000000000 +0800
+++ linux.new/drivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800
@@ -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;
}
/*
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] pktcdvd : add kobject_put when kobject register fails
2007-12-04 1:31 [PATCH] pktcdvd : add kobject_put when kobject register fails Dave Young
@ 2007-12-04 7:45 ` Pekka Enberg
2007-12-04 8:00 ` Dave Young
0 siblings, 1 reply; 5+ messages in thread
From: Pekka Enberg @ 2007-12-04 7:45 UTC (permalink / raw)
To: Dave Young; +Cc: petero2, linux-kernel
Hi Dave,
On Dec 4, 2007 3:31 AM, Dave Young <hidave.darkstar@gmail.com> wrote:
> 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.
[snip]
> diff -upr linux/drivers/block/pktcdvd.c linux.new/drivers/block/pktcdvd.c
> --- linux/drivers/block/pktcdvd.c 2007-11-30 13:13:44.000000000 +0800
> +++ linux.new/drivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800
> @@ -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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] pktcdvd : add kobject_put when kobject register fails
2007-12-04 7:45 ` Pekka Enberg
@ 2007-12-04 8:00 ` Dave Young
2007-12-04 8:05 ` Pekka J Enberg
0 siblings, 1 reply; 5+ messages in thread
From: Dave Young @ 2007-12-04 8:00 UTC (permalink / raw)
To: Pekka Enberg; +Cc: petero2, linux-kernel
On Dec 4, 2007 3:45 PM, Pekka Enberg <penberg@cs.helsinki.fi> wrote:
> Hi Dave,
>
> On Dec 4, 2007 3:31 AM, Dave Young <hidave.darkstar@gmail.com> wrote:
> > 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.
>
> [snip]
>
> > diff -upr linux/drivers/block/pktcdvd.c linux.new/drivers/block/pktcdvd.c
> > --- linux/drivers/block/pktcdvd.c 2007-11-30 13:13:44.000000000 +0800
> > +++ linux.new/drivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800
> > @@ -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?
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
>
> Pekka
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] pktcdvd : add kobject_put when kobject register fails
2007-12-04 8:00 ` Dave Young
@ 2007-12-04 8:05 ` Pekka J Enberg
2007-12-04 8:26 ` Dave Young
0 siblings, 1 reply; 5+ messages in thread
From: Pekka J Enberg @ 2007-12-04 8:05 UTC (permalink / raw)
To: Dave Young; +Cc: petero2, linux-kernel
Hi Dave,
On Tue, 4 Dec 2007, Dave Young wrote:
> 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
Ok, thanks! Please the explanation to the changelog too.
Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi>
Pekka
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] pktcdvd : add kobject_put when kobject register fails
2007-12-04 8:05 ` Pekka J Enberg
@ 2007-12-04 8:26 ` Dave Young
0 siblings, 0 replies; 5+ messages in thread
From: Dave Young @ 2007-12-04 8:26 UTC (permalink / raw)
To: Pekka J Enberg; +Cc: petero2, linux-kernel
On Tue, Dec 04, 2007 at 10:05:24AM +0200, Pekka J Enberg wrote:
> Hi Dave,
>
> On Tue, 4 Dec 2007, Dave Young wrote:
> > 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
>
> Ok, 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.
Signed-off-by: Dave Young <hidave.darkstar@gmail.com>
Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
drivers/block/pktcdvd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff -upr linux/drivers/block/pktcdvd.c linux.new/drivers/block/pktcdvd.c
--- linux/drivers/block/pktcdvd.c 2007-11-30 13:13:44.000000000 +0800
+++ linux.new/drivers/block/pktcdvd.c 2007-11-30 13:24:08.000000000 +0800
@@ -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;
}
/*
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-12-04 8:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-04 1:31 [PATCH] pktcdvd : add kobject_put when kobject register fails Dave Young
2007-12-04 7:45 ` Pekka Enberg
2007-12-04 8:00 ` Dave Young
2007-12-04 8:05 ` Pekka J Enberg
2007-12-04 8:26 ` Dave Young
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).