linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] fs/proc/vmcore: a few cleanups for vmcore_add_device_dump
@ 2025-06-26 10:54 Su Hui
  2025-06-26 13:24 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Su Hui @ 2025-06-26 10:54 UTC (permalink / raw)
  To: akpm, bhe, vgoyal, dyoung
  Cc: Su Hui, dan.carpenter, kexec, linux-kernel, linux-fsdevel,
	kernel-janitors

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@nfschina.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] fs/proc/vmcore: a few cleanups for vmcore_add_device_dump
  2025-06-26 10:54 [PATCH v2] fs/proc/vmcore: a few cleanups for vmcore_add_device_dump Su Hui
@ 2025-06-26 13:24 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2025-06-26 13:24 UTC (permalink / raw)
  To: Su Hui
  Cc: akpm, bhe, vgoyal, dyoung, kexec, linux-kernel, linux-fsdevel,
	kernel-janitors

On Thu, Jun 26, 2025 at 06:54:41PM +0800, Su Hui wrote:
> 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@nfschina.com>
> ---

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-26 13:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-26 10:54 [PATCH v2] fs/proc/vmcore: a few cleanups for vmcore_add_device_dump Su Hui
2025-06-26 13:24 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).