xen-netback: correctly check failed allocation
Subsystems (3)
PATCH 1/1 xen-netback: correctly check failed allocation
Since vzalloc can be failed in memory pressure,
writes -ENOMEM to xenstore to indicate error.
--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/xen-netback/xenbus.c +6 -0
@@ -788,6 +788,12 @@ 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
I changed patch with valid format.
Quoted 14 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/xen-netback/xenbus.c +0
-0
drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;
I didn't use goto err, because another error handling is not required
Quoted 9 lines
drivers/net/xen-netback/xenbus.c +2
-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
Quoted 12 lines · Insu Yun
I changed patch with valid format.
Quoted 8 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)
Quoted 17 lines
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +0
-0drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;I didn't use goto err, because another error handling is not required
It's recommended in kernel coding style to use "goto" style error handling. I personally prefer that to arbitrary return in function body, too.
It's not a matter of whether another error handling is required or not, it's about cleaner code that is easy to reason about and consistent coding style.
The existing code is not perfect, but that doesn't mean we should follow bad example.
Wei.
Quoted 15 lines
Quoted 10 lines
drivers/net/xen-netback/xenbus.c +2
-1+ } + be->vif->num_queues = requested_num_queues; be->vif->stalled_queues = requested_num_queues; --1.9.1
Signature · 2 lines
Regards Insu Yun
Wei Liu
Acked-byQuoted 35 lines · Wei Liu
Quoted 12 lines · Insu Yun
I changed patch with valid format.
Quoted 8 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 17 lines
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +0
-0drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;I didn't use goto err, because another error handling is not required
It's recommended in kernel coding style to use "goto" style error handling. I personally prefer that to arbitrary return in function body, too.
Quoted 6 lines
It's not a matter of whether another error handling is required or not, it's about cleaner code that is easy to reason about and consistent coding style.
The existing code is not perfect, but that doesn't mean we should follow bad example.
And to be clear, I don't want to block this patch just because of this coding style thing. It's still an improvement and fix a real problem. So:
Wei Liu
Acked-byQuoted 35 lines · Wei Liu
Quoted 12 lines · Insu Yun
I changed patch with valid format.
Quoted 8 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 17 lines
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +0
-0drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;I didn't use goto err, because another error handling is not required
It's recommended in kernel coding style to use "goto" style error handling. I personally prefer that to arbitrary return in function body, too.
Quoted 6 lines
It's not a matter of whether another error handling is required or not, it's about cleaner code that is easy to reason about and consistent coding style.
The existing code is not perfect, but that doesn't mean we should follow bad example.
And to be clear, I don't want to block this patch just because of this coding style thing. It's still an improvement and fix a real problem. So:
Quoted 31 lines · Wei Liu
Quoted 12 lines · Insu Yun
I changed patch with valid format.
Quoted 8 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 17 lines
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +0
-0drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;I didn't use goto err, because another error handling is not required
Quoted 7 lines
It's recommended in kernel coding style to use "goto" style error handling. I personally prefer that to arbitrary return in function body, too.
It's not a matter of whether another error handling is required or not, it's about cleaner code that is easy to reason about and consistent coding style.
Using xenbus_dev_fatal(); return; throughout would be consistent and easy to reason about.
Also, the goto err path should raise a fatal error (instead of disconnecting). I also note that failures in the xen_net_read_rate(), xen_register_watchers() and read_xenbus_vif_flags() are also not handled.
David
For me, it seems more consistent using xen_bus_dev_fatal(); return; Because other codes also use them.
If you want to use goto, then feel free to make a patch for this issue.
Quoted 49 lines · David Vrabel
Quoted 31 lines · Wei Liu
Quoted 12 lines · Insu Yun
I changed patch with valid format.
Quoted 8 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 17 lines
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +0
-0drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;I didn't use goto err, because another error handling is not required
Quoted 7 lines
It's recommended in kernel coding style to use "goto" style error handling. I personally prefer that to arbitrary return in function body, too.
It's not a matter of whether another error handling is required or not, it's about cleaner code that is easy to reason about and consistent coding style.
Using
xenbus_dev_fatal(); return; throughout would be consistent and easy to reason about.Also, the goto err path should raise a fatal error (instead of disconnecting). I also note that failures in the
xen_net_read_rate(),xen_register_watchers()andread_xenbus_vif_flags()are also not handled.David
Signature · 2 lines
Regards Insu Yun
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 31 lines · Wei Liu
Quoted 12 lines · Insu Yun
I changed patch with valid format.
Quoted 8 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 17 lines
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +0
-0drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;I didn't use goto err, because another error handling is not required
Quoted 7 lines
It's recommended in kernel coding style to use "goto" style error handling. I personally prefer that to arbitrary return in function body, too.
It's not a matter of whether another error handling is required or not, it's about cleaner code that is easy to reason about and consistent coding style.
Using xenbus_dev_fatal(); return; throughout would be consistent and easy to reason about.
Also, the goto err path should raise a fatal error (instead of disconnecting). I also note that failures in the xen_net_read_rate(), xen_register_watchers() and read_xenbus_vif_flags() are also not handled.
David
Quoted 12 lines · Insu Yun
I changed patch with valid format.
Quoted 8 lines · Insu Yun
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>--- drivers/net/xen-netback/xenbus.c | 6 ++++++ 1 file changed, 6 insertions(+)
Quoted 17 lines
Quoted 6 lines
drivers/net/xen-netback/xenbus.c +0
-0drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 795
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4
-0@@ -788,6 +788,12 @@ 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 ;I didn't use goto err, because another error handling is not required
It's recommended in kernel coding style to use "goto" style error handling. I personally prefer that to arbitrary return in function body, too.
It's not a matter of whether another error handling is required or not, it's about cleaner code that is easy to reason about and consistent coding style.
The existing code is not perfect, but that doesn't mean we should follow bad example.
Wei.
Quoted 15 lines
Quoted 10 lines
drivers/net/xen-netback/xenbus.c +2
-1+ } + be->vif->num_queues = requested_num_queues; be->vif->stalled_queues = requested_num_queues; --1.9.1
Signature · 2 lines
Regards Insu Yun
From: Insu Yun <[email protected]>
Date: Thu, 15 Oct 2015 18:02:28 +0000
Quoted 4 lines
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>
Applied.
From: Insu Yun <[email protected]>
Date: Thu, 15 Oct 2015 18:02:28 +0000
Quoted 4 lines
Since vzalloc can be failed in memory pressure,
writes-ENOMEMto xenstore to indicate error.Signed-off-by Insu Yun <[email protected]>
Applied.