Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sysfs: convert BUG_ON to WARN_ON

It's rude to crash the system just because the developer did something
wrong, as it prevents them from usually even seeing what went wrong.

So convert the few BUG_ON() calls that have snuck into the sysfs code
over the years to WARN_ON() to make it more "friendly". All of these
are able to be recovered from, so it makes no sense to crash.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+10 -5
+2 -1
fs/sysfs/dir.c
··· 43 43 kuid_t uid; 44 44 kgid_t gid; 45 45 46 - BUG_ON(!kobj); 46 + if (WARN_ON(!kobj)) 47 + return -EINVAL; 47 48 48 49 if (kobj->parent) 49 50 parent = kobj->parent->sd;
+4 -2
fs/sysfs/file.c
··· 325 325 kuid_t uid; 326 326 kgid_t gid; 327 327 328 - BUG_ON(!kobj || !kobj->sd || !attr); 328 + if (WARN_ON(!kobj || !kobj->sd || !attr)) 329 + return -EINVAL; 329 330 330 331 kobject_get_ownership(kobj, &uid, &gid); 331 332 return sysfs_add_file_mode_ns(kobj->sd, attr, false, attr->mode, ··· 538 537 kuid_t uid; 539 538 kgid_t gid; 540 539 541 - BUG_ON(!kobj || !kobj->sd || !attr); 540 + if (WARN_ON(!kobj || !kobj->sd || !attr)) 541 + return -EINVAL; 542 542 543 543 kobject_get_ownership(kobj, &uid, &gid); 544 544 return sysfs_add_file_mode_ns(kobj->sd, &attr->attr, true,
+2 -1
fs/sysfs/group.c
··· 112 112 kgid_t gid; 113 113 int error; 114 114 115 - BUG_ON(!kobj || (!update && !kobj->sd)); 115 + if (WARN_ON(!kobj || (!update && !kobj->sd))) 116 + return -EINVAL; 116 117 117 118 /* Updates may happen before the object has been instantiated */ 118 119 if (unlikely(update && !kobj->sd))
+2 -1
fs/sysfs/symlink.c
··· 23 23 { 24 24 struct kernfs_node *kn, *target = NULL; 25 25 26 - BUG_ON(!name || !parent); 26 + if (WARN_ON(!name || !parent)) 27 + return -EINVAL; 27 28 28 29 /* 29 30 * We don't own @target_kobj and it may be removed at any time.