mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 12:21:22 -05:00
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 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>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
list_add_tail(&dump->list, &vmcoredd_list);
|
||||
vmcoredd_update_size(data_size);
|
||||
mutex_unlock(&vmcore_mutex);
|
||||
return 0;
|
||||
|
||||
unlock:
|
||||
mutex_unlock(&vmcore_mutex);
|
||||
|
||||
out_err:
|
||||
vfree(buf);
|
||||
vfree(dump);
|
||||
|
||||
Reference in New Issue
Block a user