Skip to contentSkip to conversation

usercopy: Add parentheses around assignment in test_copy_struct_from_user

PATCH In review Nathan Chancellor 3 participants 3 messages Oct 3, 2019 1 message not in the archive Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usercopy: Add parentheses around assignment in test_copy_struct_from_user

Clang warns:

lib/test_user_copy.c:96:10: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]

        if (ret |= test(umem_src == NULL, "kmalloc failed"))
            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/test_user_copy.c:96:10: note: place parentheses around the
assignment to silence this warning
        if (ret |= test(umem_src == NULL, "kmalloc failed"))
                ^
            (                                              )
lib/test_user_copy.c:96:10: note: use '!=' to turn this compound
assignment into an inequality comparison
        if (ret |= test(umem_src == NULL, "kmalloc failed"))
                ^~
                !=

Add the parentheses as it suggests because this is intentional.

Fixes f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper")
---
 lib/test_user_copy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/test_user_copy.c +2 -2
index 950ee88cd6ac..e365ace06538 100644
@@ -93,11 +93,11 @@ 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"))
+	if ((ret |= test(umem_src == NULL, "kmalloc failed")))
 		goto out_free;
 
 	expected = kmalloc(size, GFP_KERNEL);
-	if (ret |= test(expected == NULL, "kmalloc failed"))
+	if ((ret |= test(expected == NULL, "kmalloc failed")))
 		goto out_free;
 
 	/* Fill umem with a fixed byte pattern. */
Signature · 1 line
2.23.0

A message that is not in the archive (sent off-list or not yet received): CAHrFyr4GFJHQLHOi_OuDVkhuKxfnf_VkTWk6MJ2Mn1EtWhpqjg@mail.gmail.com

Acked-by
#2 lore raw
Quoted 22 lines · Christian Brauner
Quoted 19 lines · On Thu, Oct 3, 2019, 19:11 Nathan Chancellor <[email protected]> wrote:

Clang warns:

lib/test_user_copy.c:96:10: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]

        if (ret |= test(umem_src == NULL, "kmalloc failed"))
            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/test_user_copy.c:96:10: note: place parentheses around the
assignment to silence this warning
        if (ret |= test(umem_src == NULL, "kmalloc failed"))
                ^
            (                                              )
lib/test_user_copy.c:96:10: note: use '!=' to turn this compound
assignment into an inequality comparison
        if (ret |= test(umem_src == NULL, "kmalloc failed"))
                ^~
                !=

Add the parentheses as it suggests because this is intentional.

Quoted 8 lines
Quoted 4 lines
Fixes f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper")

I'll take this. Aleksa, can I get your ack too, please?

Signature · 4 lines
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
#3 lore raw
In reply to Nathan Chancellor
Quoted 17 lines · Nathan Chancellor

Clang warns:

lib/test_user_copy.c:96:10: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]

        if (ret |= test(umem_src == NULL, "kmalloc failed"))
            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/test_user_copy.c:96:10: note: place parentheses around the
assignment to silence this warning
        if (ret |= test(umem_src == NULL, "kmalloc failed"))
                ^
            (                                              )
lib/test_user_copy.c:96:10: note: use '!=' to turn this compound
assignment into an inequality comparison
        if (ret |= test(umem_src == NULL, "kmalloc failed"))
                ^~
                !=
Quoted 5 lines

Add the parentheses as it suggests because this is intentional.

Fixes f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper")

Applied to:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/log/?h=copy_struct_from_user

Thanks!
Christian