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

Philippe Mathieu-Daudé posted 4 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH-for-9.1 v2 3/4] hw/ssi/pnv_spi: Return early in transfer()
Posted by Philippe Mathieu-Daudé 3 months, 2 weeks ago
Return early to simplify next commit.
No logical change intended.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/ssi/pnv_spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/ssi/pnv_spi.c b/hw/ssi/pnv_spi.c
index 13a47f07e7..05e6afc11e 100644
--- a/hw/ssi/pnv_spi.c
+++ b/hw/ssi/pnv_spi.c
@@ -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)
-- 
2.45.2


Re: [PATCH-for-9.1 v2 3/4] hw/ssi/pnv_spi: Return early in transfer()
Posted by Richard Henderson 3 months, 2 weeks ago
On 8/8/24 06:28, Philippe Mathieu-Daudé wrote:
> Return early to simplify next commit.
> No logical change intended.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/ssi/pnv_spi.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/ssi/pnv_spi.c b/hw/ssi/pnv_spi.c
> index 13a47f07e7..05e6afc11e 100644
> --- a/hw/ssi/pnv_spi.c
> +++ b/hw/ssi/pnv_spi.c
> @@ -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

> +    if (!rsp_payload) {
> +        return;
> +    }

so this will never fail.

>       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~