]> git.baikalelectronics.ru Git - kernel.git/commit
lib: test_user_copy: style cleanup
authorAleksa Sarai <cyphar@cyphar.com>
Sat, 5 Oct 2019 23:30:28 +0000 (10:30 +1100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 7 Oct 2019 00:03:07 +0000 (02:03 +0200)
commitda9a182ea814de3f6a73d54ae05279ed95ba62fb
treebd1f9f766105c864a30c4278ad1cbc59887a74aa
parent52b7759f73b03afc7cba59d3686ec69261291235
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: 4ad1403ea6ee ("usercopy: Add parentheses around assignment in test_copy_struct_from_user")
Fixes: 3d1843034a3a ("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>
lib/test_user_copy.c