test_firmware: remove some dead code
Subsystems (2)
PATCH 1/2 test_firmware: remove some dead code
The test_fw_config->reqs allocation succeeded so these addresses can't be NULL. Also on the second error path, we forgot to set "rc = -ENOMEM;".
--- lib/test_firmware.c | 9 --------- 1 file changed, 9 deletions(-)
lib/test_firmware.c +0 -9
@@ -631,11 +631,6 @@ static ssize_t trigger_batched_requests_store(struct device *dev,for (i =0 ; i < test_fw_config->num_requests; i++) { req = &test_fw_config->reqs[i]; -if (!req) { -WARN_ON (1 ); - rc = -ENOMEM ; - goto out_bail; - } req->fw =NULL ; req->idx = i; req->name = test_fw_config->name;
@@ -737,10 +732,6 @@ ssize_t trigger_batched_requests_async_store(struct device *dev,for (i =0 ; i < test_fw_config->num_requests; i++) { req = &test_fw_config->reqs[i]; -if (!req) { -WARN_ON (1 ); - goto out_bail; - } req->name = test_fw_config->name; req->fw =NULL ; req->idx = i;
Signature · 1 line
2.17.1
PATCH 2/2 test_firmware: silence underflow warning in test_dev_config_update_u8()
We put an upper bound on "new" but we don't check for negatives. In this case the underflow doesn't matter very much, but we may as well make the static checker happy.
--- lib/test_firmware.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
lib/test_firmware.c +2 -5
@@ -326,15 +326,12 @@ static ssize_t test_dev_config_show_int(char *buf, int cfg)static int test_dev_config_update_u8 (const char *buf,size_t size,u8 *cfg) {int ret; -long new; +u8 new; - ret =kstrtol (buf,10 , &new); + ret =kstrtou8 (buf,10 , &new);if (ret)return ret; -if (new >U8_MAX ) -return -EINVAL ; -mutex_lock (&test_fw_mutex); *(u8 *)cfg = new;mutex_unlock (&test_fw_mutex);
Signature · 1 line
2.17.1
Andrew Morton
maintainerRe: [PATCH 2/2] test_firmware: silence underflow warning in test_dev_config_update_u8()
Quoted 1 line · On Thu, 21 Feb 2019 21:38:26 +0300 Dan Carpenter <[email protected]>…
We put an upper bound on "new" but we don't check for negatives.
U8_MAX has unsigned type, so `if (new > U8_MAX)' does check for negative.
Quoted 16 lines
In
this case the underflow doesn't matter very much, but we may as well make the static checker happy....
lib/test_firmware.c +1
-2@@ -326,15 +326,12 @@ static ssize_t test_dev_config_show_int(char *buf, int cfg)static int test_dev_config_update_u8 (const char *buf,size_t size,u8 *cfg) {int ret; -long new; +u8 new; - ret =kstrtol (buf,10 , &new);
lib/test_firmware.c static ssize_t test_dev_config_show_int(char *buf, int cfg) · line 337
Quoted 10 lines
lib/test_firmware.c +1
-3+ ret =kstrtou8 (buf,10 , &new);if (ret)return ret; -if (new >U8_MAX ) -return -EINVAL ; -mutex_lock (&test_fw_mutex); *(u8 *)cfg = new;mutex_unlock (&test_fw_mutex);
if *buf="257",
previous behavior: -EINVAL
new behavior: *cfg = 1
yes?
The old behavior seems better.
Re: [PATCH 2/2] test_firmware: silence underflow warning in test_dev_config_update_u8()
Quoted 6 lines · Andrew Morton
Quoted 1 line · On Thu, 21 Feb 2019 21:38:26 +0300 Dan Carpenter <[email protected]>…
We put an upper bound on "new" but we don't check for negatives.
U8_MAXhas unsigned type, so `if (new >U8_MAX)' does check for negative.
No, doesn't work in this case.
#define U8_MAX ((u8)~0U)
It would need to unsigned long for the type promotion to prevent negatives, but it starts as unsigned int, then unsigned char, which is type promoted to int.
It would be more clear to just write it as:
#define U8_MAX 0xff
Quoted 29 lines
Quoted 16 lines
In
this case the underflow doesn't matter very much, but we may as well make the static checker happy....
lib/test_firmware.c +1
-2@@ -326,15 +326,12 @@ static ssize_t test_dev_config_show_int(char *buf, int cfg)static int test_dev_config_update_u8 (const char *buf,size_t size,u8 *cfg) {int ret; -long new; +u8 new; - ret =kstrtol (buf,10 , &new);lib/test_firmware.c static ssize_t test_dev_config_show_int(char *buf, int cfg) · line 337
Quoted 10 lines
lib/test_firmware.c +1
-3+ ret =kstrtou8 (buf,10 , &new);if (ret)return ret; -if (new >U8_MAX ) -return -EINVAL ; -mutex_lock (&test_fw_mutex); *(u8 *)cfg = new;mutex_unlock (&test_fw_mutex);if *buf="257",
Quoted 4 lines
previous behavior:
-EINVAL
new behavior: *cfg = 1yes?
No. The kstrtou8() check the limit so it will return -ERANGE. I should have probably spelled that out better in the commit message. I'll resend tomorrow.
regard,
dan carpenter
Andrew Morton
maintainerRe: [PATCH 2/2] test_firmware: silence underflow warning in test_dev_config_update_u8()
Quoted 8 lines · On Thu, 21 Feb 2019 22:18:56 +0300 Dan Carpenter <[email protected]>…
Quoted 6 lines · Andrew Morton
Quoted 1 line · On Thu, 21 Feb 2019 21:38:26 +0300 Dan Carpenter <[email protected]>…
We put an upper bound on "new" but we don't check for negatives.
U8_MAXhas unsigned type, so `if (new >U8_MAX)' does check for negative.
Quoted 7 lines
No, doesn't work in this case.
#define
U8_MAX((u8)~0U)It would need to unsigned long for the type promotion to prevent negatives, but it starts as unsigned int, then unsigned char, which is type promoted to int.
OK.
Quoted 3 lines
It would be more clear to just write it as:
#define
U8_MAX0xff
That doesn't work either. Tricky.
#include <stdio.h>
typedef unsigned char u8;
#define U8_MAX 0xff
int main(int argc, char *argv[])
{
long new;
new = -20;
if (new > U8_MAX)
printf("over\n");
}Re: [PATCH 2/2] test_firmware: silence underflow warning in test_dev_config_update_u8()
I've looked at this some more and I don't think it's a good idea to change the type of U8_MAX. Right now INT_MAX is int and USHRT_MAX is unsigned short etc. That's the only intuitive thing for them to be.
regards,
dan carpenter