Skip to content

Commit de96e9f

Browse files
committed
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>
1 parent bfeffd1 commit de96e9f

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎fs/sysfs/dir.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
4343
kuid_t uid;
4444
kgid_t gid;
4545

46-
BUG_ON(!kobj);
46+
if (WARN_ON(!kobj))
47+
return -EINVAL;
4748

4849
if (kobj->parent)
4950
parent = kobj->parent->sd;

‎fs/sysfs/file.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr,
325325
kuid_t uid;
326326
kgid_t gid;
327327

328-
BUG_ON(!kobj || !kobj->sd || !attr);
328+
if (WARN_ON(!kobj || !kobj->sd || !attr))
329+
return -EINVAL;
329330

330331
kobject_get_ownership(kobj, &uid, &gid);
331332
return sysfs_add_file_mode_ns(kobj->sd, attr, false, attr->mode,
@@ -537,7 +538,8 @@ int sysfs_create_bin_file(struct kobject *kobj,
537538
kuid_t uid;
538539
kgid_t gid;
539540

540-
BUG_ON(!kobj || !kobj->sd || !attr);
541+
if (WARN_ON(!kobj || !kobj->sd || !attr))
542+
return -EINVAL;
541543

542544
kobject_get_ownership(kobj, &uid, &gid);
543545
return sysfs_add_file_mode_ns(kobj->sd, &attr->attr, true,

‎fs/sysfs/group.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ static int internal_create_group(struct kobject *kobj, int update,
112112
kgid_t gid;
113113
int error;
114114

115-
BUG_ON(!kobj || (!update && !kobj->sd));
115+
if (WARN_ON(!kobj || (!update && !kobj->sd)))
116+
return -EINVAL;
116117

117118
/* Updates may happen before the object has been instantiated */
118119
if (unlikely(update && !kobj->sd))

‎fs/sysfs/symlink.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ static int sysfs_do_create_link_sd(struct kernfs_node *parent,
2323
{
2424
struct kernfs_node *kn, *target = NULL;
2525

26-
BUG_ON(!name || !parent);
26+
if (WARN_ON(!name || !parent))
27+
return -EINVAL;
2728

2829
/*
2930
* We don't own @target_kobj and it may be removed at any time.

0 commit comments

Comments
 (0)