Skip to contentSkip to conversation

virtio-net: don't allocate control_buf if not supported

PATCH In review Max Gurtovoy 4 participants 4 messages May 2, 2021 – May 6, 2021

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

PATCH 1/1 virtio-net: don't allocate control_buf if not supported

Not all virtio_net devices support the ctrl queue feature. Thus, there is no need to allocate unused resources.

---
 drivers/net/virtio_net.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +7 -3
index 7fda2ae4c40f..9b6a4a875c55 100644
@@ -2870,9 +2870,13 @@ static int virtnet_alloc_queues(struct virtnet_info *vi)
 {
 	int i;
 
-	vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
-	if (!vi->ctrl)
-		goto err_ctrl;
+	if (vi->has_cvq) {
+		vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
+		if (!vi->ctrl)
+			goto err_ctrl;
+	} else {
+		vi->ctrl = NULL;
+	}
 	vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL);
 	if (!vi->sq)
 		goto err_sq;
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Max Gurtovoy

Not all virtio_net devices support the ctrl queue feature. Thus, there is no need to allocate unused resources.

Quoted 30 lines
---
 drivers/net/virtio_net.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +7 -3
index 7fda2ae4c40f..9b6a4a875c55 100644
@@ -2870,9 +2870,13 @@ static int virtnet_alloc_queues(struct virtnet_info
 *vi)
 {
 	int i;
 
-	vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
-	if (!vi->ctrl)
-		goto err_ctrl;
+	if (vi->has_cvq) {
+		vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
+		if (!vi->ctrl)
+			goto err_ctrl;
+	} else {
+		vi->ctrl = NULL;
+	}
 	vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL);
 	if (!vi->sq)

goto err_sq;
--
2.18.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Max Gurtovoy
Quoted 19 lines

Not all virtio_net devices support the ctrl queue feature. Thus, there is no need to allocate unused resources.

---
 drivers/net/virtio_net.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +0 -3
index 7fda2ae4c40f..9b6a4a875c55 100644
@@ -2870,9 +2870,13 @@ static int virtnet_alloc_queues(struct virtnet_info *vi)
 {
        int i;
 
-       vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
-       if (!vi->ctrl)
-               goto err_ctrl;

drivers/net/virtio_net.c static int virtnet_alloc_queues(struct virtnet_info *vi) · line 2882

Quoted 10 lines
drivers/net/virtio_net.c +7 -0
+       if (vi->has_cvq) {
+               vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
+               if (!vi->ctrl)
+                       goto err_ctrl;
+       } else {
+               vi->ctrl = NULL;
+       }
        vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL);
        if (!vi->sq)
                goto err_sq;
Acked-by on v1 1/1
#3 lore raw
In reply to Max Gurtovoy
Quoted 4 lines · Max Gurtovoy

Not all virtio_net devices support the ctrl queue feature. Thus, there is no need to allocate unused resources.

Quoted 25 lines
---
  drivers/net/virtio_net.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +7 -3
index 7fda2ae4c40f..9b6a4a875c55 100644
@@ -2870,9 +2870,13 @@ static int virtnet_alloc_queues(struct virtnet_info *vi)
  {
  	int i;
 
-	vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
-	if (!vi->ctrl)
-		goto err_ctrl;
+	if (vi->has_cvq) {
+		vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
+		if (!vi->ctrl)
+			goto err_ctrl;
+	} else {
+		vi->ctrl = NULL;
+	}
  	vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL);
  	if (!vi->sq)
  		goto err_sq;