]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/proc/vmcore: a few cleanups for vmcore_add_device_dump()
authorSu Hui <suhui@nfschina.com>
Thu, 26 Jun 2025 10:54:41 +0000 (18:54 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 05:57:56 +0000 (22:57 -0700)
There are two cleanups for vmcore_add_device_dump().  Return -ENOMEM
directly rather than goto the label to simplify the code and use
scoped_guard() to simplify the lock/unlock code.

Link: https://lkml.kernel.org/r/20250626105440.1053139-1-suhui@nfschina.com
Signed-off-by: Su Hui <suhui@nfschina.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Suhui <suhui@nfschina.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/vmcore.c

index 10d01eb09c43d792afc0d30ecb7a1a1b7c6f7632..f188bd900eb2d9b0a8b2d5ea8ad237c22ee0fcf3 100644 (file)
@@ -1490,10 +1490,8 @@ int vmcore_add_device_dump(struct vmcoredd_data *data)
                return -EINVAL;
 
        dump = vzalloc(sizeof(*dump));
-       if (!dump) {
-               ret = -ENOMEM;
-               goto out_err;
-       }
+       if (!dump)
+               return -ENOMEM;
 
        /* Keep size of the buffer page aligned so that it can be mmaped */
        data_size = roundup(sizeof(struct vmcoredd_header) + data->size,
@@ -1519,22 +1517,19 @@ int vmcore_add_device_dump(struct vmcoredd_data *data)
        dump->size = data_size;
 
        /* Add the dump to driver sysfs list and update the elfcore hdr */
-       mutex_lock(&vmcore_mutex);
-       if (vmcore_opened)
-               pr_warn_once("Unexpected adding of device dump\n");
-       if (vmcore_open) {
-               ret = -EBUSY;
-               goto unlock;
-       }
+       scoped_guard(mutex, &vmcore_mutex) {
+               if (vmcore_opened)
+                       pr_warn_once("Unexpected adding of device dump\n");
+               if (vmcore_open) {
+                       ret = -EBUSY;
+                       goto out_err;
+               }
 
-       list_add_tail(&dump->list, &vmcoredd_list);
-       vmcoredd_update_size(data_size);
-       mutex_unlock(&vmcore_mutex);
+               list_add_tail(&dump->list, &vmcoredd_list);
+               vmcoredd_update_size(data_size);
+       }
        return 0;
 
-unlock:
-       mutex_unlock(&vmcore_mutex);
-
 out_err:
        vfree(buf);
        vfree(dump);