Skip to content

Commit ad0039d

Browse files
Su Huiakpm00
authored andcommitted
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/[email protected] Signed-off-by: Su Hui <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Cc: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Cc: Suhui <[email protected]> Cc: Vivek Goyal <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 37d0f07 commit ad0039d

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

fs/proc/vmcore.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,10 +1490,8 @@ int vmcore_add_device_dump(struct vmcoredd_data *data)
14901490
return -EINVAL;
14911491

14921492
dump = vzalloc(sizeof(*dump));
1493-
if (!dump) {
1494-
ret = -ENOMEM;
1495-
goto out_err;
1496-
}
1493+
if (!dump)
1494+
return -ENOMEM;
14971495

14981496
/* Keep size of the buffer page aligned so that it can be mmaped */
14991497
data_size = roundup(sizeof(struct vmcoredd_header) + data->size,
@@ -1519,22 +1517,19 @@ int vmcore_add_device_dump(struct vmcoredd_data *data)
15191517
dump->size = data_size;
15201518

15211519
/* Add the dump to driver sysfs list and update the elfcore hdr */
1522-
mutex_lock(&vmcore_mutex);
1523-
if (vmcore_opened)
1524-
pr_warn_once("Unexpected adding of device dump\n");
1525-
if (vmcore_open) {
1526-
ret = -EBUSY;
1527-
goto unlock;
1528-
}
1520+
scoped_guard(mutex, &vmcore_mutex) {
1521+
if (vmcore_opened)
1522+
pr_warn_once("Unexpected adding of device dump\n");
1523+
if (vmcore_open) {
1524+
ret = -EBUSY;
1525+
goto out_err;
1526+
}
15291527

1530-
list_add_tail(&dump->list, &vmcoredd_list);
1531-
vmcoredd_update_size(data_size);
1532-
mutex_unlock(&vmcore_mutex);
1528+
list_add_tail(&dump->list, &vmcoredd_list);
1529+
vmcoredd_update_size(data_size);
1530+
}
15331531
return 0;
15341532

1535-
unlock:
1536-
mutex_unlock(&vmcore_mutex);
1537-
15381533
out_err:
15391534
vfree(buf);
15401535
vfree(dump);

0 commit comments

Comments
 (0)