diff mbox series

[rdma-rc] RDMA/cma: Fix truncation compilation warning in make_cma_ports

Message ID a7e3b347ee134167fa6a3787c56ef231a04bc8c2.1694434639.git.leonro@nvidia.com (mailing list archive)
State Accepted
Headers show
Series [rdma-rc] RDMA/cma: Fix truncation compilation warning in make_cma_ports | expand

Commit Message

Leon Romanovsky Sept. 11, 2023, 12:18 p.m. UTC
From: Leon Romanovsky <leonro@nvidia.com>

The following compilation error is false alarm as RDMA devices don't
have such large amount of ports to actually cause to format truncation.

drivers/infiniband/core/cma_configfs.c: In function ‘make_cma_ports’:
drivers/infiniband/core/cma_configfs.c:223:57: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  223 |                 snprintf(port_str, sizeof(port_str), "%u", i + 1);
      |                                                         ^
drivers/infiniband/core/cma_configfs.c:223:17: note: ‘snprintf’ output between 2 and 11 bytes into a destination of size 10
  223 |                 snprintf(port_str, sizeof(port_str), "%u", i + 1);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[5]: *** [scripts/Makefile.build:243: drivers/infiniband/core/cma_configfs.o] Error 1

Fixes: 045959db65c6 ("IB/cma: Add configfs for rdma_cm")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/cma_configfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Leon Romanovsky Sept. 18, 2023, 8:51 a.m. UTC | #1
On Mon, 11 Sep 2023 15:18:06 +0300, Leon Romanovsky wrote:
> The following compilation error is false alarm as RDMA devices don't
> have such large amount of ports to actually cause to format truncation.
> 
> drivers/infiniband/core/cma_configfs.c: In function ‘make_cma_ports’:
> drivers/infiniband/core/cma_configfs.c:223:57: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
>   223 |                 snprintf(port_str, sizeof(port_str), "%u", i + 1);
>       |                                                         ^
> drivers/infiniband/core/cma_configfs.c:223:17: note: ‘snprintf’ output between 2 and 11 bytes into a destination of size 10
>   223 |                 snprintf(port_str, sizeof(port_str), "%u", i + 1);
>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make[5]: *** [scripts/Makefile.build:243: drivers/infiniband/core/cma_configfs.o] Error 1
> 
> [...]

Applied, thanks!

[1/1] RDMA/cma: Fix truncation compilation warning in make_cma_ports
      https://git.kernel.org/rdma/rdma/c/0c6836da373dfb

Best regards,
diff mbox series

Patch

diff --git a/drivers/infiniband/core/cma_configfs.c b/drivers/infiniband/core/cma_configfs.c
index 7b68b3ea979f..f2fb2d8a6597 100644
--- a/drivers/infiniband/core/cma_configfs.c
+++ b/drivers/infiniband/core/cma_configfs.c
@@ -217,7 +217,7 @@  static int make_cma_ports(struct cma_dev_group *cma_dev_group,
 		return -ENOMEM;
 
 	for (i = 0; i < ports_num; i++) {
-		char port_str[10];
+		char port_str[11];
 
 		ports[i].port_num = i + 1;
 		snprintf(port_str, sizeof(port_str), "%u", i + 1);