Skip to contentSkip to conversation

9pfs: simplify v9fs_walk()

PATCH In review Christian Schoenebeck 2 participants 3 messages May 16, 2021 – May 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 9pfs: simplify v9fs_walk()

There is only one comparison between nwnames and P9_MAXWELEM required.

---
 hw/9pfs/9p.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/9pfs/9p.c +5 -4
index 0fa776af09..89aa07db78 100644
@@ -1739,7 +1739,11 @@ static void coroutine_fn v9fs_walk(void *opaque)
 
     trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames);
 
-    if (nwnames && nwnames <= P9_MAXWELEM) {
+    if (nwnames > P9_MAXWELEM) {
+        err = -EINVAL;
+        goto out_nofid;
+    }
+    if (nwnames) {
         wnames = g_new0(V9fsString, nwnames);
         qids   = g_new0(V9fsQID, nwnames);
         for (i = 0; i < nwnames; i++) {
@@ -1753,9 +1757,6 @@ static void coroutine_fn v9fs_walk(void *opaque)
             }
             offset += err;
         }
-    } else if (nwnames > P9_MAXWELEM) {
-        err = -EINVAL;
-        goto out_nofid;
     }
     fidp = get_fid(pdu, fid);
     if (fidp == NULL) {
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Sun, 16 May 2021 17:55:34 +0200 Christian Schoenebeck…

There is only one comparison between nwnames and P9_MAXWELEM required.

---

Nice catch. It's been there for a decade :)

Quoted 30 lines
 hw/9pfs/9p.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/9pfs/9p.c +5 -4
index 0fa776af09..89aa07db78 100644
@@ -1739,7 +1739,11 @@ static void coroutine_fn v9fs_walk(void *opaque)
 
     trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames);
 
-    if (nwnames && nwnames <= P9_MAXWELEM) {
+    if (nwnames > P9_MAXWELEM) {
+        err = -EINVAL;
+        goto out_nofid;
+    }
+    if (nwnames) {
         wnames = g_new0(V9fsString, nwnames);
         qids   = g_new0(V9fsQID, nwnames);
         for (i = 0; i < nwnames; i++) {
@@ -1753,9 +1757,6 @@ static void coroutine_fn v9fs_walk(void *opaque)
             }
             offset += err;
         }
-    } else if (nwnames > P9_MAXWELEM) {
-        err = -EINVAL;
-        goto out_nofid;
     }
     fidp = get_fid(pdu, fid);
     if (fidp == NULL) {
#2 lore raw
Quoted 11 lines · On Montag, 17. Mai 2021 13:35:09 CEST Greg Kurz wrote:

On Sun, 16 May 2021 17:55:34 +0200

Quoted 4 lines · Christian Schoenebeck

There is only one comparison between nwnames and P9_MAXWELEM required.

---

Nice catch. It's been there for a decade :)

Now that was a quick response! Queued, thanks!

https://github.com/cschoenebeck/qemu/commits/9p.next

Quoted 37 lines
Quoted 37 lines
 hw/9pfs/9p.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/9pfs/9p.c +5 -1
index 0fa776af09..89aa07db78 100644
@@ -1739,7 +1739,11 @@ static void coroutine_fn v9fs_walk(void *opaque)
 
     trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames);
 
-    if (nwnames && nwnames <= P9_MAXWELEM) {
+    if (nwnames > P9_MAXWELEM) {
+        err = -EINVAL;
+        goto out_nofid;
+    }
+    if (nwnames) {
 
         wnames = g_new0(V9fsString, nwnames);
         qids   = g_new0(V9fsQID, nwnames);
         for (i = 0; i < nwnames; i++) {
hw/9pfs/9p.c +0 -3
@@ -1753,9 +1757,6 @@ static void coroutine_fn v9fs_walk(void *opaque)
 
             }
             offset += err;
 
         }
 
-    } else if (nwnames > P9_MAXWELEM) {
-        err = -EINVAL;
-        goto out_nofid;
     }
     fidp = get_fid(pdu, fid);
     if (fidp == NULL) {