Commit ad0039db authored by Su Hui's avatar Su Hui Committed by Andrew Morton
Browse files

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: default avatarSu Hui <suhui@nfschina.com>
Reviewed-by: default avatarDan 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: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 37d0f07b
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -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);
	scoped_guard(mutex, &vmcore_mutex) {
		if (vmcore_opened)
			pr_warn_once("Unexpected adding of device dump\n");
		if (vmcore_open) {
			ret = -EBUSY;
		goto unlock;
			goto out_err;
		}

		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);