kobject: name reference should not be lost when lack of memory error happens
Subsystems (2)
PATCH 1/1 kobject: name reference should not be lost when lack of memory error happens
If lack of memory error happens we must restore the old kobject name reference
--- lib/kobject.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
lib/kobject.c +3 -1
@@ -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,'/' )))
Signature · 1 line
1.7.0.4
Quoted 1 line · Roman Tereshonkov
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
Quoted 23 lines
Signed-off-by Roman Tereshonkov <[email protected]>--- lib/kobject.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)lib/kobject.c +3
-1@@ -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,'/' )))Signature · 1 line
1.7.0.4
Quoted 8 lines · Greg KH
Quoted 1 line · Roman Tereshonkov
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
Quoted 10 lines · Kay Sievers
Quoted 8 lines · Greg KH
Quoted 1 line · Roman Tereshonkov
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.
Quoted 6 lines
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_namelogic, and add aWARN()whenkobj->nameis 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