mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
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 <torvalds@linux-foundation.org> 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:341115822f
("usercopy: Add parentheses around assignment in test_copy_struct_from_user") Fixes:f5a1a536fa
("lib: introduce copy_struct_from_user() helper") Signed-off-by: Aleksa Sarai <cyphar@cyphar.com> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com> Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com> Link: https://lore.kernel.org/r/20191005233028.18566-1-cyphar@cyphar.com Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
da0c9ea146
commit
c90012ac85
@ -52,13 +52,14 @@ static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)
|
||||
size_t zero_end = size - zero_start;
|
||||
|
||||
/*
|
||||
* We conduct a series of check_nonzero_user() tests on a block of memory
|
||||
* with the following byte-pattern (trying every possible [start,end]
|
||||
* pair):
|
||||
* We conduct a series of check_nonzero_user() tests on a block of
|
||||
* memory with the following byte-pattern (trying every possible
|
||||
* [start,end] pair):
|
||||
*
|
||||
* [ 00 ff 00 ff ... 00 00 00 00 ... ff 00 ff 00 ]
|
||||
*
|
||||
* And we verify that check_nonzero_user() acts identically to memchr_inv().
|
||||
* And we verify that check_nonzero_user() acts identically to
|
||||
* memchr_inv().
|
||||
*/
|
||||
|
||||
memset(kmem, 0x0, size);
|
||||
@ -93,11 +94,13 @@ static int test_copy_struct_from_user(char *kmem, char __user *umem,
|
||||
size_t ksize, usize;
|
||||
|
||||
umem_src = kmalloc(size, GFP_KERNEL);
|
||||
if ((ret |= test(umem_src == NULL, "kmalloc failed")))
|
||||
ret = test(umem_src == NULL, "kmalloc failed");
|
||||
if (ret)
|
||||
goto out_free;
|
||||
|
||||
expected = kmalloc(size, GFP_KERNEL);
|
||||
if ((ret |= test(expected == NULL, "kmalloc failed")))
|
||||
ret = test(expected == NULL, "kmalloc failed");
|
||||
if (ret)
|
||||
goto out_free;
|
||||
|
||||
/* Fill umem with a fixed byte pattern. */
|
||||
|
Loading…
Reference in New Issue
Block a user