Alvaro Karsz
2022-Dec-21 07:20 UTC
[PATCH] 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 alvaro.karsz at solid-run.com Reported-by: Nathan Chancellor <nathan at kernel.org> Signed-off-by: Alvaro Karsz <alvaro.karsz at solid-run.com> --- drivers/vdpa/solidrun/snet_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/vdpa/solidrun/snet_main.c b/drivers/vdpa/solidrun/snet_main.c index d438a89b359..9ceacf96de0 100644 --- a/drivers/vdpa/solidrun/snet_main.c +++ b/drivers/vdpa/solidrun/snet_main.c @@ -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
Nick Desaulniers
2022-Dec-21 20:03 UTC
[PATCH] virtio: vdpa: fix snprintf size argument in snet_vdpa driver
On Tue, Dec 20, 2022 at 11:20 PM Alvaro Karsz <alvaro.karsz at solid-run.com> wrote:> > 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 alvaro.karsz at solid-run.com > > Reported-by: Nathan Chancellor <nathan at kernel.org> > Signed-off-by: Alvaro Karsz <alvaro.karsz at solid-run.com>Thanks for the fix! Reviewed-by: Nick Desaulniers <ndesaulniers at google.com>> --- > drivers/vdpa/solidrun/snet_main.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/vdpa/solidrun/snet_main.c b/drivers/vdpa/solidrun/snet_main.c > index d438a89b359..9ceacf96de0 100644 > --- a/drivers/vdpa/solidrun/snet_main.c > +++ b/drivers/vdpa/solidrun/snet_main.c > @@ -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 >-- Thanks, ~Nick Desaulniers
Jason Wang
2022-Dec-22 03:53 UTC
[PATCH] virtio: vdpa: fix snprintf size argument in snet_vdpa driver
On Wed, Dec 21, 2022 at 3:20 PM Alvaro Karsz <alvaro.karsz at solid-run.com> wrote:> > 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 alvaro.karsz at solid-run.com > > Reported-by: Nathan Chancellor <nathan at kernel.org> > Signed-off-by: Alvaro Karsz <alvaro.karsz at solid-run.com>Acked-by: Jason Wang <jasowang at redhat.com> Thanks> --- > drivers/vdpa/solidrun/snet_main.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/vdpa/solidrun/snet_main.c b/drivers/vdpa/solidrun/snet_main.c > index d438a89b359..9ceacf96de0 100644 > --- a/drivers/vdpa/solidrun/snet_main.c > +++ b/drivers/vdpa/solidrun/snet_main.c > @@ -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 >