Skip to contentSkip to conversation

hw/ssi/pnv_spi: Fixes Coverity CID 1558831

PATCH In review Philippe Mathieu-Daudé 5 participants 15 messages Aug 7, 2024 – Nov 4, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover hw/ssi/pnv_spi: Fixes Coverity CID 1558831

v2:
- Cover PowerNV SSI in MAINTAINERS
- Use GLib API in pnv_spi_xfer_buffer_free()
- Simplify returning early

Supersedes: <[email protected]>

Chalapathi V (1):
hw/ssi/pnv_spi: Fixes Coverity CID 1558831

Philippe Mathieu-Daudé (3):
MAINTAINERS: Cover PowerPC SPI model in PowerNV section hw/ssi/pnv_spi: Match _xfer_buffer_free() with _xfer_buffer_new() hw/ssi/pnv_spi: Return early in transfer()

 MAINTAINERS      |  2 ++
 hw/ssi/pnv_spi.c | 12 +++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/4 MAINTAINERS: Cover PowerPC SPI model in PowerNV section

It is unfair to let the PowerNV SPI model to the SSI maintainers. Also include the PowerNV ones.

Fixes 29318db133 ("hw/ssi: Add SPI model")
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 74a85360fd..52843876ab 100644
@@ -1542,8 +1542,10 @@ F: hw/ppc/pnv*
 F: hw/intc/pnv*
 F: hw/intc/xics_pnv.c
 F: hw/pci-host/pnv*
+F: hw/ssi/pnv_spi.c
 F: include/hw/ppc/pnv*
 F: include/hw/pci-host/pnv*
+F: hw/ssi/pnv_spi*
 F: pc-bios/skiboot.lid
 F: tests/qtest/pnv*
 
Signature · 1 line
2.45.2
#2 lore raw

PATCH v2 2/4 hw/ssi/pnv_spi: Match _xfer_buffer_free() with _xfer_buffer_new()

In reply to Philippe Mathieu-Daudé

pnv_spi_xfer_buffer_new() allocates %payload using g_malloc0(), and pnv_spi_xfer_buffer_write_ptr() allocates %payload->data using g_realloc(). Use the API equivalent g_free() to release the buffers.

---
 hw/ssi/pnv_spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ssi/pnv_spi.c +2 -2
index c1297ab733..13a47f07e7 100644
@@ -53,8 +53,8 @@ static PnvXferBuffer *pnv_spi_xfer_buffer_new(void)
 
 static void pnv_spi_xfer_buffer_free(PnvXferBuffer *payload)
 {
-    free(payload->data);
-    free(payload);
+    g_free(payload->data);
+    g_free(payload);
 }
 
 static uint8_t *pnv_spi_xfer_buffer_write_ptr(PnvXferBuffer *payload,
Signature · 1 line
2.45.2
Reviewed-by on v2 2/4
#3 lore raw

Re: [PATCH-for-9.1 v2 2/4] hw/ssi/pnv_spi: Match _xfer_buffer_free() with _xfer_buffer_new()

Quoted 15 lines · Philippe Mathieu-Daudé

pnv_spi_xfer_buffer_new() allocates %payload using g_malloc0(), and pnv_spi_xfer_buffer_write_ptr() allocates %payload->data using g_realloc(). Use the API equivalent g_free() to release the buffers.

---
  hw/ssi/pnv_spi.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
hw/ssi/pnv_spi.c +0 -0
index c1297ab733..13a47f07e7 100644

hw/ssi/pnv_spi.c static PnvXferBuffer *pnv_spi_xfer_buffer_new(void) · line 60

Quoted 10 lines
hw/ssi/pnv_spi.c +2 -2
@@ -53,8 +53,8 @@ static PnvXferBuffer *pnv_spi_xfer_buffer_new(void)
 
  static void pnv_spi_xfer_buffer_free(PnvXferBuffer *payload)
  {
-    free(payload->data);
-    free(payload);
+    g_free(payload->data);
+    g_free(payload);
  }
 
  static uint8_t *pnv_spi_xfer_buffer_write_ptr(PnvXferBuffer *payload,

g_free/free are supposed to be interchangeable in this epoch.

But

r~

#4 lore raw

PATCH v2 3/4 hw/ssi/pnv_spi: Return early in transfer()

In reply to Philippe Mathieu-Daudé

Return early to simplify next commit.
No logical change intended.

---
 hw/ssi/pnv_spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/pnv_spi.c +4 -3
index 13a47f07e7..05e6afc11e 100644
@@ -217,6 +217,9 @@ static void transfer(PnvSpi *s, PnvXferBuffer *payload)
     PnvXferBuffer *rsp_payload = NULL;
 
     rsp_payload = pnv_spi_xfer_buffer_new();
+    if (!rsp_payload) {
+        return;
+    }
     for (int offset = 0; offset < payload->len; offset += s->transfer_len) {
         tx = 0;
         for (int i = 0; i < s->transfer_len; i++) {
@@ -235,9 +238,7 @@ static void transfer(PnvSpi *s, PnvXferBuffer *payload)
                     (rx >> (8 * (s->transfer_len - 1) - i * 8)) & 0xFF;
         }
     }
-    if (rsp_payload != NULL) {
-        spi_response(s, s->N1_bits, rsp_payload);
-    }
+    spi_response(s, s->N1_bits, rsp_payload);
 }
 
 static inline uint8_t get_seq_index(PnvSpi *s)
Signature · 1 line
2.45.2
#5 lore raw

Re: [PATCH-for-9.1 v2 3/4] hw/ssi/pnv_spi: Return early in transfer()

Quoted 13 lines · Philippe Mathieu-Daudé

Return early to simplify next commit.
No logical change intended.

---
  hw/ssi/pnv_spi.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/pnv_spi.c +0 -0
index 13a47f07e7..05e6afc11e 100644

hw/ssi/pnv_spi.c static void transfer(PnvSpi *s, PnvXferBuffer *payload) · line 219

Quoted 3 lines
hw/ssi/pnv_spi.c +0 -0
@@ -217,6 +217,9 @@ static void transfer(PnvSpi *s, PnvXferBuffer *payload)
      PnvXferBuffer *rsp_payload = NULL;
 
      rsp_payload = pnv_spi_xfer_buffer_new();

this uses g_malloc0

hw/ssi/pnv_spi.c static void transfer(PnvSpi *s, PnvXferBuffer *payload) · line 222

Quoted 3 lines
hw/ssi/pnv_spi.c +3 -0
+    if (!rsp_payload) {
+        return;
+    }

so this will never fail.

hw/ssi/pnv_spi.c static void transfer(PnvSpi *s, PnvXferBuffer *payload) · line 242

Quoted 12 lines
hw/ssi/pnv_spi.c +1 -3
      for (int offset = 0; offset < payload->len; offset += s->transfer_len) {
          tx = 0;
          for (int i = 0; i < s->transfer_len; i++) {
@@ -235,9 +238,7 @@ static void transfer(PnvSpi *s, PnvXferBuffer *payload)
                      (rx >> (8 * (s->transfer_len - 1) - i * 8)) & 0xFF;
          }
      }
-    if (rsp_payload != NULL) {
-        spi_response(s, s->N1_bits, rsp_payload);
-    }
+    spi_response(s, s->N1_bits, rsp_payload);
  }

The cleanup could simply be this hunk.

r~

#6 lore raw

PATCH v2 4/4 hw/ssi/pnv_spi: Fixes Coverity CID 1558831

In reply to Philippe Mathieu-Daudé

From: Chalapathi V <[email protected]>

In this commit the following coverity scan defect has been fixed CID 1558831: Resource leaks (RESOURCE_LEAK)
Variable "rsp_payload" going out of scope leaks the storage it points to.

Fixes Coverity CID 1558831
Fixes b4cb930e40 ("hw/ssi: Extend SPI model")
[PMD: Rebased on previous commit (returning earlier)]
---
 hw/ssi/pnv_spi.c | 1 +
 1 file changed, 1 insertion(+)
hw/ssi/pnv_spi.c +1 -0
index 05e6afc11e..eadc36fa86 100644
@@ -239,6 +239,7 @@ static void transfer(PnvSpi *s, PnvXferBuffer *payload)
         }
     }
     spi_response(s, s->N1_bits, rsp_payload);
+    pnv_spi_xfer_buffer_free(rsp_payload);
 }
 
 static inline uint8_t get_seq_index(PnvSpi *s)
Signature · 1 line
2.45.2
author Reviewed-by on v2 4/4
#7 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé

From: Chalapathi V <[email protected]>

In this commit the following coverity scan defect has been fixed CID 1558831: Resource leaks (RESOURCE_LEAK)
Variable "rsp_payload" going out of scope leaks the storage it points to.

Fixes Coverity CID 1558831
Fixes b4cb930e40 ("hw/ssi: Extend SPI model")
Quoted 18 lines
[PMD: Rebased on previous commit (returning earlier)]
---
  hw/ssi/pnv_spi.c | 1 +
  1 file changed, 1 insertion(+)
hw/ssi/pnv_spi.c +1 -0
index 05e6afc11e..eadc36fa86 100644
@@ -239,6 +239,7 @@ static void transfer(PnvSpi *s, PnvXferBuffer *payload)
          }
      }
      spi_response(s, s->N1_bits, rsp_payload);
+    pnv_spi_xfer_buffer_free(rsp_payload);
  }
 
  static inline uint8_t get_seq_index(PnvSpi *s)
Reviewed-by on v2 4/4
#8 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

From: Chalapathi V<[email protected]>

In this commit the following coverity scan defect has been fixed CID 1558831: Resource leaks (RESOURCE_LEAK)
Variable "rsp_payload" going out of scope leaks the storage it points to.

Quoted 8 lines
Fixes Coverity CID 1558831
Fixes b4cb930e40 ("hw/ssi: Extend SPI model")
[PMD: Rebased on previous commit (returning earlier)]
---
  hw/ssi/pnv_spi.c | 1 +
  1 file changed, 1 insertion(+)

r~

#9 lore raw
In reply to Philippe Mathieu-Daudé

Chalapthi,

Quoted 6 lines · Philippe Mathieu-Daudé

v2:
- Cover PowerNV SSI in MAINTAINERS
- Use GLib API in pnv_spi_xfer_buffer_free()
- Simplify returning early

Supersedes: <[email protected]>

I was wondering where we were on this series. I see there were comments on the initial one that would need some response at least. Do you have plans for a respin ?

Thanks,

C.

Quoted 12 lines

Chalapathi V (1):

   hw/ssi/pnv_spi: Fixes Coverity CID 1558831

Philippe Mathieu-Daudé (3):
MAINTAINERS: Cover PowerPC SPI model in PowerNV section hw/ssi/pnv_spi: Match _xfer_buffer_free() with _xfer_buffer_new() hw/ssi/pnv_spi: Return early in transfer()

  MAINTAINERS      |  2 ++
  hw/ssi/pnv_spi.c | 12 +++++++-----
  2 files changed, 9 insertions(+), 5 deletions(-)
#10 lore raw
Quoted 10 lines · Cédric Le Goater

Chalapthi,

Quoted 6 lines · Philippe Mathieu-Daudé

v2:
- Cover PowerNV SSI in MAINTAINERS
- Use GLib API in pnv_spi_xfer_buffer_free()
- Simplify returning early

Supersedes: <[email protected]>

Quoted 8 lines

I was wondering where we were on this series. I see there were comments on the initial one that would need some response at least. Do you have plans for a respin ?

Thanks,

C.

Hello Cedric,

Thank You so much for reminding me. I apologize for not getting back on this sooner. I am working on the review comments from initial v1 patchset and send the v2 patchset ASAP.

Thank You,

Chalapathi

Quoted 15 lines
Quoted 13 lines

Chalapathi V (1):
   hw/ssi/pnv_spi: Fixes Coverity CID 1558831

Philippe Mathieu-Daudé (3):
   MAINTAINERS: Cover PowerPC SPI model in PowerNV section hw/ssi/pnv_spi: Match _xfer_buffer_free() with _xfer_buffer_new() hw/ssi/pnv_spi: Return early in transfer()

  MAINTAINERS      |  2 ++
  hw/ssi/pnv_spi.c | 12 +++++++-----

  2 files changed, 9 insertions(+), 5 deletions(-)
#11 lore raw

Hello,

Quoted 16 lines · Chalapathi V
Quoted 14 lines · Cédric Le Goater

Chalapthi,

Quoted 6 lines · Philippe Mathieu-Daudé

v2:
- Cover PowerNV SSI in MAINTAINERS
- Use GLib API in pnv_spi_xfer_buffer_free()
- Simplify returning early

Supersedes: <[email protected]>

I was wondering where we were on this series. I see there were comments on the initial one that would need some response at least. Do you have plans for a respin ?

Quoted 7 lines
Quoted 4 lines

Thanks,

C.

Hello Cedric,

Thank You so much for reminding me. I apologize for not getting back on this sooner.

That's fine. We have some spare time before the QEMU 9.2 cycle closes. I'd say ~2 months. Still, it would be good to address these issues before adding more models (Dan's TPM device model) relying on it.

Quoted 1 line

I am working on the review comments from initial v1 patchset and send the v2 patchset ASAP.

That would be a v3 ? Since Philippe sent a v2.

Thanks,

C.

#12 lore raw
Quoted 23 lines · Cédric Le Goater

Hello,

Quoted 20 lines · Chalapathi V
Quoted 18 lines · Cédric Le Goater

Chalapthi,

Quoted 6 lines · Philippe Mathieu-Daudé

v2:
- Cover PowerNV SSI in MAINTAINERS
- Use GLib API in pnv_spi_xfer_buffer_free()
- Simplify returning early

Supersedes: <[email protected]>

I was wondering where we were on this series. I see there were comments on the initial one that would need some response at least. Do you have plans for a respin ?

Thanks,

C.

Quoted 8 lines
Quoted 3 lines

Hello Cedric,

Thank You so much for reminding me. I apologize for not getting back on this sooner.

That's fine. We have some spare time before the QEMU 9.2 cycle closes. I'd say ~2 months. Still, it would be good to address these issues before adding more models (Dan's TPM device model) relying on it.

Sure. Thank You.

Quoted 8 lines
Quoted 2 lines

I am working on the review comments from initial v1 patchset and send the v2 patchset ASAP.

That would be a v3 ? Since Philippe sent a v2.

Thanks,

C.

Sure. Will send v3 for the series: hw/ssi/pnv_spi: Fixes Coverity CID 1558831 and

a separate series for resolving Coverity CID 1558827.

Thank You,

Chalapathi

#13 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

v2:
- Cover PowerNV SSI in MAINTAINERS
- Use GLib API in pnv_spi_xfer_buffer_free()
- Simplify returning early

Supersedes: <[email protected]>

Quoted 7 lines

Chalapathi V (1):
hw/ssi/pnv_spi: Fixes Coverity CID 1558831

Philippe Mathieu-Daudé (3):
MAINTAINERS: Cover PowerPC SPI model in PowerNV section hw/ssi/pnv_spi: Match _xfer_buffer_free() with _xfer_buffer_new() hw/ssi/pnv_spi: Return early in transfer()

Note that I included this series in the ppc 9.2 PR, because Chalapathi has not found time to finish the better rework. There were a couple of comments about style / unnecessary code for these, but that will all get replaced by the rework so I prefer to leave unchanged. Thanks all for the help with this.

Thanks,
Nick

#14 lore raw
Quoted 16 lines · Nicholas Piggin
Quoted 7 lines · Philippe Mathieu-Daudé

v2:
- Cover PowerNV SSI in MAINTAINERS
- Use GLib API in pnv_spi_xfer_buffer_free()
- Simplify returning early

Supersedes: <[email protected]>

Quoted 7 lines

Chalapathi V (1):

   hw/ssi/pnv_spi: Fixes Coverity CID 1558831

Philippe Mathieu-Daudé (3):
MAINTAINERS: Cover PowerPC SPI model in PowerNV section hw/ssi/pnv_spi: Match _xfer_buffer_free() with _xfer_buffer_new() hw/ssi/pnv_spi: Return early in transfer()

Quoted 5 lines

Note that I included this series in the ppc 9.2 PR, because Chalapathi has not found time to finish the better rework. There were a couple of comments about style / unnecessary code for these, but that will all get replaced by the rework so I prefer to leave unchanged. Thanks all for the help with this.

Thanks Nick!