Skip to contentSkip to conversation

3 easy-to-fix clang warnings, 1 error code fixed

PATCH Applied Philippe Mathieu-Daudé 3 participants 10 messages Apr 7, 2017 – Jul 15, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover 3 easy-to-fix clang warnings, 1 error code fixed

This patchset fixes three easy-to-fix unrelated clang warnings, so it was probably better to send them separately the first time.

v2:
- hw/usb/dev-smartcard-reader.c: The first patch was treating NULL and 0 as errors but those values are legal in some cases, i.e. no (virtual) smartcard inserted into the card reader (Gerd Hoffmann's review).
- device_tree.c: Added Marc-André Lureau's Reviewed-by.
- qga/commands-posix.c: Added a commit to improve failed operation, as suggested by Michael Roth.

Philippe Mathieu-Daudé (4):
usb-ccid: make ccid_write_data_block() cope with null buffers
device_tree: fix compiler warnings (clang 5)
qga: fix compiler warnings (clang 5)
qga: improve error handling in transfer_memory_block

 device_tree.c                 |  1 +
 hw/usb/dev-smartcard-reader.c |  5 ++++-
 qga/commands-posix.c          | 11 ++++++++---
 3 files changed, 13 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/4 usb-ccid: make ccid_write_data_block() cope with null buffers

static code analyzer complain:

hw/usb/dev-smartcard-reader.c:816:5: warning: Null pointer passed as an argument to a 'nonnull' parameter

    memcpy(p->abData, data, len);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 hw/usb/dev-smartcard-reader.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/usb/dev-smartcard-reader.c +4 -1
index 757b8b3f5a..49cb1829b5 100644
@@ -813,7 +813,10 @@ static void ccid_write_data_block(USBCCIDState *s, uint8_t slot, uint8_t seq,
     if (p->b.bError) {
         DPRINTF(s, D_VERBOSE, "error %d\n", p->b.bError);
     }
-    memcpy(p->abData, data, len);
+    if (len) {
+        g_assert_nonnull(data);
+        memcpy(p->abData, data, len);
+    }
     ccid_reset_error_status(s);
     usb_wakeup(s->bulk, 0);
 }
Signature · 1 line
2.11.0
#2 lore raw

PATCH v2 2/4 device_tree: fix compiler warnings (clang 5)

In reply to Philippe Mathieu-Daudé

static code analyzer complain:

device_tree.c:155:18: warning: Null pointer passed as an argument to a 'nonnull' parameter

    while ((de = readdir(d)) != NULL) {
                 ^~~~~~~~~~
Reported-by Clang Static Analyzer
---
 device_tree.c | 1 +
 1 file changed, 1 insertion(+)
device_tree.c +1 -0
index 6e06320830..a24ddff02b 100644
@@ -148,6 +148,7 @@ static void read_fstree(void *fdt, const char *dirname)
     d = opendir(dirname);
     if (!d) {
         error_setg(&error_fatal, "%s cannot open %s", __func__, dirname);
+        return;
     }
 
     while ((de = readdir(d)) != NULL) {
Signature · 1 line
2.11.0
#3 lore raw

PATCH v2 3/4 qga: fix compiler warnings (clang 5)

In reply to Philippe Mathieu-Daudé

static code analyzer complain:

qga/commands-posix.c:2127:9: warning: Null pointer passed as an argument to a 'nonnull' parameter

        closedir(dp);
        ^~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 qga/commands-posix.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
qga/commands-posix.c +5 -3
index 915df9ed90..fc45102a1e 100644
@@ -2124,9 +2124,11 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
          * we think this VM does not support online/offline memory block,
          * any other solution?
          */
-        if (!dp && errno == ENOENT) {
-            result->response =
-                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+        if (!dp) {
+            if (errno == ENOENT) {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            }
             goto out1;
         }
         closedir(dp);
Signature · 1 line
2.11.0
Reviewed-by on v2 3/4
#4 lore raw

Re: [Qemu-devel] [PATCH v2 3/4] qga: fix compiler warnings (clang 5)

Quoting Philippe Mathieu-Daudé (2017-04-07 17:20:15)

Quoted 9 lines

static code analyzer complain:

qga/commands-posix.c:2127:9: warning: Null pointer passed as an argument to a 'nonnull' parameter

        closedir(dp);
        ^~~~~~~~~~~~
Reported-by Clang Static Analyzer
Quoted 26 lines
---
 qga/commands-posix.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
qga/commands-posix.c +5 -3
index 915df9ed90..fc45102a1e 100644
@@ -2124,9 +2124,11 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
          * we think this VM does not support online/offline memory block,
          * any other solution?
          */
-        if (!dp && errno == ENOENT) {
-            result->response =
-                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+        if (!dp) {
+            if (errno == ENOENT) {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            }
             goto out1;
         }
         closedir(dp);
Signature · 1 line
2.11.0
#5 lore raw

PATCH v2 4/4 qga: improve error handling in transfer_memory_block

In reply to Philippe Mathieu-Daudé

---

Michael should I use Signed-off-by instead of the Suggested-by (since it is your code)?

 qga/commands-posix.c | 3 +++
 1 file changed, 3 insertions(+)
qga/commands-posix.c +3 -0
index fc45102a1e..ca5a24b2c9 100644
@@ -2128,6 +2128,9 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
             if (errno == ENOENT) {
                 result->response =
                     GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            } else {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED;
             }
             goto out1;
         }
Signature · 1 line
2.11.0
Reviewed-by on v2 4/4
#6 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] qga: improve error handling in transfer_memory_block

Quoting Philippe Mathieu-Daudé (2017-04-07 17:20:16)

Quoted 2 lines
Quoted 4 lines

---

Michael should I use Signed-off-by instead of the Suggested-by (since it is your code)?

I suppose it could go either way depending on the circumstances (assuming you've asked for / obtained their SoB obviously), but speaking for myself here I don't think it's necessary.

Quoted 21 lines
 qga/commands-posix.c | 3 +++
 1 file changed, 3 insertions(+)
qga/commands-posix.c +3 -0
index fc45102a1e..ca5a24b2c9 100644
@@ -2128,6 +2128,9 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
             if (errno == ENOENT) {
                 result->response =
                     GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            } else {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED;
             }
             goto out1;
         }
Signature · 1 line
2.11.0
#7 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] qga: improve error handling in transfer_memory_block

Quoted 6 lines · Michael Roth

Quoting Philippe Mathieu-Daudé (2017-04-07 17:20:16)

Quoted 2 lines
Quoted 9 lines
Quoted 4 lines

---

Michael should I use Signed-off-by instead of the Suggested-by (since it is your code)?

I suppose it could go either way depending on the circumstances (assuming you've asked for / obtained their SoB obviously), but speaking for myself here I don't think it's necessary.

Ok! I allowed myself to add your "Suggested-by" after reading Linux's process/submitting-patches.rst doc, assuming no need to ask for it since you answered in public ML. I'll diligently ask next time!

Quoted 22 lines
Quoted 21 lines
 qga/commands-posix.c | 3 +++
 1 file changed, 3 insertions(+)
qga/commands-posix.c +3 -1
index fc45102a1e..ca5a24b2c9 100644
@@ -2128,6 +2128,9 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
             if (errno == ENOENT) {
                 result->response =
                     GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            } else {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED;
             }
             goto out1;
         }
--

2.11.0

#8 lore raw

Re: [Qemu-devel] [PATCH v2 4/4] qga: improve error handling in transfer_memory_block

In reply to Michael Roth

ping?

Quoted 37 lines · Michael Roth

Quoting Philippe Mathieu-Daudé (2017-04-07 17:20:16)

Quoted 2 lines
Quoted 4 lines

---

Michael should I use Signed-off-by instead of the Suggested-by (since it is your code)?

I suppose it could go either way depending on the circumstances (assuming you've asked for / obtained their SoB obviously), but speaking for myself here I don't think it's necessary.

Quoted 21 lines
 qga/commands-posix.c | 3 +++
 1 file changed, 3 insertions(+)
qga/commands-posix.c +3 -1
index fc45102a1e..ca5a24b2c9 100644
@@ -2128,6 +2128,9 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
             if (errno == ENOENT) {
                 result->response =
                     GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            } else {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED;
             }
             goto out1;
         }
--

2.11.0

#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

This patchset fixes three easy-to-fix unrelated clang warnings, so it was probably better to send them separately the first time.

v2:
- hw/usb/dev-smartcard-reader.c: The first patch was treating NULL and 0 as errors but those values are legal in some cases, i.e. no (virtual) smartcard inserted into the card reader (Gerd Hoffmann's review).
- device_tree.c: Added Marc-André Lureau's Reviewed-by.
- qga/commands-posix.c: Added a commit to improve failed operation, as suggested by Michael Roth.

Quoted 5 lines

Philippe Mathieu-Daudé (4):
usb-ccid: make ccid_write_data_block() cope with null buffers
device_tree: fix compiler warnings (clang 5)
qga: fix compiler warnings (clang 5)
qga: improve error handling in transfer_memory_block

Applied to -trivial, thanks!

/mjt