Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: serio-raw - fix potential serio port name truncation

When compiling with W=1 the following warnings are triggered:

drivers/input/serio/serio_raw.c: In function ‘serio_raw_connect’:
drivers/input/serio/serio_raw.c:303:28: error: ‘%ld’ directive output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Werror=format-truncation=]
303 | "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no));

atomic_inc_return() returns an int, so there is no reason to cast it
to long and print as such. Fix the issue by removing the cast,
printing it as unsigned decimal, and expanding the name from 16 to 20
bytes to accommodate the largest possible port number.

Link: https://lore.kernel.org/r/20240905041732.2034348-22-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+2 -2
+2 -2
drivers/input/serio/serio_raw.c
··· 29 29 unsigned char queue[SERIO_RAW_QUEUE_LEN]; 30 30 unsigned int tail, head; 31 31 32 - char name[16]; 32 + char name[20]; 33 33 struct kref kref; 34 34 struct serio *serio; 35 35 struct miscdevice dev; ··· 277 277 } 278 278 279 279 snprintf(serio_raw->name, sizeof(serio_raw->name), 280 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no)); 280 + "serio_raw%u", atomic_inc_return(&serio_raw_no)); 281 281 kref_init(&serio_raw->kref); 282 282 INIT_LIST_HEAD(&serio_raw->client_list); 283 283 init_waitqueue_head(&serio_raw->wait);