public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pete Batard" <pete@akeo.ie>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org
Subject: [edk2-platforms: PATCH 1/3] Platform/RPi3: Use Wait4Bit return value consistently
Date: Wed, 17 Jul 2019 12:46:43 +0100	[thread overview]
Message-ID: <20190717114645.7776-2-pete@akeo.ie> (raw)
In-Reply-To: <20190717114645.7776-1-pete@akeo.ie>

From: Michael Brown <mbrown@fensystems.co.uk>

There are multiple points in the existing code that take the UINT32
value returned by Wait4Bit and return it directly as an EFI_STATUS
value.  If Wait4Bit fails, this will result in a spurious EFI_STATUS
value of 0x1 (EFI_WARN_UNKNOWN_GLYPH) being returned to the caller.  A
caller treating any non-zero value as an error will see this as a
failure, but a caller using the EFI_ERROR macro will incorrectly see
it as a success.

Fix by defining the return type of Wait4Bit as EFI_STATUS and ensuring
that a valid EFI_STATUS value is always returned.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/RPi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/Platform/RaspberryPi/RPi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.c b/Platform/RaspberryPi/RPi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.c
index 59120b9d8564..c1e1229f858e 100644
--- a/Platform/RaspberryPi/RPi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.c
+++ b/Platform/RaspberryPi/RPi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.c
@@ -53,7 +53,7 @@ DwCoreInit (
   IN EFI_EVENT        Timeout
   );
 
-UINT32
+EFI_STATUS
 Wait4Bit (
   IN  EFI_EVENT Timeout,
   IN  UINT32    Reg,
@@ -70,14 +70,14 @@ Wait4Bit (
     }
 
     if ((Value & Mask) == Mask) {
-      return 0;
+      return EFI_SUCCESS;
     }
   } while (EFI_ERROR (gBS->CheckEvent (Timeout)));
 
   DEBUG ((DEBUG_ERROR, "Wait4Bit: %a timeout (reg:0x%x, value:0x%x, mask:0x%x)\n",
     Set ? "set" : "clear", Reg, Set ? Value : ~Value, Mask));
 
-  return 1;
+  return EFI_TIMEOUT;
 }
 
 CHANNEL_HALT_REASON
@@ -91,13 +91,14 @@ Wait4Chhltd (
   IN  SPLIT_CONTROL   *Split
   )
 {
-  INT32   Ret;
+  EFI_STATUS Status;
   UINT32  Hcint, Hctsiz;
   UINT32  HcintCompHltAck = DWC2_HCINT_XFERCOMP;
 
   MicroSecondDelay (100);
-  Ret = Wait4Bit (Timeout, DwHc->DwUsbBase + HCINT (Channel), DWC2_HCINT_CHHLTD, 1);
-  if (Ret) {
+  Status = Wait4Bit (Timeout, DwHc->DwUsbBase + HCINT (Channel),
+                     DWC2_HCINT_CHHLTD, 1);
+  if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "Channel %u did not halt\n", Channel));
     return XFER_NOT_HALTED;
   }
@@ -204,7 +205,7 @@ DwCoreReset (
   IN  EFI_EVENT Timeout
   )
 {
-  UINT32  Status;
+  EFI_STATUS Status;
 
   Status = Wait4Bit (Timeout, DwHc->DwUsbBase + GRSTCTL, DWC2_GRSTCTL_AHBIDLE, 1);
   if (Status) {
@@ -1261,7 +1262,7 @@ DwFlushTxFifo (
   IN INT32 Num
   )
 {
-  UINT32 Status;
+  EFI_STATUS Status;
 
   MmioWrite32 (DwHc->DwUsbBase + GRSTCTL, DWC2_GRSTCTL_TXFFLSH |
     (Num << DWC2_GRSTCTL_TXFNUM_OFFSET));
@@ -1279,7 +1280,7 @@ DwFlushRxFifo (
   IN  EFI_EVENT Timeout
   )
 {
-  UINT32 Status;
+  EFI_STATUS Status;
 
   MmioWrite32 (DwHc->DwUsbBase + GRSTCTL, DWC2_GRSTCTL_RXFFLSH);
 
-- 
2.21.0.windows.1


  reply	other threads:[~2019-07-17 11:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-17 11:46 [edk2-platforms: PATCH 0/3] Platform/RPi3: Improve timeout handling in DwUsbHostDxe Pete Batard
2019-07-17 11:46 ` Pete Batard [this message]
2019-07-17 11:46 ` [edk2-platforms: PATCH 2/3] Platform/RPi3: Gracefully disable USB channel after a timeout Pete Batard
2019-07-17 11:46 ` [edk2-platforms: PATCH 3/3] Platform/RPi3: Reduce debug noise when using a USB network device Pete Batard
2019-07-19 11:53 ` [edk2-platforms: PATCH 0/3] Platform/RPi3: Improve timeout handling in DwUsbHostDxe Leif Lindholm
2019-07-19 15:22   ` [edk2-devel] " Michael Brown
2019-07-19 16:43     ` Leif Lindholm
2019-07-19 15:40   ` Pete Batard
2019-07-19 16:35     ` Leif Lindholm

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-list 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=20190717114645.7776-2-pete@akeo.ie \
    --to=devel@edk2.groups.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox