Skip to contentSkip to conversation

virtio: vdpa: fix snprintf size argument in snet_vdpa driver

PATCH In review Alvaro Karsz 3 participants 4 messages Dec 21, 2022 – Jan 8, 2023

Subsystems (2)
lore
Share & tools
lore

Alvaro Karsz

author reviewer
#0 lore raw

PATCH 1/1 virtio: vdpa: fix snprintf size argument in snet_vdpa driver

The buffer size and the size passed to snprintf don't match, causing clang warnings.

This patch increases a little bit the size of the buffer, and uses sizeof() to get the buffer size.

This patch should be applied on top of the following patch:

virtio: vdpa: new SolidNET DPU driver,
by Alvaro Karsz [email protected]

---
 drivers/vdpa/solidrun/snet_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/solidrun/snet_main.c +4 -4
index d438a89b359..9ceacf96de0 100644
@@ -540,7 +540,7 @@ static const struct vdpa_config_ops snet_config_ops = {
 
 static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 {
-	char name[25];
+	char name[50];
 	int ret, i, mask = 0;
 	/* We don't know which BAR will be used to communicate..
 	 * We will map every bar with len > 0.
@@ -558,7 +558,7 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 		return -ENODEV;
 	}
 
-	snprintf(name, SNET_NAME_SIZE, "psnet[%s]-bars", pci_name(pdev));
+	snprintf(name, sizeof(name), "psnet[%s]-bars", pci_name(pdev));
 	ret = pcim_iomap_regions(pdev, mask, name);
 	if (ret) {
 		SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
@@ -575,10 +575,10 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 
 static int snet_open_vf_bar(struct pci_dev *pdev, struct snet *snet)
 {
-	char name[20];
+	char name[50];
 	int ret;
 
-	snprintf(name, SNET_NAME_SIZE, "snet[%s]-bar", pci_name(pdev));
+	snprintf(name, sizeof(name), "snet[%s]-bar", pci_name(pdev));
 	/* Request and map BAR */
 	ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
 	if (ret) {
Signature · 6 lines
2.32.0

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Alvaro Karsz

The buffer size and the size passed to snprintf don't match, causing clang warnings.

This patch increases a little bit the size of the buffer, and uses sizeof() to get the buffer size.

Quoted 7 lines

This patch should be applied on top of the following patch:

virtio: vdpa: new SolidNET DPU driver,
by Alvaro Karsz [email protected]

Thanks for the fix!

Quoted 42 lines
---
 drivers/vdpa/solidrun/snet_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/solidrun/snet_main.c +4 -5
index d438a89b359..9ceacf96de0 100644
@@ -540,7 +540,7 @@ static const struct vdpa_config_ops snet_config_ops = {
 
 static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 {
-       char name[25];
+       char name[50];
        int ret, i, mask = 0;
        /* We don't know which BAR will be used to communicate..
         * We will map every bar with len > 0.
@@ -558,7 +558,7 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
                return -ENODEV;
        }
 
-       snprintf(name, SNET_NAME_SIZE, "psnet[%s]-bars", pci_name(pdev));
+       snprintf(name, sizeof(name), "psnet[%s]-bars", pci_name(pdev));
        ret = pcim_iomap_regions(pdev, mask, name);
        if (ret) {
                SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
@@ -575,10 +575,10 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 
 static int snet_open_vf_bar(struct pci_dev *pdev, struct snet *snet)
 {
-       char name[20];
+       char name[50];
        int ret;
 
-       snprintf(name, SNET_NAME_SIZE, "snet[%s]-bar", pci_name(pdev));
+       snprintf(name, sizeof(name), "snet[%s]-bar", pci_name(pdev));
        /* Request and map BAR */
        ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
        if (ret) {
--

2.32.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
Acked-by on v1 1/1
#2 lore raw
In reply to Alvaro Karsz
Quoted 7 lines · Alvaro Karsz

The buffer size and the size passed to snprintf don't match, causing clang warnings.

This patch increases a little bit the size of the buffer, and uses sizeof() to get the buffer size.

Quoted 7 lines

This patch should be applied on top of the following patch:

virtio: vdpa: new SolidNET DPU driver,
by Alvaro Karsz [email protected]

Thanks

Quoted 40 lines
---
 drivers/vdpa/solidrun/snet_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/solidrun/snet_main.c +4 -5
index d438a89b359..9ceacf96de0 100644
@@ -540,7 +540,7 @@ static const struct vdpa_config_ops snet_config_ops = {
 
 static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 {
-       char name[25];
+       char name[50];
        int ret, i, mask = 0;
        /* We don't know which BAR will be used to communicate..
         * We will map every bar with len > 0.
@@ -558,7 +558,7 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
                return -ENODEV;
        }
 
-       snprintf(name, SNET_NAME_SIZE, "psnet[%s]-bars", pci_name(pdev));
+       snprintf(name, sizeof(name), "psnet[%s]-bars", pci_name(pdev));
        ret = pcim_iomap_regions(pdev, mask, name);
        if (ret) {
                SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
@@ -575,10 +575,10 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
 
 static int snet_open_vf_bar(struct pci_dev *pdev, struct snet *snet)
 {
-       char name[20];
+       char name[50];
        int ret;
 
-       snprintf(name, SNET_NAME_SIZE, "snet[%s]-bar", pci_name(pdev));
+       snprintf(name, sizeof(name), "snet[%s]-bar", pci_name(pdev));
        /* Request and map BAR */
        ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
        if (ret) {
--
Quoted 2 lines

2.32.0

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization