[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250626105440.1053139-1-suhui@nfschina.com>
Date: Thu, 26 Jun 2025 18:54:41 +0800
From: Su Hui <suhui@...china.com>
To: akpm@...ux-foundation.org,
bhe@...hat.com,
vgoyal@...hat.com,
dyoung@...hat.com
Cc: Su Hui <suhui@...china.com>,
dan.carpenter@...aro.org,
kexec@...ts.infradead.org,
linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
kernel-janitors@...r.kernel.org
Subject: [PATCH v2] fs/proc/vmcore: a few cleanups for vmcore_add_device_dump
There are two cleanups for vmcore_add_device_dump(). Return -ENOMEM
directly rather than goto the label to simplify the code. Using
scoped_guard() to simplify the lock/unlock code.
Signed-off-by: Su Hui <suhui@...china.com>
---
v2:
- Remove the wrong change of 'data_size'.
- Move 'Return 0;' out of the scoped_guard.
v1:
- https://lore.kernel.org/all/20250623104704.3489471-1-suhui@nfschina.com/
fs/proc/vmcore.c | 29 ++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 10d01eb09c43..f188bd900eb2 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -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);
--
2.30.2
Powered by blists - more mailing lists