Skip to content

Commit

Permalink
sysfs: convert BUG_ON to WARN_ON
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gregkh committed Jan 7, 2019
1 parent bfeffd1 commit de96e9f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion fs/sysfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
kuid_t uid;
kgid_t gid;

BUG_ON(!kobj);
if (WARN_ON(!kobj))
return -EINVAL;

if (kobj->parent)
parent = kobj->parent->sd;
Expand Down
6 changes: 4 additions & 2 deletions fs/sysfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr,
kuid_t uid;
kgid_t gid;

BUG_ON(!kobj || !kobj->sd || !attr);
if (WARN_ON(!kobj || !kobj->sd || !attr))
return -EINVAL;

kobject_get_ownership(kobj, &uid, &gid);
return sysfs_add_file_mode_ns(kobj->sd, attr, false, attr->mode,
Expand Down Expand Up @@ -537,7 +538,8 @@ int sysfs_create_bin_file(struct kobject *kobj,
kuid_t uid;
kgid_t gid;

BUG_ON(!kobj || !kobj->sd || !attr);
if (WARN_ON(!kobj || !kobj->sd || !attr))
return -EINVAL;

kobject_get_ownership(kobj, &uid, &gid);
return sysfs_add_file_mode_ns(kobj->sd, &attr->attr, true,
Expand Down
3 changes: 2 additions & 1 deletion fs/sysfs/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ static int internal_create_group(struct kobject *kobj, int update,
kgid_t gid;
int error;

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

/* Updates may happen before the object has been instantiated */
if (unlikely(update && !kobj->sd))
Expand Down
3 changes: 2 additions & 1 deletion fs/sysfs/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static int sysfs_do_create_link_sd(struct kernfs_node *parent,
{
struct kernfs_node *kn, *target = NULL;

BUG_ON(!name || !parent);
if (WARN_ON(!name || !parent))
return -EINVAL;

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

0 comments on commit de96e9f

Please sign in to comment.