Skip to contentSkip to conversation

xen-netback: corretly check failed allocation

PATCH In review Insu Yun 4 participants 8 messages Oct 15, 2015 – Oct 16, 2015

Subsystems (3)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 xen-netback: corretly check failed allocation

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/xen-netback/xenbus.c +5 -0
index 929a6e7..e288246 100644
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
 	/* Use the number of queues requested by the frontend */
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }
+
 	be->vif->num_queues = requested_num_queues;
 	be->vif->stalled_queues = requested_num_queues;
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 14 lines · Insu Yun

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/xen renamed from drivers/net/xen-netback/xenbus.c +0 -1
-netback/xenbus.c

index 929a6e7..e288246 100644

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 794

Quoted 7 lines
drivers/net/xen-netback/xenbus.c +4 -0
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
 	/* Use the number of queues requested by the frontend */
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }

Please fix the coding style, perhaps using checkpatch.pl or by observing the surrounding code.

Ian.

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +1 -0
+
 	be->vif->num_queues = requested_num_queues;
 	be->vif->stalled_queues = requested_num_queues;
 
#2 lore raw
In reply to Insu Yun
Quoted 14 lines · Insu Yun

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/xen renamed from drivers/net/xen-netback/xenbus.c +0 -1
-netback/xenbus.c

index 929a6e7..e288246 100644

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 794

Quoted 7 lines
drivers/net/xen-netback/xenbus.c +4 -0
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
 	/* Use the number of queues requested by the frontend */
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }

Please fix the coding style, perhaps using checkpatch.pl or by observing the surrounding code.

Ian.

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +1 -0
+
 	be->vif->num_queues = requested_num_queues;
 	be->vif->stalled_queues = requested_num_queues;
 
#3 lore raw
In reply to Insu Yun
Quoted 2 lines · Insu Yun

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

This function doesn't return ENOMEM, instead it writes to xenstore to indicate error. The commit log needs to be updated.

Quoted 11 lines
---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/xen-netback/xenbus.c +0 -0
index 929a6e7..e288246 100644

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795

Quoted 8 lines
drivers/net/xen-netback/xenbus.c +5 -0
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
 	/* Use the number of queues requested by the frontend */
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }
+

The indentation is wrong. Please configure your email client properly.

And please use "goto err" for error handling -- yes, I understand there is existing code that returns directly but IMHO that should be fixed too.

We.

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -0
 	be->vif->num_queues = requested_num_queues;
 	be->vif->stalled_queues = requested_num_queues;
 
Signature · 1 line
1.9.1
author
#4 lore raw

Sorry for wrong format, I forgot to change my configuration.

Quoted 8 lines · Wei Liu
Quoted 2 lines · Insu Yun

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

This function doesn't return ENOMEM, instead it writes to xenstore to indicate error. The commit log needs to be updated.

Good. I will update it.

Quoted 23 lines

Review

Quoted 7 lines
---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/net/xen-netback/xenbus.c

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795

Quoted 12 lines

index 929a6e7..e288246 100644

drivers/net/xen-netback/xenbus.c +5 -0
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
      /* Use the number of queues requested by the frontend */
      be->vif->queues = vzalloc(requested_num_queues *
                                sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }
+

The indentation is wrong. Please configure your email client properly.

Quoted 5 lines

And please use "goto err" for error handling -- yes, I understand there is existing code that returns directly but IMHO that should be fixed too.

Ok. Actually I made a code referring the existing code.

Quoted 8 lines

We.

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -1
      be->vif->num_queues = requested_num_queues;
      be->vif->stalled_queues = requested_num_queues;
 
--

1.9.1

Signature · 2 lines
Regards
Insu Yun

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
In reply to Insu Yun
Quoted 2 lines · Insu Yun

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

This function doesn't return ENOMEM, instead it writes to xenstore to indicate error. The commit log needs to be updated.

Quoted 11 lines
---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/xen-netback/xenbus.c +0 -0
index 929a6e7..e288246 100644

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795

Quoted 8 lines
drivers/net/xen-netback/xenbus.c +5 -0
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
 	/* Use the number of queues requested by the frontend */
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }
+

The indentation is wrong. Please configure your email client properly.

And please use "goto err" for error handling -- yes, I understand there is existing code that returns directly but IMHO that should be fixed too.

We.

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -0
 	be->vif->num_queues = requested_num_queues;
 	be->vif->stalled_queues = requested_num_queues;
 
Signature · 1 line
1.9.1
maintainer
#6 lore raw
In reply to Insu Yun

From: Insu Yun <[email protected]>
Date: Thu, 15 Oct 2015 12:26:16 -0400

Quoted 13 lines

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/xen-netback/xenbus.c +0 -0
index 929a6e7..e288246 100644

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 794

Quoted 7 lines
drivers/net/xen-netback/xenbus.c +4 -0
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
 	/* Use the number of queues requested by the frontend */
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }

This is definitely not indented correctly.

maintainer
#7 lore raw
In reply to Insu Yun

From: Insu Yun <[email protected]>
Date: Thu, 15 Oct 2015 12:26:16 -0400

Quoted 13 lines

Since vzalloc can be failed in memory pressure,
return value should be checked and return ENOMEM.

---
 drivers/net/xen-netback/xenbus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/xen-netback/xenbus.c +0 -0
index 929a6e7..e288246 100644

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 794

Quoted 7 lines
drivers/net/xen-netback/xenbus.c +4 -0
@@ -788,6 +788,11 @@ static void connect(struct backend_info *be)
 	/* Use the number of queues requested by the frontend */
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
+  if (!be->vif->queues)  {
+    xenbus_dev_fatal(dev, -ENOMEM, "allocating queues");
+    return;
+  }

This is definitely not indented correctly.