Skip to contentSkip to conversation

xen-netback: use kstrdup() in connect_data_rings()

PATCH In review Denis Efremov 2 participants 2 messages Jun 3, 2020

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

PATCH 1/1 xen-netback: use kstrdup() in connect_data_rings()

Use kstrdup() instead of opencoded alloc and copy. kzalloc() is excessive here.

---
 drivers/net/xen-netback/xenbus.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/xen-netback/xenbus.c +1 -2
index 286054b60d47..69352154a51b 100644
@@ -839,13 +839,12 @@ static int connect_data_rings(struct backend_info *be,
 	 * queue-N.
 	 */
 	if (num_queues == 1) {
-		xspath = kzalloc(strlen(dev->otherend) + 1, GFP_KERNEL);
+		xspath = kstrdup(dev->otherend, GFP_KERNEL);
 		if (!xspath) {
 			xenbus_dev_fatal(dev, -ENOMEM,
 					 "reading ring references");
 			return -ENOMEM;
 		}
-		strcpy(xspath, dev->otherend);
 	} else {
 		xspathsize = strlen(dev->otherend) + xenstore_path_ext_size;
 		xspath = kzalloc(xspathsize, GFP_KERNEL);
Signature · 1 line
2.26.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Denis Efremov

Use kstrdup() instead of opencoded alloc and copy. kzalloc() is excessive here.

Quoted 26 lines
---
 drivers/net/xen-netback/xenbus.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/xen-netback/xenbus.c +1 -2
index 286054b60d47..69352154a51b 100644
@@ -839,13 +839,12 @@ static int connect_data_rings(struct backend_info *be,
 	 * queue-N.
 	 */
 	if (num_queues == 1) {
-		xspath = kzalloc(strlen(dev->otherend) + 1, GFP_KERNEL);
+		xspath = kstrdup(dev->otherend, GFP_KERNEL);
 		if (!xspath) {
 			xenbus_dev_fatal(dev, -ENOMEM,
 					 "reading ring references");
 			return -ENOMEM;
 		}
-		strcpy(xspath, dev->otherend);
 	} else {
 		xspathsize = strlen(dev->otherend) + xenstore_path_ext_size;
 		xspath = kzalloc(xspathsize, GFP_KERNEL);
Signature · 1 line
2.26.2