Skip to contentSkip to conversation

Fix assignment of devid value returned from libxl__device_nextid

PATCH In review Jim Fehlig 3 participants 6 messages Jun 25, 2013 – Jun 26, 2013

lore
Share & tools
lore

Jim Fehlig

author
#0 lore raw

PATCH 1/1 Fix assignment of devid value returned from libxl__device_nextid

Commit 5420f265 has some misplaced parenthesis that caused devid to be assigned 1 or 0 based on checking return value of libxl__device_nextid < 0, e.g.

devid = libxl__device_nextid(...) < 0

This works when only one instance of a given device type exists, but subsequent devices of the same type will also have a devid = 1 if libxl__device_nextid succeeds. Fix by checking the value assigned to devid, e.g.

(devid = libxl__device_nextid(...)) < 0

---
 tools/libxl/libxl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl.c +4 -4
index 0612d85..1bbb990 100644
@@ -1781,7 +1781,7 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
     back = flexarray_make(gc, 16, 1);
 
     if (vtpm->devid == -1) {
-        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm") < 0)) {
+        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -2877,7 +2877,7 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
     back = flexarray_make(gc, 18, 1);
 
     if (nic->devid == -1) {
-        if ((nic->devid = libxl__device_nextid(gc, domid, "vif") < 0)) {
+        if ((nic->devid = libxl__device_nextid(gc, domid, "vif")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3258,7 +3258,7 @@ int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
     back = flexarray_make(gc, 16, 1);
 
     if (vkb->devid == -1) {
-        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb") < 0)) {
+        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3359,7 +3359,7 @@ int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
     back = flexarray_make(gc, 16, 1);
 
     if (vfb->devid == -1) {
-        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb") < 0)) {
+        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
Signature · 1 line
1.8.0.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jim Fehlig

Commit 5420f265 has some misplaced parenthesis that caused devid to be assigned 1 or 0 based on checking return value of libxl__device_nextid < 0, e.g.

devid = libxl__device_nextid(...) < 0

Quoted 8 lines

This works when only one instance of a given device type exists, but subsequent devices of the same type will also have a devid = 1 if libxl__device_nextid succeeds. Fix by checking the value assigned to devid, e.g.

(devid = libxl__device_nextid(...)) < 0

Both for 4.3, and as a patch in general:

Quoted 52 lines
---
 tools/libxl/libxl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl.c +4 -5
index 0612d85..1bbb990 100644
@@ -1781,7 +1781,7 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
     back = flexarray_make(gc, 16, 1);
 
     if (vtpm->devid == -1) {
-        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm") < 0)) {
+        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -2877,7 +2877,7 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
     back = flexarray_make(gc, 18, 1);
 
     if (nic->devid == -1) {
-        if ((nic->devid = libxl__device_nextid(gc, domid, "vif") < 0)) {
+        if ((nic->devid = libxl__device_nextid(gc, domid, "vif")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3258,7 +3258,7 @@ int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
     back = flexarray_make(gc, 16, 1);
 
     if (vkb->devid == -1) {
-        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb") < 0)) {
+        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3359,7 +3359,7 @@ int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
     back = flexarray_make(gc, 16, 1);
 
     if (vfb->devid == -1) {
-        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb") < 0)) {
+        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
--

1.8.0.1

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

#2 lore raw
Quoted 5 lines · George Dunlap
Quoted 4 lines · Jim Fehlig

Commit 5420f265 has some misplaced parenthesis that caused devid to be assigned 1 or 0 based on checking return value of libxl__device_nextid < 0, e.g.

Quoted 8 lines
Quoted 8 lines

devid = libxl__device_nextid(...) < 0

This works when only one instance of a given device type exists, but subsequent devices of the same type will also have a devid = 1 if libxl__device_nextid succeeds. Fix by checking the value assigned to devid, e.g.

(devid = libxl__device_nextid(...)) < 0

This is why I hate combined assignment & logic!

Quoted 5 lines
Quoted 1 line

Both for 4.3, and as a patch in general:

Acked + applied, thanks.

author
#3 lore raw
In reply to George Dunlap
Quoted 13 lines · George Dunlap
Quoted 11 lines · Jim Fehlig

Commit 5420f265 has some misplaced parenthesis that caused devid to be assigned 1 or 0 based on checking return value of libxl__device_nextid < 0, e.g.

devid = libxl__device_nextid(...) < 0

This works when only one instance of a given device type exists, but subsequent devices of the same type will also have a devid = 1 if libxl__device_nextid succeeds. Fix by checking the value assigned to devid, e.g.

Quoted 7 lines
Quoted 4 lines

(devid = libxl__device_nextid(...)) < 0

Both for 4.3, and as a patch in general:

Noticed I have the commit msg a tad bit wrong. It should read "...devices of the same type will also have a devid = 0 if..." since libxl__device_nextid(...) < 0 is false when libxl__device_nextid() succeeds. Also, perhaps I should add that xl is not affected since it supplies devid, but apps such as libvirt that allow libxl to fill in devid are certainly affected when there is more than 1 of the same device type. Should I submit a V2 with an improved commit msg?

Regards,
Jim

Quoted 63 lines
Quoted 48 lines
---
 tools/libxl/libxl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl.c +4 -5
index 0612d85..1bbb990 100644
@@ -1781,7 +1781,7 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
     back = flexarray_make(gc, 16, 1);
 
     if (vtpm->devid == -1) {
-        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm") < 0)) {
+        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -2877,7 +2877,7 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
     back = flexarray_make(gc, 18, 1);
 
     if (nic->devid == -1) {
-        if ((nic->devid = libxl__device_nextid(gc, domid, "vif") < 0)) {
+        if ((nic->devid = libxl__device_nextid(gc, domid, "vif")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3258,7 +3258,7 @@ int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
     back = flexarray_make(gc, 16, 1);
 
     if (vkb->devid == -1) {
-        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb") < 0)) {
+        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3359,7 +3359,7 @@ int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
     back = flexarray_make(gc, 16, 1);
 
     if (vfb->devid == -1) {
-        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb") < 0)) {
+        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb")) < 0) {
             rc = ERROR_FAIL;
             goto out;
         }
--

1.8.0.1

Quoted 5 lines

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

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

#4 lore raw
Quoted 22 lines · Jim Fehlig
Quoted 13 lines · George Dunlap
Quoted 11 lines · Jim Fehlig

Commit 5420f265 has some misplaced parenthesis that caused devid to be assigned 1 or 0 based on checking return value of libxl__device_nextid < 0, e.g.

devid = libxl__device_nextid(...) < 0

This works when only one instance of a given device type exists, but subsequent devices of the same type will also have a devid = 1 if libxl__device_nextid succeeds. Fix by checking the value assigned to devid, e.g.

Quoted 7 lines
Quoted 4 lines

(devid = libxl__device_nextid(...)) < 0

Both for 4.3, and as a patch in general:

Quoted 7 lines

Noticed I have the commit msg a tad bit wrong. It should read "...devices of the same type will also have a devid = 0 if..." since libxl__device_nextid(...) < 0 is false when libxl__device_nextid() succeeds. Also, perhaps I should add that xl is not affected since it supplies devid, but apps such as libvirt that allow libxl to fill in devid are certainly affected when there is more than 1 of the same device type. Should I submit a V2 with an improved commit msg?

I'm afraid I have already committed.

Not to worry.

Ian.

author
#5 lore raw
Quoted 35 lines · Ian Campbell
Quoted 24 lines · Jim Fehlig
Quoted 14 lines · George Dunlap
Quoted 11 lines · Jim Fehlig

Commit 5420f265 has some misplaced parenthesis that caused devid to be assigned 1 or 0 based on checking return value of libxl__device_nextid < 0, e.g.

devid = libxl__device_nextid(...) < 0

This works when only one instance of a given device type exists, but subsequent devices of the same type will also have a devid = 1 if libxl__device_nextid succeeds. Fix by checking the value assigned to devid, e.g.

Quoted 8 lines
Quoted 5 lines

(devid = libxl__device_nextid(...)) < 0

Both for 4.3, and as a patch in general:

Quoted 8 lines

Noticed I have the commit msg a tad bit wrong. It should read "...devices of the same type will also have a devid = 0 if..." since libxl__device_nextid(...) < 0 is false when libxl__device_nextid() succeeds. Also, perhaps I should add that xl is not affected since it supplies devid, but apps such as libvirt that allow libxl to fill in devid are certainly affected when there is more than 1 of the same device type. Should I submit a V2 with an improved commit msg?

Quoted 2 lines

I'm afraid I have already committed.

Yep, saw that just after I sent this message :).

Quoted 2 lines

Not to worry.

Right. The existing msg at least adequately describes the problem.

Regards,
Jim