Commit cb360bbf6352712310a7528137919c626a782744
Committed by
Greg Kroah-Hartman
1 parent
270a6c4cad
Exists in
master
and in
7 other branches
driver core fixes: make_class_name() retval checks
Make make_class_name() return NULL on error and fixup callers in the driver core. Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 2 changed files with 25 additions and 13 deletions Side-by-side Diff
drivers/base/class.c
... | ... | @@ -364,7 +364,7 @@ |
364 | 364 | |
365 | 365 | class_name = kmalloc(size, GFP_KERNEL); |
366 | 366 | if (!class_name) |
367 | - return ERR_PTR(-ENOMEM); | |
367 | + return NULL; | |
368 | 368 | |
369 | 369 | strcpy(class_name, name); |
370 | 370 | strcat(class_name, ":"); |
... | ... | @@ -411,8 +411,11 @@ |
411 | 411 | return 0; |
412 | 412 | |
413 | 413 | class_name = make_class_name(class_dev->class->name, &class_dev->kobj); |
414 | - error = sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, | |
415 | - class_name); | |
414 | + if (class_name) | |
415 | + error = sysfs_create_link(&class_dev->dev->kobj, | |
416 | + &class_dev->kobj, class_name); | |
417 | + else | |
418 | + error = -ENOMEM; | |
416 | 419 | kfree(class_name); |
417 | 420 | return error; |
418 | 421 | } |
... | ... | @@ -425,7 +428,8 @@ |
425 | 428 | return; |
426 | 429 | |
427 | 430 | class_name = make_class_name(class_dev->class->name, &class_dev->kobj); |
428 | - sysfs_remove_link(&class_dev->dev->kobj, class_name); | |
431 | + if (class_name) | |
432 | + sysfs_remove_link(&class_dev->dev->kobj, class_name); | |
429 | 433 | kfree(class_name); |
430 | 434 | } |
431 | 435 | #else |
... | ... | @@ -863,9 +867,12 @@ |
863 | 867 | if (class_dev->dev) { |
864 | 868 | new_class_name = make_class_name(class_dev->class->name, |
865 | 869 | &class_dev->kobj); |
866 | - sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, | |
867 | - new_class_name); | |
868 | - sysfs_remove_link(&class_dev->dev->kobj, old_class_name); | |
870 | + if (new_class_name) | |
871 | + sysfs_create_link(&class_dev->dev->kobj, | |
872 | + &class_dev->kobj, new_class_name); | |
873 | + if (old_class_name) | |
874 | + sysfs_remove_link(&class_dev->dev->kobj, | |
875 | + old_class_name); | |
869 | 876 | } |
870 | 877 | #endif |
871 | 878 | class_device_put(class_dev); |
drivers/base/core.c
... | ... | @@ -527,9 +527,13 @@ |
527 | 527 | &dev->kobj, dev->bus_id); |
528 | 528 | #ifdef CONFIG_SYSFS_DEPRECATED |
529 | 529 | if (parent) { |
530 | - sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); | |
531 | - class_name = make_class_name(dev->class->name, &dev->kobj); | |
532 | - sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); | |
530 | + sysfs_create_link(&dev->kobj, &dev->parent->kobj, | |
531 | + "device"); | |
532 | + class_name = make_class_name(dev->class->name, | |
533 | + &dev->kobj); | |
534 | + if (class_name) | |
535 | + sysfs_create_link(&dev->parent->kobj, | |
536 | + &dev->kobj, class_name); | |
533 | 537 | } |
534 | 538 | #endif |
535 | 539 | } |
... | ... | @@ -672,7 +676,9 @@ |
672 | 676 | if (parent) { |
673 | 677 | char *class_name = make_class_name(dev->class->name, |
674 | 678 | &dev->kobj); |
675 | - sysfs_remove_link(&dev->parent->kobj, class_name); | |
679 | + if (class_name) | |
680 | + sysfs_remove_link(&dev->parent->kobj, | |
681 | + class_name); | |
676 | 682 | kfree(class_name); |
677 | 683 | sysfs_remove_link(&dev->kobj, "device"); |
678 | 684 | } |
... | ... | @@ -975,8 +981,7 @@ |
975 | 981 | |
976 | 982 | class_name = make_class_name(dev->class->name, &dev->kobj); |
977 | 983 | if (!class_name) { |
978 | - error = PTR_ERR(class_name); | |
979 | - class_name = NULL; | |
984 | + error = -ENOMEM; | |
980 | 985 | goto out; |
981 | 986 | } |
982 | 987 | if (old_parent) { |