* [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr()
@ 2022-06-03 16:44 Andy Shevchenko
2022-06-03 16:44 ` [PATCH v1 2/2] wireless: ray_cs: Drop useless status variable " Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-06-03 16:44 UTC (permalink / raw)
To: Andy Shevchenko, linux-wireless, netdev, linux-kernel
Cc: Kalle Valo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Instead of doing simple operations and using an additional variable on stack,
utilize strnlen() and reuse len variable.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/net/wireless/ray_cs.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 87e98ab068ed..9ac371d6cd6c 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -1643,31 +1643,29 @@ static void authenticate_timeout(struct timer_list *t)
/*===========================================================================*/
static int parse_addr(char *in_str, UCHAR *out)
{
+ int i, k;
int len;
- int i, j, k;
int status;
if (in_str == NULL)
return 0;
- if ((len = strlen(in_str)) < 2)
+ len = strnlen(in_str, ADDRLEN * 2 + 1) - 1;
+ if (len < 1)
return 0;
memset(out, 0, ADDRLEN);
status = 1;
- j = len - 1;
- if (j > 12)
- j = 12;
i = 5;
- while (j > 0) {
- if ((k = hex_to_bin(in_str[j--])) != -1)
+ while (len > 0) {
+ if ((k = hex_to_bin(in_str[len--])) != -1)
out[i] = k;
else
return 0;
- if (j == 0)
+ if (len == 0)
break;
- if ((k = hex_to_bin(in_str[j--])) != -1)
+ if ((k = hex_to_bin(in_str[len--])) != -1)
out[i] += k << 4;
else
return 0;
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 2/2] wireless: ray_cs: Drop useless status variable in parse_addr()
2022-06-03 16:44 [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr() Andy Shevchenko
@ 2022-06-03 16:44 ` Andy Shevchenko
2022-06-03 16:50 ` [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() " Joe Perches
2022-06-08 8:08 ` [v1,1/2] wifi: " Kalle Valo
2 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-06-03 16:44 UTC (permalink / raw)
To: Andy Shevchenko, linux-wireless, netdev, linux-kernel
Cc: Kalle Valo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
The status variable assigned only once and used also only once.
Replace it's usage by actual value.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/net/wireless/ray_cs.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 9ac371d6cd6c..1f57a0055bbd 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -1645,7 +1645,6 @@ static int parse_addr(char *in_str, UCHAR *out)
{
int i, k;
int len;
- int status;
if (in_str == NULL)
return 0;
@@ -1654,7 +1653,6 @@ static int parse_addr(char *in_str, UCHAR *out)
return 0;
memset(out, 0, ADDRLEN);
- status = 1;
i = 5;
while (len > 0) {
@@ -1672,7 +1670,7 @@ static int parse_addr(char *in_str, UCHAR *out)
if (!i--)
break;
}
- return status;
+ return 1;
}
/*===========================================================================*/
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr()
2022-06-03 16:44 [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr() Andy Shevchenko
2022-06-03 16:44 ` [PATCH v1 2/2] wireless: ray_cs: Drop useless status variable " Andy Shevchenko
@ 2022-06-03 16:50 ` Joe Perches
2022-06-03 17:05 ` Andy Shevchenko
2022-06-08 8:08 ` [v1,1/2] wifi: " Kalle Valo
2 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2022-06-03 16:50 UTC (permalink / raw)
To: Andy Shevchenko, linux-wireless, netdev, linux-kernel
Cc: Kalle Valo, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Fri, 2022-06-03 at 19:44 +0300, Andy Shevchenko wrote:
> Instead of doing simple operations and using an additional variable on stack,
> utilize strnlen() and reuse len variable.
[]
> diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
[]
> + while (len > 0) {
> + if ((k = hex_to_bin(in_str[len--])) != -1)
> out[i] = k;
> else
> return 0;
could be reversed and unindented
>
> - if (j == 0)
> + if (len == 0)
> break;
> - if ((k = hex_to_bin(in_str[j--])) != -1)
> + if ((k = hex_to_bin(in_str[len--])) != -1)
> out[i] += k << 4;
> else
> return 0;
and here
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr()
2022-06-03 16:50 ` [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() " Joe Perches
@ 2022-06-03 17:05 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-06-03 17:05 UTC (permalink / raw)
To: Joe Perches
Cc: linux-wireless, netdev, linux-kernel, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Fri, Jun 03, 2022 at 09:50:55AM -0700, Joe Perches wrote:
> On Fri, 2022-06-03 at 19:44 +0300, Andy Shevchenko wrote:
> > Instead of doing simple operations and using an additional variable on stack,
> > utilize strnlen() and reuse len variable.
> []
> > diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
> []
> > + while (len > 0) {
> > + if ((k = hex_to_bin(in_str[len--])) != -1)
> > out[i] = k;
> > else
> > return 0;
>
> could be reversed and unindented
>
> >
> > - if (j == 0)
> > + if (len == 0)
> > break;
> > - if ((k = hex_to_bin(in_str[j--])) != -1)
> > + if ((k = hex_to_bin(in_str[len--])) != -1)
> > out[i] += k << 4;
> > else
> > return 0;
>
> and here
It might be done as a follow up. Thanks!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [v1,1/2] wifi: ray_cs: Utilize strnlen() in parse_addr()
2022-06-03 16:44 [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr() Andy Shevchenko
2022-06-03 16:44 ` [PATCH v1 2/2] wireless: ray_cs: Drop useless status variable " Andy Shevchenko
2022-06-03 16:50 ` [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() " Joe Perches
@ 2022-06-08 8:08 ` Kalle Valo
2 siblings, 0 replies; 5+ messages in thread
From: Kalle Valo @ 2022-06-08 8:08 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andy Shevchenko, linux-wireless, netdev, linux-kernel,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> Instead of doing simple operations and using an additional variable on stack,
> utilize strnlen() and reuse len variable.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2 patches applied to wireless-next.git, thanks.
9e8e9187673c wifi: ray_cs: Utilize strnlen() in parse_addr()
4dfc63c002a5 wifi: ray_cs: Drop useless status variable in parse_addr()
--
https://patchwork.kernel.org/project/linux-wireless/patch/20220603164414.48436-1-andriy.shevchenko@linux.intel.com/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-06-08 8:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-03 16:44 [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr() Andy Shevchenko
2022-06-03 16:44 ` [PATCH v1 2/2] wireless: ray_cs: Drop useless status variable " Andy Shevchenko
2022-06-03 16:50 ` [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() " Joe Perches
2022-06-03 17:05 ` Andy Shevchenko
2022-06-08 8:08 ` [v1,1/2] wifi: " Kalle Valo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).