diff mbox

s390: avoid always-true comparison in s390_pci_generate_fid()

Message ID 1476968226-15918-1-git-send-email-peter.maydell@linaro.org
State Accepted
Commit 35b6e94ba50cd92600a85eef444bc31df8999de1
Headers show

Commit Message

Peter Maydell Oct. 20, 2016, 12:57 p.m. UTC
Coverity points out that the comparison "fid <= ZPCI_MAX_FID"
in s390_pci_generate_fid() is always true (because fid
is 32 bits and ZPCI_MAX_FID is 0xffffffff). This isn't a
bug because the real loop termination condition is
expressed later via an "if (...) break;" inside the loop,
but it is a bit odd. Rephrase the loop to avoid the
unnecessary duplicate-but-never-true conditional.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 hw/s390x/s390-pci-bus.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

-- 
2.7.4

Comments

Cornelia Huck Oct. 20, 2016, 1:26 p.m. UTC | #1
On Thu, 20 Oct 2016 13:57:06 +0100
Peter Maydell <peter.maydell@linaro.org> wrote:

> Coverity points out that the comparison "fid <= ZPCI_MAX_FID"

> in s390_pci_generate_fid() is always true (because fid

> is 32 bits and ZPCI_MAX_FID is 0xffffffff). This isn't a

> bug because the real loop termination condition is

> expressed later via an "if (...) break;" inside the loop,

> but it is a bit odd. Rephrase the loop to avoid the

> unnecessary duplicate-but-never-true conditional.

> 

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

> ---

>  hw/s390x/s390-pci-bus.c | 10 ++--------

>  1 file changed, 2 insertions(+), 8 deletions(-)


Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>


I assume this will go via the trivial tree?
Michael Tokarev Oct. 26, 2016, 6:42 p.m. UTC | #2
Applied to -trivial, thanks!

/mjt
diff mbox

Patch

diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index b7f8bca..bbbe0b1 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -809,17 +809,11 @@  static uint32_t s390_pci_generate_fid(Error **errp)
 {
     uint32_t fid = 0;
 
-    while (fid <= ZPCI_MAX_FID) {
+    do {
         if (!s390_pci_find_dev_by_fid(fid)) {
             return fid;
         }
-
-        if (fid == ZPCI_MAX_FID) {
-            break;
-        }
-
-        fid++;
-    }
+    } while (fid++ != ZPCI_MAX_FID);
 
     error_setg(errp, "no free fid could be found");
     return 0;