diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kobject.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index ae6bb900bfb6..0487d1f64806 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -397,6 +397,7 @@ int kobject_rename(struct kobject *kobj, const char *new_name) | |||
397 | { | 397 | { |
398 | int error = 0; | 398 | int error = 0; |
399 | const char *devpath = NULL; | 399 | const char *devpath = NULL; |
400 | const char *dup_name = NULL, *name; | ||
400 | char *devpath_string = NULL; | 401 | char *devpath_string = NULL; |
401 | char *envp[2]; | 402 | char *envp[2]; |
402 | 403 | ||
@@ -420,15 +421,27 @@ int kobject_rename(struct kobject *kobj, const char *new_name) | |||
420 | envp[0] = devpath_string; | 421 | envp[0] = devpath_string; |
421 | envp[1] = NULL; | 422 | envp[1] = NULL; |
422 | 423 | ||
424 | name = dup_name = kstrdup(new_name, GFP_KERNEL); | ||
425 | if (!name) { | ||
426 | error = -ENOMEM; | ||
427 | goto out; | ||
428 | } | ||
429 | |||
423 | error = sysfs_rename_dir(kobj, new_name); | 430 | error = sysfs_rename_dir(kobj, new_name); |
431 | if (error) | ||
432 | goto out; | ||
433 | |||
434 | /* Install the new kobject name */ | ||
435 | dup_name = kobj->name; | ||
436 | kobj->name = name; | ||
424 | 437 | ||
425 | /* This function is mostly/only used for network interface. | 438 | /* This function is mostly/only used for network interface. |
426 | * Some hotplug package track interfaces by their name and | 439 | * Some hotplug package track interfaces by their name and |
427 | * therefore want to know when the name is changed by the user. */ | 440 | * therefore want to know when the name is changed by the user. */ |
428 | if (!error) | 441 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); |
429 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); | ||
430 | 442 | ||
431 | out: | 443 | out: |
444 | kfree(dup_name); | ||
432 | kfree(devpath_string); | 445 | kfree(devpath_string); |
433 | kfree(devpath); | 446 | kfree(devpath); |
434 | kobject_put(kobj); | 447 | kobject_put(kobj); |