Skip to contentSkip to conversation

RDMA/rtrs: Use strscpy() to cache the HCA name

PATCH In review Serhat Kumral 4 participants 5 messages Oct 9 – Oct 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/rtrs: Use strscpy() to cache the HCA name

As the comment states, the HCA name is cached for sysfs. Use strscpy() to copy it directly without unnecessary formatting and avoid interpreting format specifiers in the name.

Fixes 6a98d71daea1 ("RDMA/rtrs: client: main functionality")

---
found by smatch:
- drivers/infiniband/ulp/rtrs/rtrs-clt.c:1906 rtrs_rdma_conn_established() warn: call of 'scnprintf' with non-constant format argument

 drivers/infiniband/ulp/rtrs/rtrs-clt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2 -2
index 927e3f30483c..c85e22f670ba 100644
@@ -1918,8 +1918,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con,
 		 * Cache the hca_port and hca_name for sysfs
 		 */
 		clt_path->hca_port = con->c.cm_id->port_num;
-		scnprintf(clt_path->hca_name, sizeof(clt_path->hca_name),
-			  clt_path->s.dev->ib_dev->name);
+		strscpy(clt_path->hca_name, clt_path->s.dev->ib_dev->name,
+			sizeof(clt_path->hca_name));
 		clt_path->s.src_addr = con->c.cm_id->route.addr.src_addr;
 		/* set for_new_clt, to allow future reconnect on any path */
 		clt_path->for_new_clt = 1;
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

As the comment states, the HCA name is cached for sysfs. Use strscpy() to copy it directly without unnecessary formatting and avoid interpreting format specifiers in the name.

Fixes 6a98d71daea1 ("RDMA/rtrs: client: main functionality")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Serhat Kumral
Quoted 18 lines · Serhat Kumral

As the comment states, the HCA name is cached for sysfs. Use strscpy() to copy it directly without unnecessary formatting and avoid interpreting format specifiers in the name.

Fixes 6a98d71daea1 ("RDMA/rtrs: client: main functionality")

---
found by smatch:
- drivers/infiniband/ulp/rtrs/rtrs-clt.c:1906 rtrs_rdma_conn_established() warn: call of 'scnprintf' with non-constant format argument

 drivers/infiniband/ulp/rtrs/rtrs-clt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0 -0
index 927e3f30483c..c85e22f670ba 100644

drivers/infiniband/ulp/rtrs/rtrs-clt.c static int rtrs_rdma_conn_established(struct rtrs_clt_con *con, · line 1922

Quoted 7 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2 -2
@@ -1918,8 +1918,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con,
 		 * Cache the hca_port and hca_name for sysfs
 		 */
 		clt_path->hca_port = con->c.cm_id->port_num;
-		scnprintf(clt_path->hca_name, sizeof(clt_path->hca_name),
-			  clt_path->s.dev->ib_dev->name);
+		strscpy(clt_path->hca_name, clt_path->s.dev->ib_dev->name,
+			sizeof(clt_path->hca_name));

Haris, Jinpu

These names shouldn't be cached.

Thanks

Quoted 6 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0 -0
 		clt_path->s.src_addr = con->c.cm_id->route.addr.src_addr;
 		/* set for_new_clt, to allow future reconnect on any path */
 		clt_path->for_new_clt = 1;
Signature · 1 line
2.53.0
#3 lore raw
Quoted 30 lines · Leon Romanovsky
Quoted 18 lines · Serhat Kumral

As the comment states, the HCA name is cached for sysfs. Use strscpy() to copy it directly without unnecessary formatting and avoid interpreting format specifiers in the name.

Fixes 6a98d71daea1 ("RDMA/rtrs: client: main functionality")

---
found by smatch:
- drivers/infiniband/ulp/rtrs/rtrs-clt.c:1906 rtrs_rdma_conn_established() warn: call of 'scnprintf' with non-constant format argument

 drivers/infiniband/ulp/rtrs/rtrs-clt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0 -0
index 927e3f30483c..c85e22f670ba 100644

drivers/infiniband/ulp/rtrs/rtrs-clt.c static int rtrs_rdma_conn_established(struct rtrs_clt_con *con, · line 1922

Quoted 7 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2 -2
@@ -1918,8 +1918,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con,
               * Cache the hca_port and hca_name for sysfs
               */
              clt_path->hca_port = con->c.cm_id->port_num;
-             scnprintf(clt_path->hca_name, sizeof(clt_path->hca_name),
-                       clt_path->s.dev->ib_dev->name);
+             strscpy(clt_path->hca_name, clt_path->s.dev->ib_dev->name,
+                     sizeof(clt_path->hca_name));

Haris, Jinpu

Quoted 1 line

These names shouldn't be cached.

Leon, you mean the hostname could change at runtime?

Quoted 9 lines

Thanks

Quoted 6 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0 -1
              clt_path->s.src_addr = con->c.cm_id->route.addr.src_addr;
              /* set for_new_clt, to allow future reconnect on any path */
              clt_path->for_new_clt = 1;
--

2.53.0

#4 lore raw
Quoted 31 lines · Jinpu Wang
Quoted 30 lines · Leon Romanovsky
Quoted 18 lines · Serhat Kumral

As the comment states, the HCA name is cached for sysfs. Use strscpy() to copy it directly without unnecessary formatting and avoid interpreting format specifiers in the name.

Fixes 6a98d71daea1 ("RDMA/rtrs: client: main functionality")

---
found by smatch:
- drivers/infiniband/ulp/rtrs/rtrs-clt.c:1906 rtrs_rdma_conn_established() warn: call of 'scnprintf' with non-constant format argument

 drivers/infiniband/ulp/rtrs/rtrs-clt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0 -0
index 927e3f30483c..c85e22f670ba 100644

drivers/infiniband/ulp/rtrs/rtrs-clt.c static int rtrs_rdma_conn_established(struct rtrs_clt_con *con, · line 1922

Quoted 7 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2 -2
@@ -1918,8 +1918,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con,
               * Cache the hca_port and hca_name for sysfs
               */
              clt_path->hca_port = con->c.cm_id->port_num;
-             scnprintf(clt_path->hca_name, sizeof(clt_path->hca_name),
-                       clt_path->s.dev->ib_dev->name);
+             strscpy(clt_path->hca_name, clt_path->s.dev->ib_dev->name,
+                     sizeof(clt_path->hca_name));

Haris, Jinpu

Quoted 3 lines
Quoted 1 line

These names shouldn't be cached.

Leon, you mean the hostname could change at runtime?

Yes, users can change the hostname at any time. However, this code caches the ib_device name, which can also change at any time.

Thanks

Quoted 10 lines
Quoted 10 lines

Thanks

Quoted 6 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0 -1
              clt_path->s.src_addr = con->c.cm_id->route.addr.src_addr;
              /* set for_new_clt, to allow future reconnect on any path */
              clt_path->for_new_clt = 1;
--

2.53.0