staging: speakup: Replace BUG_ON() with WARN_ON().
authorVarsha Rao <rvarsha016@gmail.com>
Sat, 25 Feb 2017 12:23:58 +0000 (17:53 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Mar 2018 08:17:36 +0000 (09:17 +0100)
[ Upstream commit d351c2db5420bb17dcd2d9aac7ddb5f64c6d04b3 ]

BUG_ON() is replaced with WARN_ON() and EINVAL is returned, when
WARN_ON() is true. This fixes the following checkpatch issue:

Avoid crashing the kernel - try using WARN_ON & recovery code rather
than BUG() or BUG_ON().

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/speakup/kobjects.c

index e744aa9..dea018c 100644 (file)
@@ -834,7 +834,9 @@ static ssize_t message_show(struct kobject *kobj,
        struct msg_group_t *group = spk_find_msg_group(attr->attr.name);
        unsigned long flags;
 
-       BUG_ON(!group);
+       if (WARN_ON(!group))
+               return -EINVAL;
+
        spin_lock_irqsave(&speakup_info.spinlock, flags);
        retval = message_show_helper(buf, group->start, group->end);
        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
@@ -846,7 +848,9 @@ static ssize_t message_store(struct kobject *kobj, struct kobj_attribute *attr,
 {
        struct msg_group_t *group = spk_find_msg_group(attr->attr.name);
 
-       BUG_ON(!group);
+       if (WARN_ON(!group))
+               return -EINVAL;
+
        return message_store_helper(buf, count, group);
 }