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

mlx4: Use snprintf instead of complicated strcpy

This fixes a compilation warning in sysfs.c

drivers/infiniband/hw/mlx4/sysfs.c:360:2: warning: 'strncpy' output may be
truncated copying 8 bytes from a string of length 31
[-Wstringop-truncation]

By eliminating the temporary stack buffer.

Signed-off-by: Qian Cai <cai@gmx.us>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Qian Cai and committed by
Jason Gunthorpe
0fbc9b8b 9aefcabe

+4 -8
+4 -8
drivers/infiniband/hw/mlx4/sysfs.c
··· 353 353 354 354 static void get_name(struct mlx4_ib_dev *dev, char *name, int i, int max) 355 355 { 356 - char base_name[9]; 357 - 358 - /* pci_name format is: bus:dev:func -> xxxx:yy:zz.n */ 359 - strlcpy(name, pci_name(dev->dev->persist->pdev), max); 360 - strncpy(base_name, name, 8); /*till xxxx:yy:*/ 361 - base_name[8] = '\0'; 362 - /* with no ARI only 3 last bits are used so when the fn is higher than 8 356 + /* pci_name format is: bus:dev:func -> xxxx:yy:zz.n 357 + * with no ARI only 3 last bits are used so when the fn is higher than 8 363 358 * need to add it to the dev num, so count in the last number will be 364 359 * modulo 8 */ 365 - sprintf(name, "%s%.2d.%d", base_name, (i/8), (i%8)); 360 + snprintf(name, max, "%.8s%.2d.%d", pci_name(dev->dev->persist->pdev), 361 + i / 8, i % 8); 366 362 } 367 363 368 364 struct mlx4_port {