]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
mlx4: Use snprintf instead of complicated strcpy
authorQian Cai <cai@gmx.us>
Fri, 30 Nov 2018 02:18:07 +0000 (21:18 -0500)
committerMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
Fri, 17 Jan 2020 17:22:23 +0000 (14:22 -0300)
BugLink: https://bugs.launchpad.net/bugs/1857158
[ Upstream commit 0fbc9b8b4ea3f688a5da141a64f97aa33ad02ae9 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/infiniband/hw/mlx4/sysfs.c

index e219093d2764536a58c7c362a08167361ed0e93a..d2da28d613f2cc41397de8f2a9d7af99510aaa54 100644 (file)
@@ -353,16 +353,12 @@ err:
 
 static void get_name(struct mlx4_ib_dev *dev, char *name, int i, int max)
 {
-       char base_name[9];
-
-       /* pci_name format is: bus:dev:func -> xxxx:yy:zz.n */
-       strlcpy(name, pci_name(dev->dev->persist->pdev), max);
-       strncpy(base_name, name, 8); /*till xxxx:yy:*/
-       base_name[8] = '\0';
-       /* with no ARI only 3 last bits are used so when the fn is higher than 8
+       /* pci_name format is: bus:dev:func -> xxxx:yy:zz.n
+        * with no ARI only 3 last bits are used so when the fn is higher than 8
         * need to add it to the dev num, so count in the last number will be
         * modulo 8 */
-       sprintf(name, "%s%.2d.%d", base_name, (i/8), (i%8));
+       snprintf(name, max, "%.8s%.2d.%d", pci_name(dev->dev->persist->pdev),
+                i / 8, i % 8);
 }
 
 struct mlx4_port {