Skip to contentSkip to conversation

xen-netfront: update num_queues to real created

PATCH In review Joe Jin 3 participants 5 messages Oct 15, 2015 – Oct 16, 2015

Subsystems (4)
lore
Share & tools
lore

Joe Jin

author
#0 lore raw

PATCH 1/1 xen-netfront: update num_queues to real created

Sometimes xennet_create_queues() may failed to created all requested queues, we need to update num_queues to real created to avoid NULL pointer dereference.

Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/net/xen-netfront.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/xen-netfront.c +6 -3
index f821a97..d580aec 100644
@@ -1746,7 +1746,7 @@ static int xennet_create_queues(struct netfront_info *info,
 		dev_err(&info->netdev->dev, "no queues\n");
 		return -EINVAL;
 	}
-	return 0;
+	return num_queues;
 }
 
 /* Common code used when first setting up, and when resuming. */
@@ -1788,9 +1788,12 @@ static int talk_to_netback(struct xenbus_device *dev,
 	if (info->queues)
 		xennet_destroy_queues(info);
 
-	err = xennet_create_queues(info, num_queues);
-	if (err < 0)
+	/* Update queues number to real created */
+	num_queues = xennet_create_queues(info, num_queues);
+	if (num_queues < 0) {
+		err = num_queues;
 		goto destroy_ring;
+	}
 
 	/* Create shared ring, alloc event channel -- for each queue */
 	for (i = 0; i < num_queues; ++i) {
Signature · 1 line
1.7.1
#1 lore raw

CC David and Boris (Konrad was already a recipient).

Quoted 42 lines · Joe Jin

Sometimes xennet_create_queues() may failed to created all requested queues, we need to update num_queues to real created to avoid NULL pointer dereference.

Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/net/xen-netfront.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/xen-netfront.c +6 -3
index f821a97..d580aec 100644
@@ -1746,7 +1746,7 @@ static int xennet_create_queues(struct netfront_info *info,
 		dev_err(&info->netdev->dev, "no queues\n");
 		return -EINVAL;
 	}
-	return 0;
+	return num_queues;
 }
 
 /* Common code used when first setting up, and when resuming. */
@@ -1788,9 +1788,12 @@ static int talk_to_netback(struct xenbus_device *dev,
 	if (info->queues)
 		xennet_destroy_queues(info);
 
-	err = xennet_create_queues(info, num_queues);
-	if (err < 0)
+	/* Update queues number to real created */
+	num_queues = xennet_create_queues(info, num_queues);
+	if (num_queues < 0) {
+		err = num_queues;
 		goto destroy_ring;
+	}
 
 	/* Create shared ring, alloc event channel -- for each queue */
 	for (i = 0; i < num_queues; ++i) {
Signature · 1 line
1.7.1
#2 lore raw
Quoted 32 lines · Wei Liu

CC David and Boris (Konrad was already a recipient).

Quoted 29 lines · Joe Jin

Sometimes xennet_create_queues() may failed to created all requested queues, we need to update num_queues to real created to avoid NULL pointer dereference.

Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David S. Miller <[email protected]>
---
  drivers/net/xen-netfront.c |    9 ++++++---
  1 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/xen-netfront.c +1 -1
index f821a97..d580aec 100644
@@ -1746,7 +1746,7 @@ static int xennet_create_queues(struct netfront_info *info,
  		dev_err(&info->netdev->dev, "no queues\n");
  		return -EINVAL;
  	}
-	return 0;
+	return num_queues;
  }
 
  /* Common code used when first setting up, and when resuming. */
@@ -1788,9 +1788,12 @@ static int talk_to_netback(struct xenbus_device *dev,
  	if (info->queues)
  		xennet_destroy_queues(info);
 
Quoted 4 lines

drivers/net/xen-netfront.c static int talk_to_netback(struct xenbus_device *dev, · line 1792

Quoted 4 lines
drivers/net/xen-netfront.c +2 -2
-	err = xennet_create_queues(info, num_queues);
-	if (err < 0)
+	/* Update queues number to real created */
+	num_queues = xennet_create_queues(info, num_queues);

I think it would be more natural to have

                    err = xennet_create_queues(info, &num_queues);

-boris

Quoted 9 lines
Quoted 9 lines
drivers/net/xen-netfront.c +3 -0
+	if (num_queues < 0) {
+		err = num_queues;
  		goto destroy_ring;
+	}
 
  	/* Create shared ring, alloc event channel -- for each queue */
  	for (i = 0; i < num_queues; ++i) {
Signature · 1 line
1.7.1
#3 lore raw
In reply to Wei Liu
Quoted 32 lines · Wei Liu

CC David and Boris (Konrad was already a recipient).

Quoted 29 lines · Joe Jin

Sometimes xennet_create_queues() may failed to created all requested queues, we need to update num_queues to real created to avoid NULL pointer dereference.

Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David S. Miller <[email protected]>
---
  drivers/net/xen-netfront.c |    9 ++++++---
  1 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/xen-netfront.c +1 -1
index f821a97..d580aec 100644
@@ -1746,7 +1746,7 @@ static int xennet_create_queues(struct netfront_info *info,
  		dev_err(&info->netdev->dev, "no queues\n");
  		return -EINVAL;
  	}
-	return 0;
+	return num_queues;
  }
 
  /* Common code used when first setting up, and when resuming. */
@@ -1788,9 +1788,12 @@ static int talk_to_netback(struct xenbus_device *dev,
  	if (info->queues)
  		xennet_destroy_queues(info);
 
Quoted 4 lines

drivers/net/xen-netfront.c static int talk_to_netback(struct xenbus_device *dev, · line 1792

Quoted 4 lines
drivers/net/xen-netfront.c +2 -2
-	err = xennet_create_queues(info, num_queues);
-	if (err < 0)
+	/* Update queues number to real created */
+	num_queues = xennet_create_queues(info, num_queues);

I think it would be more natural to have

                    err = xennet_create_queues(info, &num_queues);

-boris

Quoted 9 lines
Quoted 9 lines
drivers/net/xen-netfront.c +3 -0
+	if (num_queues < 0) {
+		err = num_queues;
  		goto destroy_ring;
+	}
 
  	/* Create shared ring, alloc event channel -- for each queue */
  	for (i = 0; i < num_queues; ++i) {
Signature · 1 line
1.7.1
#4 lore raw
In reply to Joe Jin

CC David and Boris (Konrad was already a recipient).

Quoted 42 lines · Joe Jin

Sometimes xennet_create_queues() may failed to created all requested queues, we need to update num_queues to real created to avoid NULL pointer dereference.

Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/net/xen-netfront.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/xen-netfront.c +6 -3
index f821a97..d580aec 100644
@@ -1746,7 +1746,7 @@ static int xennet_create_queues(struct netfront_info *info,
 		dev_err(&info->netdev->dev, "no queues\n");
 		return -EINVAL;
 	}
-	return 0;
+	return num_queues;
 }
 
 /* Common code used when first setting up, and when resuming. */
@@ -1788,9 +1788,12 @@ static int talk_to_netback(struct xenbus_device *dev,
 	if (info->queues)
 		xennet_destroy_queues(info);
 
-	err = xennet_create_queues(info, num_queues);
-	if (err < 0)
+	/* Update queues number to real created */
+	num_queues = xennet_create_queues(info, num_queues);
+	if (num_queues < 0) {
+		err = num_queues;
 		goto destroy_ring;
+	}
 
 	/* Create shared ring, alloc event channel -- for each queue */
 	for (i = 0; i < num_queues; ++i) {
Signature · 1 line
1.7.1