efi_test: fix Coccinelle warning and CoverityScan issues
Subsystems (2)
cover efi_test: fix Coccinelle warning and CoverityScan issues
Fix the memdup_user warning found by Cocinelle, and some minor uninitialized scalar variable issues found by CoverityScan.
Ivan Hu (3):
efi/efi_test: use memdup_user() as a cleanup efi/efi_test: fix the uninitialized value datasize efi/efi_test: fix the uninitialized value rv
drivers/firmware/efi/test/efi_test.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1474859691-8574-1-git-send-email-ivan.hu-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org
PATCH 1/3 efi/efi_test: use memdup_user() as a cleanup
Cleanup the warning, drivers/firmware/efi/test/efi_test.c:269:8-15: WARNING opportunity for memdup_user
Use memdup_user rather than duplicating its implementation This is a little bit restricted to reduce false positives
Generated by: coccinelle/api/memdup_user.coc
--- drivers/firmware/efi/test/efi_test.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/firmware/efi/test/efi_test.c +3 -7
@@ -266,14 +266,10 @@ static long efi_runtime_set_variable(unsigned long arg)return rv; } - data =kmalloc (setvariable.data_size,GFP_KERNEL ); -if (!data) { + data =memdup_user (setvariable.data, setvariable.data_size); +if (IS_ERR (data)) {kfree (name); -return -ENOMEM ; - } -if (copy_from_user (data, setvariable.data, setvariable.data_size)) { - rv = -EFAULT ; - goto out; +return PTR_ERR (data); } status = efi.set_variable(name, &vendor_guid,
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1474859691-8574-2-git-send-email-ivan.hu-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org
Re: [PATCH 1/3] efi/efi_test: use memdup_user() as a cleanup
Quoted 6 lines · Ivan Hu
Cleanup the warning, drivers/firmware/efi/test/efi_test.c:269:8-15: WARNING opportunity for
memdup_userUse
memdup_userrather than duplicating its implementation This is a little bit restricted to reduce false positives
I don't understand this sentence. What restriction are you talking about?
Quoted 32 lines
Generated by: coccinelle/api/memdup_user.coc
Signed-off-by Ivan Hu <[email protected]>--- drivers/firmware/efi/test/efi_test.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/firmware/efi/test/efi_test.c +3
-7@@ -266,14 +266,10 @@ static long efi_runtime_set_variable(unsigned long arg)return rv; } - data =kmalloc (setvariable.data_size,GFP_KERNEL ); -if (!data) { + data =memdup_user (setvariable.data, setvariable.data_size); +if (IS_ERR (data)) {kfree (name); -return -ENOMEM ; - } -if (copy_from_user (data, setvariable.data, setvariable.data_size)) { - rv = -EFAULT ; - goto out; +return PTR_ERR (data); } status = efi.set_variable(name, &vendor_guid,Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 20161003201718.GL16071-mF/unelCI9GS6iBeEJttW/[email protected]
Re: [PATCH 1/3] efi/efi_test: use memdup_user() as a cleanup
Hi Matt,
The warning message is from Kbuild test robot,
and I believe it tries to persuade us to use memdup_user instead of kmalloc and copy_form_user,
With this new function, we don't have to write 'len' twice, which can lead to typos/mistakes. It also produces smaller code and kernel text.
http://lkml.iu.edu/hypermail/linux/kernel/0903.0/02349.html
Cheers,
Ivan
Quoted 43 lines · Matt Fleming
Quoted 6 lines · Ivan Hu
Cleanup the warning, drivers/firmware/efi/test/efi_test.c:269:8-15: WARNING opportunity for
memdup_userUse
memdup_userrather than duplicating its implementation This is a little bit restricted to reduce false positivesI don't understand this sentence. What restriction are you talking about?
Quoted 32 lines
Generated by: coccinelle/api/memdup_user.coc
Signed-off-by Ivan Hu <[email protected]>--- drivers/firmware/efi/test/efi_test.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/firmware/efi/test/efi_test.c +3
-7@@ -266,14 +266,10 @@ static long efi_runtime_set_variable(unsigned long arg)return rv; } - data =kmalloc (setvariable.data_size,GFP_KERNEL ); -if (!data) { + data =memdup_user (setvariable.data, setvariable.data_size); +if (IS_ERR (data)) {kfree (name); -return -ENOMEM ; - } -if (copy_from_user (data, setvariable.data, setvariable.data_size)) { - rv = -EFAULT ; - goto out; +return PTR_ERR (data); } status = efi.set_variable(name, &vendor_guid,Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 3fb6d9fa-b554-509b-fc59-d75340017589-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org
Re: [PATCH 1/3] efi/efi_test: use memdup_user() as a cleanup
Quoted 7 lines · ivanhu
Hi Matt,
The warning message is from
Kbuildtest robot,
Quoted 8 lines
and I believe it tries to persuade us to use
memdup_userinstead of kmalloc andcopy_form_user,With this new function, we don't have to write 'len' twice, which can lead to typos/mistakes.
It also produces smaller code and kernel text.
Right, I understand all that. My question was specifically about the following sentence from your patch,
Quoted 1 line
This is a little bit restricted to reduce false positives
What restriction that reduces false positives are you referring to?
A message that is not in the archive (sent off-list or not yet received): 20161004213743.GV16071-mF/unelCI9GS6iBeEJttW/[email protected]
Re: [PATCH 1/3] efi/efi_test: use memdup_user() as a cleanup
Quoted 15 lines · Matt Fleming
Quoted 14 lines · ivanhu
Hi Matt,
The warning message is from
Kbuildtest robot,and I believe it tries to persuade us to use
memdup_userinstead of kmalloc andcopy_form_user,With this new function, we don't have to write 'len' twice, which can lead to typos/mistakes.
It also produces smaller code and kernel text.
Quoted 8 lines
Right, I understand all that. My question was specifically about the following sentence from your patch,
Quoted 1 line
This is a little bit restricted to reduce false positives
What restriction that reduces false positives are you referring to?
I believe that author means that, with this new function, we don't have to write 'len' twice, which can lead to typos/mistakes ....
Let me remove the ambiguous comments and send out the patch again.
Ivan
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/3 efi/efi_test: fix the uninitialized value datasize
In reply to a message not in the archiveFix the minor issue found by CoverityScan
CID 1358931 (#1 of 1): Uninitialized scalar variable (UNINIT)9.uninit_use: Using uninitialized value datasize.
199 prev_datasize = datasize;
200 status = efi.get_variable(name, vd, at, dz, data);
--- drivers/firmware/efi/test/efi_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/test/efi_test.c +1 -1
@@ -156,7 +156,7 @@ static long efi_runtime_get_variable(unsigned long arg) {struct efi_getvariable __user *getvariable_user;struct efi_getvariable getvariable; -unsigned long datasize, prev_datasize, *dz; +unsigned long datasize =0 , prev_datasize, *dz;efi_guid_t vendor_guid, *vd =NULL ;efi_status_t status;efi_char16_t *name =NULL ;
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1474859691-8574-3-git-send-email-ivan.hu-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org
Matt Fleming
AppliedRe: [PATCH 2/3] efi/efi_test: fix the uninitialized value datasize
Quoted 16 lines · Ivan Hu
Fix the minor issue found by CoverityScan
CID 1358931 (#1 of 1): Uninitialized scalar variable (UNINIT)9.uninit_use: Using uninitialized value datasize.
199prev_datasize= datasize;
200 status =efi.get_variable(name, vd, at, dz, data);Signed-off-by Ivan Hu <[email protected]>--- drivers/firmware/efi/test/efi_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/firmware/efi/test/efi_test.c +0
-0
drivers/firmware/efi/test/efi_test.c static long efi_runtime_get_variable(unsigned long arg) · line 162
Quoted 8 lines
drivers/firmware/efi/test/efi_test.c +1
-1@@ -156,7 +156,7 @@ static long efi_runtime_get_variable(unsigned long arg) {struct efi_getvariable __user *getvariable_user;struct efi_getvariable getvariable; -unsigned long datasize, prev_datasize, *dz; +unsigned long datasize =0 , prev_datasize, *dz;efi_guid_t vendor_guid, *vd =NULL ;efi_status_t status;efi_char16_t *name =NULL ;
Thanks, applied to 'next'.
PATCH 3/3 efi/efi_test: fix the uninitialized value rv
In reply to a message not in the archiveFix the minor issue found by CoverityScan
520 kfree(name);
CID 1358932 (#1 of 1): Uninitialized scalar variable (UNINIT)17.uninit_use: Using uninitialized value rv.
521 return rv;
522}
--- drivers/firmware/efi/test/efi_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/test/efi_test.c +1 -1
@@ -425,7 +425,7 @@ static long efi_runtime_get_nextvariablename(unsigned long arg)efi_guid_t *vd =NULL ;efi_guid_t vendor_guid;efi_char16_t *name =NULL ; -int rv; +int rv =0 ; getnextvariablename_user = (struct efi_getnextvariablename __user *)arg;
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1474859691-8574-4-git-send-email-ivan.hu-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org
Matt Fleming
AppliedRe: [PATCH 3/3] efi/efi_test: fix the uninitialized value rv
Quoted 17 lines · Ivan Hu
Fix the minor issue found by CoverityScan
520 kfree(name);
CID 1358932 (#1 of 1): Uninitialized scalar variable (UNINIT)17.uninit_use: Using uninitialized value rv.
521 return rv;
522}Signed-off-by Ivan Hu <[email protected]>--- drivers/firmware/efi/test/efi_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/firmware/efi/test/efi_test.c +0
-0
drivers/firmware/efi/test/efi_test.c static long efi_runtime_get_nextvariablename(unsigned long arg) · line 431
Quoted 8 lines
drivers/firmware/efi/test/efi_test.c +1
-1@@ -425,7 +425,7 @@ static long efi_runtime_get_nextvariablename(unsigned long arg)efi_guid_t *vd =NULL ;efi_guid_t vendor_guid;efi_char16_t *name =NULL ; -int rv; +int rv =0 ; getnextvariablename_user = (struct efi_getnextvariablename __user *)arg;
Thanks, applied to 'next'.