Skip to content

Commit c90012a

Browse files
cypharChristian Brauner
authored andcommitted
lib: test_user_copy: style cleanup
While writing the tests for copy_struct_from_user(), I used a construct that Linus doesn't appear to be too fond of: On 2019-10-04, Linus Torvalds <[email protected]> wrote: > Hmm. That code is ugly, both before and after the fix. > > This just doesn't make sense for so many reasons: > > if ((ret |= test(umem_src == NULL, "kmalloc failed"))) > > where the insanity comes from > > - why "|=" when you know that "ret" was zero before (and it had to > be, for the test to make sense) > > - why do this as a single line anyway? > > - don't do the stupid "double parenthesis" to hide a warning. Make it > use an actual comparison if you add a layer of parentheses. So instead, use a bog-standard check that isn't nearly as ugly. Fixes: 3411158 ("usercopy: Add parentheses around assignment in test_copy_struct_from_user") Fixes: f5a1a53 ("lib: introduce copy_struct_from_user() helper") Signed-off-by: Aleksa Sarai <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent da0c9ea commit c90012a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/test_user_copy.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)
5252
size_t zero_end = size - zero_start;
5353

5454
/*
55-
* We conduct a series of check_nonzero_user() tests on a block of memory
56-
* with the following byte-pattern (trying every possible [start,end]
57-
* pair):
55+
* We conduct a series of check_nonzero_user() tests on a block of
56+
* memory with the following byte-pattern (trying every possible
57+
* [start,end] pair):
5858
*
5959
* [ 00 ff 00 ff ... 00 00 00 00 ... ff 00 ff 00 ]
6060
*
61-
* And we verify that check_nonzero_user() acts identically to memchr_inv().
61+
* And we verify that check_nonzero_user() acts identically to
62+
* memchr_inv().
6263
*/
6364

6465
memset(kmem, 0x0, size);
@@ -93,11 +94,13 @@ static int test_copy_struct_from_user(char *kmem, char __user *umem,
9394
size_t ksize, usize;
9495

9596
umem_src = kmalloc(size, GFP_KERNEL);
96-
if ((ret |= test(umem_src == NULL, "kmalloc failed")))
97+
ret = test(umem_src == NULL, "kmalloc failed");
98+
if (ret)
9799
goto out_free;
98100

99101
expected = kmalloc(size, GFP_KERNEL);
100-
if ((ret |= test(expected == NULL, "kmalloc failed")))
102+
ret = test(expected == NULL, "kmalloc failed");
103+
if (ret)
101104
goto out_free;
102105

103106
/* Fill umem with a fixed byte pattern. */

0 commit comments

Comments
 (0)