linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: xtensa/iss: Use umin() to fix Coccinelle warning
@ 2024-04-03 23:47 Thorsten Blum
  2024-04-04  2:10 ` Max Filippov
  2024-04-04  5:05 ` Jiri Slaby
  0 siblings, 2 replies; 9+ messages in thread
From: Thorsten Blum @ 2024-04-03 23:47 UTC (permalink / raw)
  To: Chris Zankel, Max Filippov
  Cc: Greg Kroah-Hartman, Jiri Slaby (SUSE), linux-kernel, Thorsten Blum

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()

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 arch/xtensa/platforms/iss/console.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index 8896e691c051..b493fc50933d 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -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));
 	}
 }
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] tty: xtensa/iss: Use umin() to fix Coccinelle warning
  2024-04-03 23:47 [PATCH] tty: xtensa/iss: Use umin() to fix Coccinelle warning Thorsten Blum
@ 2024-04-04  2:10 ` Max Filippov
  2024-04-04  5:05 ` Jiri Slaby
  1 sibling, 0 replies; 9+ messages in thread
From: Max Filippov @ 2024-04-04  2:10 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Chris Zankel, Greg Kroah-Hartman, Jiri Slaby (SUSE), linux-kernel

On Wed, Apr 3, 2024 at 4:48 PM Thorsten Blum <thorsten.blum@toblux.com> wrote:
>
> 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()
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  arch/xtensa/platforms/iss/console.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Thanks. Applied to my xtensa tree.

-- Max

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] tty: xtensa/iss: Use umin() to fix Coccinelle warning
  2024-04-03 23:47 [PATCH] tty: xtensa/iss: Use umin() to fix Coccinelle warning Thorsten Blum
  2024-04-04  2:10 ` Max Filippov
@ 2024-04-04  5:05 ` Jiri Slaby
  2024-04-04  7:35   ` Thorsten Blum
  2024-04-04  7:38   ` [PATCH v2] tty: xtensa/iss: Use min() " Thorsten Blum
  1 sibling, 2 replies; 9+ messages in thread
From: Jiri Slaby @ 2024-04-04  5:05 UTC (permalink / raw)
  To: Thorsten Blum, Chris Zankel, Max Filippov
  Cc: Greg Kroah-Hartman, linux-kernel

On 04. 04. 24, 1:47, Thorsten Blum wrote:
> 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()
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>   arch/xtensa/platforms/iss/console.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
> index 8896e691c051..b493fc50933d 100644
> --- a/arch/xtensa/platforms/iss/console.c
> +++ b/arch/xtensa/platforms/iss/console.c
> @@ -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?

>   	}
>   }
>   

thanks,
-- 
js
suse labs


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] tty: xtensa/iss: Use umin() to fix Coccinelle warning
  2024-04-04  5:05 ` Jiri Slaby
@ 2024-04-04  7:35   ` Thorsten Blum
  2024-04-04  7:38   ` [PATCH v2] tty: xtensa/iss: Use min() " Thorsten Blum
  1 sibling, 0 replies; 9+ messages in thread
From: Thorsten Blum @ 2024-04-04  7:35 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Chris Zankel, Max Filippov, Greg Kroah-Hartman, linux-kernel

On 4. Apr 2024, at 07:05, Jiri Slaby <jirislaby@kernel.org> wrote:
> 
> The cast to unsigned (ie. umin()) is now not necessary. You should have used min() 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] tty: xtensa/iss: Use min() to fix Coccinelle warning
  2024-04-04  5:05 ` Jiri Slaby
  2024-04-04  7:35   ` Thorsten Blum
@ 2024-04-04  7:38   ` Thorsten Blum
  2024-04-04  7:41     ` Jiri Slaby
  1 sibling, 1 reply; 9+ messages in thread
From: Thorsten Blum @ 2024-04-04  7:38 UTC (permalink / raw)
  To: jirislaby; +Cc: chris, gregkh, jcmvbkbc, linux-kernel, thorsten.blum

Use 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()

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
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(-)

diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index 8896e691c051..d2380767f3a4 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -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));
 	}
 }
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] tty: xtensa/iss: Use min() to fix Coccinelle warning
  2024-04-04  7:38   ` [PATCH v2] tty: xtensa/iss: Use min() " Thorsten Blum
@ 2024-04-04  7:41     ` Jiri Slaby
  2024-04-04  7:58       ` [PATCH v3] " Thorsten Blum
  0 siblings, 1 reply; 9+ messages in thread
From: Jiri Slaby @ 2024-04-04  7:41 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: chris, gregkh, jcmvbkbc, linux-kernel

On 04. 04. 24, 9:38, Thorsten Blum wrote:
> Use 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()
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
> 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(-)
> 
> diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
> index 8896e691c051..d2380767f3a4 100644
> --- a/arch/xtensa/platforms/iss/console.c
> +++ b/arch/xtensa/platforms/iss/console.c
> @@ -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.

>   	}
>   }
>   

-- 
js
suse labs


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
  2024-04-04  7:41     ` Jiri Slaby
@ 2024-04-04  7:58       ` Thorsten Blum
  2024-04-04  8:11         ` Jiri Slaby
  2024-04-04  9:12         ` Max Filippov
  0 siblings, 2 replies; 9+ messages in thread
From: Thorsten Blum @ 2024-04-04  7:58 UTC (permalink / raw)
  To: jirislaby; +Cc: chris, gregkh, jcmvbkbc, linux-kernel, thorsten.blum

Inline strlen() and use min() to fix the following Coccinelle/coccicheck
warning reported by minmax.cocci:

	WARNING opportunity for min()

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
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(-)

diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index 8896e691c051..abec44b687df 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -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)
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
  2024-04-04  7:58       ` [PATCH v3] " Thorsten Blum
@ 2024-04-04  8:11         ` Jiri Slaby
  2024-04-04  9:12         ` Max Filippov
  1 sibling, 0 replies; 9+ messages in thread
From: Jiri Slaby @ 2024-04-04  8:11 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: chris, gregkh, jcmvbkbc, linux-kernel

On 04. 04. 24, 9:58, Thorsten Blum wrote:
> Inline strlen() and use min() to fix the following Coccinelle/coccicheck
> warning reported by minmax.cocci:
> 
> 	WARNING opportunity for min()
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

Thanks.

> ---
> 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(-)
> 
> diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
> index 8896e691c051..abec44b687df 100644
> --- a/arch/xtensa/platforms/iss/console.c
> +++ b/arch/xtensa/platforms/iss/console.c
> @@ -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)

-- 
js
suse labs


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
  2024-04-04  7:58       ` [PATCH v3] " Thorsten Blum
  2024-04-04  8:11         ` Jiri Slaby
@ 2024-04-04  9:12         ` Max Filippov
  1 sibling, 0 replies; 9+ messages in thread
From: Max Filippov @ 2024-04-04  9:12 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: jirislaby, chris, gregkh, linux-kernel

On Thu, Apr 4, 2024 at 1:01 AM Thorsten Blum <thorsten.blum@toblux.com> wrote:
>
> Inline strlen() and use min() to fix the following Coccinelle/coccicheck
> warning reported by minmax.cocci:
>
>         WARNING opportunity for min()
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
> 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(-)

Thanks. Applied to my xtensa tree.

-- Max

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-04-04  9:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03 23:47 [PATCH] tty: xtensa/iss: Use umin() to fix Coccinelle warning Thorsten Blum
2024-04-04  2:10 ` Max Filippov
2024-04-04  5:05 ` Jiri Slaby
2024-04-04  7:35   ` Thorsten Blum
2024-04-04  7:38   ` [PATCH v2] tty: xtensa/iss: Use min() " Thorsten Blum
2024-04-04  7:41     ` Jiri Slaby
2024-04-04  7:58       ` [PATCH v3] " Thorsten Blum
2024-04-04  8:11         ` Jiri Slaby
2024-04-04  9:12         ` Max Filippov

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).