]> www.infradead.org Git - linux.git/commitdiff
kcsan: Use min() to fix Coccinelle warning
authorThorsten Blum <thorsten.blum@toblux.com>
Mon, 24 Jun 2024 17:57:28 +0000 (19:57 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Thu, 1 Aug 2024 23:40:44 +0000 (16:40 -0700)
Fixes the following Coccinelle/coccicheck warning reported by
minmax.cocci:

WARNING opportunity for min()

Use const size_t instead of int for the result of min().

Compile-tested with CONFIG_KCSAN=y.

Reviewed-by: Marco Elver <elver@google.com>
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/kcsan/debugfs.c

index 1d1d1b0e424897d1c9ba750d046f7e535b3b724d..53b21ae30e00ee196878e33ed867ed734cfad3b4 100644 (file)
@@ -225,7 +225,7 @@ debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *o
 {
        char kbuf[KSYM_NAME_LEN];
        char *arg;
-       int read_len = count < (sizeof(kbuf) - 1) ? count : (sizeof(kbuf) - 1);
+       const size_t read_len = min(count, sizeof(kbuf) - 1);
 
        if (copy_from_user(kbuf, buf, read_len))
                return -EFAULT;