fail_function: refactor code of checking return value of register_kprobe()
authorYang Yingliang <yangyingliang@huawei.com>
Fri, 26 Aug 2022 07:33:36 +0000 (15:33 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 12 Sep 2022 04:55:11 +0000 (21:55 -0700)
Refactor the error handling of register_kprobe() to improve readability.
No functional change.

Link: https://lkml.kernel.org/r/20220826073337.2085798-2-yangyingliang@huawei.com
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/fail_function.c

index 03643e3..893e8f9 100644 (file)
@@ -294,14 +294,13 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
        }
 
        ret = register_kprobe(&attr->kp);
-       if (!ret)
-               fei_debugfs_add_attr(attr);
-       if (ret < 0)
+       if (ret) {
                fei_attr_remove(attr);
-       else {
-               list_add_tail(&attr->list, &fei_attr_list);
-               ret = count;
+               goto out;
        }
+       fei_debugfs_add_attr(attr);
+       list_add_tail(&attr->list, &fei_attr_list);
+       ret = count;
 out:
        mutex_unlock(&fei_lock);
        kfree(buf);