* [PATCH] kobject: name reference should not be lost when lack of memory error happens
@ 2010-10-07 10:32 Roman Tereshonkov
2010-10-07 17:53 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Roman Tereshonkov @ 2010-10-07 10:32 UTC (permalink / raw)
To: linux-kernel; +Cc: gregkh, Roman Tereshonkov
If lack of memory error happens we must restore the old kobject name reference
Signed-off-by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
---
lib/kobject.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/kobject.c b/lib/kobject.c
index f07c572..c5cb117 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -222,8 +222,10 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
return 0;
kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
- if (!kobj->name)
+ if (!kobj->name) {
+ kobj->name = old_name;
return -ENOMEM;
+ }
/* ewww... some of these buggers have '/' in the name ... */
while ((s = strchr(kobj->name, '/')))
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kobject: name reference should not be lost when lack of memory error happens
2010-10-07 10:32 [PATCH] kobject: name reference should not be lost when lack of memory error happens Roman Tereshonkov
@ 2010-10-07 17:53 ` Greg KH
2010-10-09 14:32 ` Kay Sievers
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2010-10-07 17:53 UTC (permalink / raw)
To: Roman Tereshonkov, Kay Sievers; +Cc: linux-kernel, gregkh
On Thu, Oct 07, 2010 at 01:32:53PM +0300, Roman Tereshonkov wrote:
> If lack of memory error happens we must restore the old kobject name reference
No, we can't do that, as the caller will not be expecting that to have
happened, right Kay?
I think the code as-is is correct, your kobject is in an unknown state
and can't be used anymore.
thanks,
greg k-h
> Signed-off-by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
> ---
> lib/kobject.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/lib/kobject.c b/lib/kobject.c
> index f07c572..c5cb117 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -222,8 +222,10 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
> return 0;
>
> kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
> - if (!kobj->name)
> + if (!kobj->name) {
> + kobj->name = old_name;
> return -ENOMEM;
> + }
>
> /* ewww... some of these buggers have '/' in the name ... */
> while ((s = strchr(kobj->name, '/')))
> --
> 1.7.0.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kobject: name reference should not be lost when lack of memory error happens
2010-10-07 17:53 ` Greg KH
@ 2010-10-09 14:32 ` Kay Sievers
2010-10-09 18:32 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Kay Sievers @ 2010-10-09 14:32 UTC (permalink / raw)
To: Greg KH; +Cc: Roman Tereshonkov, linux-kernel, gregkh
On Thu, Oct 7, 2010 at 19:53, Greg KH <greg@kroah.com> wrote:
> On Thu, Oct 07, 2010 at 01:32:53PM +0300, Roman Tereshonkov wrote:
>> If lack of memory error happens we must restore the old kobject name reference
>
> No, we can't do that, as the caller will not be expecting that to have
> happened, right Kay?
>
> I think the code as-is is correct, your kobject is in an unknown state
> and can't be used anymore.
Yeah, we've been there several times already with no clear decision so far.
Trying to set a kobject name twice seems like a serious bug.
We should kill the old_name logic, and add a WARN() when kobj->name is
already set when the function is called, I think.
People must use kobject_rename() if they want a new name, like the
comment above kobject_set_name() says.
Kay
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kobject: name reference should not be lost when lack of memory error happens
2010-10-09 14:32 ` Kay Sievers
@ 2010-10-09 18:32 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2010-10-09 18:32 UTC (permalink / raw)
To: Kay Sievers; +Cc: Roman Tereshonkov, linux-kernel, gregkh
On Sat, Oct 09, 2010 at 04:32:44PM +0200, Kay Sievers wrote:
> On Thu, Oct 7, 2010 at 19:53, Greg KH <greg@kroah.com> wrote:
> > On Thu, Oct 07, 2010 at 01:32:53PM +0300, Roman Tereshonkov wrote:
> >> If lack of memory error happens we must restore the old kobject name reference
> >
> > No, we can't do that, as the caller will not be expecting that to have
> > happened, right Kay?
> >
> > I think the code as-is is correct, your kobject is in an unknown state
> > and can't be used anymore.
>
> Yeah, we've been there several times already with no clear decision so far.
>
> Trying to set a kobject name twice seems like a serious bug.
>
> We should kill the old_name logic, and add a WARN() when kobj->name is
> already set when the function is called, I think.
Agreed, it will be interesting to see what is trying to do this :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-09 18:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-07 10:32 [PATCH] kobject: name reference should not be lost when lack of memory error happens Roman Tereshonkov
2010-10-07 17:53 ` Greg KH
2010-10-09 14:32 ` Kay Sievers
2010-10-09 18:32 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox