[PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning

Thorsten Blum posted 1 patch 1 year, 10 months ago
arch/xtensa/platforms/iss/console.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
Posted by Thorsten Blum 1 year, 10 months ago
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
Re: [PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
Posted by Max Filippov 1 year, 10 months ago
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
Re: [PATCH v3] tty: xtensa/iss: Use min() to fix Coccinelle warning
Posted by Jiri Slaby 1 year, 10 months ago
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