2020-06-03 15:29:29

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: [PATCH] xen-netback: use kstrdup() in connect_data_rings()

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

Signed-off-by: Denis Efremov <[email protected]>
---
drivers/net/xen-netback/xenbus.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index 286054b60d47..69352154a51b 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -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);
--
2.26.2


2020-06-03 15:55:43

by Wei Liu

[permalink] [raw]
Subject: Re: [PATCH] xen-netback: use kstrdup() in connect_data_rings()

On Wed, Jun 03, 2020 at 06:26:43PM +0300, Denis Efremov wrote:
> Use kstrdup() instead of opencoded alloc and copy. kzalloc() is
> excessive here.
>
> Signed-off-by: Denis Efremov <[email protected]>

Acked-by: Wei Liu <[email protected]>

> ---
> drivers/net/xen-netback/xenbus.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
> index 286054b60d47..69352154a51b 100644
> --- a/drivers/net/xen-netback/xenbus.c
> +++ b/drivers/net/xen-netback/xenbus.c
> @@ -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);
> --
> 2.26.2
>