tty: xtensa/iss: Use umin() to fix Coccinelle warning
PATCH 1/1 tty: xtensa/iss: Use umin() to fix Coccinelle warning
Use unsigned size_t to improve len data type and umin() to fix the following Coccinelle/coccicheck warning reported by minmax.cocci:
WARNING opportunity for min()
--- arch/xtensa/platforms/iss/console.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/xtensa/platforms/iss/console.c +3 -2
@@ -167,8 +167,9 @@ late_initcall(rs_init);static void iss_console_write (struct console *co,const char *s,unsigned count) {if (s && *s !=0 ) { -int len =strlen (s); -simc_write (1 , s, count < len ? count : len); +size_t len =strlen (s); + +simc_write (1 , s,umin (count, len)); } }
Signature · 1 line
2.44.0
Max Filippov
maintainerQuoted 10 lines · Thorsten Blum
Use unsigned
size_tto improve len data type andumin()to fix the following Coccinelle/coccicheck warning reported byminmax.cocci:WARNING opportunity for
min()Signed-off-by Thorsten Blum <[email protected]>--- arch/xtensa/platforms/iss/console.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Thanks. Applied to my xtensa tree.
-- Max
Quoted 15 lines · Thorsten Blum
Use unsigned
size_tto improve len data type andumin()to fix the following Coccinelle/coccicheck warning reported byminmax.cocci:WARNING opportunity for
min()Signed-off-by Thorsten Blum <[email protected]>--- arch/xtensa/platforms/iss/console.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/xtensa/platforms/iss/console.c +0
-0
arch/xtensa/platforms/iss/console.c late_initcall(rs_init); · line 172
Quoted 8 lines
arch/xtensa/platforms/iss/console.c +3
-2@@ -167,8 +167,9 @@ late_initcall(rs_init);static void iss_console_write (struct console *co,const char *s,unsigned count) {if (s && *s !=0 ) { -int len =strlen (s); -simc_write (1 , s, count < len ? count : len); +size_t len =strlen (s); + +simc_write (1 , s,umin (count, len));
The cast to unsigned (ie. umin()) is now not necessary. You should have used min() as was suggested, right?
arch/xtensa/platforms/iss/console.c late_initcall(rs_init); · line 175
Quoted 3 lines
arch/xtensa/platforms/iss/console.c +0
-0} }
thanks,
Signature · 2 lines
js suse labs
Quoted 2 lines · Jiri Slaby
The cast to unsigned (ie.
umin()) is now not necessary. You should have usedmin()as was suggested, right?
Yes, umin() was only necessary before I casted len from int to size_t.
I'll submit a v2 shortly.
Thanks,
Thorsten
PATCH v2 1/1 tty: xtensa/iss: Use min() to fix Coccinelle warning
In reply to Jiri SlabyUse unsigned size_t to improve len data type and min() to fix the following Coccinelle/coccicheck warning reported by minmax.cocci:
WARNING opportunity for min()
---
Changes in v2:
- Use min() instead of umin() as suggested by Jiri Slaby
--- arch/xtensa/platforms/iss/console.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/xtensa/platforms/iss/console.c +3 -2
@@ -167,8 +167,9 @@ late_initcall(rs_init);static void iss_console_write (struct console *co,const char *s,unsigned count) {if (s && *s !=0 ) { -int len =strlen (s); -simc_write (1 , s, count < len ? count : len); +size_t len =strlen (s); + +simc_write (1 , s,min (count, len)); } }
Signature · 1 line
2.44.0
Re: [PATCH v2] tty: xtensa/iss: Use min() to fix Coccinelle warning
Quoted 18 lines · Thorsten Blum
Use unsigned
size_tto improve len data type andmin()to fix the following Coccinelle/coccicheck warning reported byminmax.cocci:WARNING opportunity for
min()Signed-off-by Thorsten Blum <[email protected]>---
Changes in v2:
- Usemin()instead ofumin()as suggested by Jiri Slaby--- arch/xtensa/platforms/iss/console.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/xtensa/platforms/iss/console.c +0
-0
arch/xtensa/platforms/iss/console.c late_initcall(rs_init); · line 172
Quoted 8 lines
arch/xtensa/platforms/iss/console.c +3
-2@@ -167,8 +167,9 @@ late_initcall(rs_init);static void iss_console_write (struct console *co,const char *s,unsigned count) {if (s && *s !=0 ) { -int len =strlen (s); -simc_write (1 , s, count < len ? count : len); +size_t len =strlen (s); + +simc_write (1 , s,min (count, len));
So do you need 'len' after all :)?
if (s && *s != 0)
simc_write(1, s, min(count, strlen(s)));
sounds good.
Quoted 3 lines
arch/xtensa/platforms/iss/console.c +0
-0} }
Signature · 2 lines
js suse labs
PATCH v3 1/1 tty: xtensa/iss: Use min() to fix Coccinelle warning
Inline strlen() and use min() to fix the following Coccinelle/coccicheck warning reported by minmax.cocci:
WARNING opportunity for min()
---
Changes in v2:
- Use min() instead of umin() as suggested by Jiri Slaby
Changes in v3:
- Inline strlen() as suggested by Jiri Slaby
--- arch/xtensa/platforms/iss/console.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/xtensa/platforms/iss/console.c +2 -4
@@ -166,10 +166,8 @@ late_initcall(rs_init);static void iss_console_write (struct console *co,const char *s,unsigned count) { -if (s && *s !=0 ) { -int len =strlen (s); -simc_write (1 , s, count < len ? count : len); - } +if (s && *s !=0 ) +simc_write (1 , s,min (count,strlen (s))); }static struct tty_driver *iss_console_device (struct console *c,int *index)
Signature · 1 line
2.44.0
Re: [PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
Quoted 6 lines · Thorsten Blum
Inline
strlen()and usemin()to fix the following Coccinelle/coccicheck warning reported byminmax.cocci:WARNING opportunity for
min()Signed-off-by Thorsten Blum <[email protected]>
Thanks.
Quoted 27 lines
---
Changes in v2:
- Usemin()instead ofumin()as suggested by Jiri SlabyChanges in v3:
- Inlinestrlen()as suggested by Jiri Slaby--- arch/xtensa/platforms/iss/console.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)arch/xtensa/platforms/iss/console.c +2
-4@@ -166,10 +166,8 @@ late_initcall(rs_init);static void iss_console_write (struct console *co,const char *s,unsigned count) { -if (s && *s !=0 ) { -int len =strlen (s); -simc_write (1 , s, count < len ? count : len); - } +if (s && *s !=0 ) +simc_write (1 , s,min (count,strlen (s))); }static struct tty_driver *iss_console_device (struct console *c,int *index)
Signature · 2 lines
js suse labs
Max Filippov
maintainerRe: [PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
In reply to Thorsten BlumQuoted 11 lines · Thorsten Blum
Inline
strlen()and usemin()to fix the following Coccinelle/coccicheck warning reported byminmax.cocci:WARNING opportunity for
min()Signed-off-by Thorsten Blum <[email protected]>---
Changes in v2:
- Usemin()instead ofumin()as suggested by Jiri Slaby
Quoted 5 lines
Changes in v3:
- Inlinestrlen()as suggested by Jiri Slaby--- arch/xtensa/platforms/iss/console.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Thanks. Applied to my xtensa tree.
-- Max