All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Peter Maydell <peter.maydell@linaro.org>,
	"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Michael Walle" <michael@walle.cc>,
	"Andrzej Zaborowski" <balrogg@gmail.com>,
	"open list:PXA2XX" <qemu-arm@nongnu.org>
Subject: [Qemu-devel] [PATCH 05/20] sdcard: Use the sd_prepare_request*() functions
Date: Fri,  4 May 2018 12:59:03 -0300	[thread overview]
Message-ID: <20180504155918.21287-6-f4bug@amsat.org> (raw)
In-Reply-To: <20180504155918.21287-1-f4bug@amsat.org>

This guaranties all SDRequest members are initialized.

This silent the Coverity warning:

  "Use of an uninitialized variable (CWE-457)"

and fixes the following issues (all "Uninitialized scalar variable"):

- CID1386072 (hw/sd/sdhci.c::sdhci_end_transfer)
- CID1386074 (hw/sd/bcm2835_sdhost.c::bcm2835_sdhost_send_command)
- CID1386076 (hw/sd/sdhci.c::sdhci_send_command)
- CID1390571 (hw/sd/ssi-sd.c::ssi_sd_transfer)

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/sd/bcm2835_sdhost.c    | 3 +--
 hw/sd/milkymist-memcard.c | 7 +++----
 hw/sd/omap_mmc.c          | 4 +---
 hw/sd/pxa2xx_mmci.c       | 4 +---
 hw/sd/sdhci.c             | 6 ++----
 hw/sd/ssi-sd.c            | 5 ++---
 6 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/hw/sd/bcm2835_sdhost.c b/hw/sd/bcm2835_sdhost.c
index ebf3b926c2..5134d7b5c7 100644
--- a/hw/sd/bcm2835_sdhost.c
+++ b/hw/sd/bcm2835_sdhost.c
@@ -110,8 +110,7 @@ static void bcm2835_sdhost_send_command(BCM2835SDHostState *s)
     uint8_t rsp[16];
     int rlen;
 
-    request.cmd = s->cmd & SDCMD_CMD_MASK;
-    request.arg = s->cmdarg;
+    sd_prepare_request(&request, s->cmd & SDCMD_CMD_MASK, s->cmdarg, false);
 
     rlen = sdbus_do_command(&s->sdbus, &request, rsp);
     if (rlen < 0) {
diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
index ff2b92dc64..d8cbb7b681 100644
--- a/hw/sd/milkymist-memcard.c
+++ b/hw/sd/milkymist-memcard.c
@@ -99,10 +99,9 @@ static void memcard_sd_command(MilkymistMemcardState *s)
 {
     SDRequest req;
 
-    req.cmd = s->command[0] & 0x3f;
-    req.arg = ldl_be_p(s->command + 1);
-    req.crc = s->command[5];
-
+    sd_prepare_request_with_crc(&req, s->command[0] & 0x3f,
+                                ldl_be_p(s->command + 1),
+                                s->command[5]);
     s->response[0] = req.cmd;
     s->response_len = sdbus_do_command(&s->sdbus, &req, s->response + 1);
     s->response_read_ptr = 0;
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index 5b47cadf11..7b71984115 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -135,9 +135,7 @@ static void omap_mmc_command(struct omap_mmc_s *host, int cmd, int dir,
     mask = 0;
     rspstatus = 0;
 
-    request.cmd = cmd;
-    request.arg = host->arg;
-    request.crc = 0; /* FIXME */
+    sd_prepare_request(&request, cmd, host->arg, false /* FIXME */);
 
     rsplen = sd_do_command(host->card, &request, response);
 
diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
index 82f8ec0d50..fd5c1e7686 100644
--- a/hw/sd/pxa2xx_mmci.c
+++ b/hw/sd/pxa2xx_mmci.c
@@ -224,9 +224,7 @@ static void pxa2xx_mmci_wakequeues(PXA2xxMMCIState *s)
     s->tx_len = 0;
     s->cmdreq = 0;
 
-    request.cmd = s->cmd;
-    request.arg = s->arg;
-    request.crc = 0;	/* FIXME */
+    sd_prepare_request(&request, s->cmd, s->arg, false /* FIXME */);
 
     rsplen = sdbus_do_command(&s->sdbus, &request, response);
     s->intreq |= INT_END_CMD;
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 63c44a4ee8..9260f59e80 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -336,8 +336,7 @@ static void sdhci_send_command(SDHCIState *s)
 
     s->errintsts = 0;
     s->acmd12errsts = 0;
-    request.cmd = s->cmdreg >> 8;
-    request.arg = s->argument;
+    sd_prepare_request(&request, s->cmdreg >> 8, s->argument, false);
 
     trace_sdhci_send_command(request.cmd, request.arg);
     rlen = sdbus_do_command(&s->sdbus, &request, response);
@@ -393,8 +392,7 @@ static void sdhci_end_transfer(SDHCIState *s)
         SDRequest request;
         uint8_t response[16];
 
-        request.cmd = 0x0C;
-        request.arg = 0;
+        sd_prepare_request(&request, 12, 0, false);
         trace_sdhci_end_transfer(request.cmd, request.arg);
         sdbus_do_command(&s->sdbus, &request, response);
         /* Auto CMD12 response goes to the upper Response register */
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 0bb26e596d..c22967170c 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -95,9 +95,8 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val)
         if (s->arglen == 4) {
             SDRequest request;
             uint8_t longresp[16];
-            /* FIXME: Check CRC.  */
-            request.cmd = s->cmd;
-            request.arg = ldl_be_p(s->cmdarg);
+            sd_prepare_request(&request, s->cmd,
+                               ldl_be_p(s->cmdarg), false /* FIXME */);
             DPRINTF("CMD%d arg 0x%08x\n", s->cmd, request.arg);
             s->arglen = sdbus_do_command(&s->sdbus, &request, longresp);
             if (s->arglen <= 0) {
-- 
2.17.0

  parent reply	other threads:[~2018-05-04 15:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-04 15:58 [Qemu-devel] [PATCH 00/20] sdcard: proper implementation of CRC Philippe Mathieu-Daudé
2018-05-04 15:58 ` [Qemu-devel] [PATCH 01/20] sdcard: Use the ldst API Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 02/20] sdcard: Extract sd_calc_frame48_crc7() from sd_req_crc_validate() Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 03/20] sdcard: Rename the SDRequest as SDFrame48 Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 04/20] sdcard: Add sd_prepare_request[_with_crc]() Philippe Mathieu-Daudé
2018-05-04 15:59 ` Philippe Mathieu-Daudé [this message]
2018-05-04 15:59 ` [Qemu-devel] [PATCH 06/20] sdcard: Add a "validate-crc" property Philippe Mathieu-Daudé
2018-05-04 23:33   ` Alistair Francis
2018-05-04 15:59 ` [Qemu-devel] [PATCH 07/20] sdcard: Constify sd_crc*()'s message argument Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 08/20] sdcard: Fix sd_crc*() style Philippe Mathieu-Daudé
2018-05-04 23:34   ` Alistair Francis
2018-05-04 15:59 ` [Qemu-devel] [PATCH 09/20] sdcard: Expose sd_crc*() functions for QTest use Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 10/20] sdcard: Expose sd_prepare_request*() " Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 11/20] sdcard: Add test_sd_request_frame_crc7() qtest (request command CRC7) Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 12/20] sdcard: Let sd_frame48_crc7_calc() work on response frames Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 13/20] sdcard: Expose sd_prepare_frame48() for QTest use Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 14/20] sdcard: Add test_sd_response_frame48_crc7 qtest (command response CRC7) Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 15/20] sdcard: Add SDFrame136 struct and 136-bit SD response frames functions Philippe Mathieu-Daudé
2018-05-04 16:57   ` Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 16/20] sdcard: Add test_sd_response_frame136_crc7() qtest Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 17/20] sdcard: Add SDFrameData struct and data frame checksum functions Philippe Mathieu-Daudé
2018-05-05  2:22   ` Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 18/20] sdcard: Fix sd_crc16() Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 19/20] sdcard: Add test_sd_data_frame_crc16() qtest Philippe Mathieu-Daudé
2018-05-04 15:59 ` [Qemu-devel] [PATCH 20/20] sdcard: Add test_sd_verify_cksum_frame48() qtest Philippe Mathieu-Daudé
2018-05-07 20:09 ` [Qemu-devel] [PATCH 00/20] sdcard: proper implementation of CRC Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180504155918.21287-6-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=alistair@alistair23.me \
    --cc=balrogg@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=michael@walle.cc \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.