blob: 2287ad646a513c5f08493fd688457fa2f0751d1a [file] [log] [blame]
From c183a72cde93d83cb6bb6745ad189df119efa1f3 Mon Sep 17 00:00:00 2001
From: Colin Ian King <>
Date: Thu, 16 Jan 2020 17:57:58 +0000
Subject: [PATCH] driver core: platform: fix u32 greater or equal to zero
commit 0707cfa5c3ef58effb143db9db6d6e20503f9dec upstream.
Currently the check that a u32 variable i is >= 0 is always true because
the unsigned variable will never be negative, causing the loop to run
forever. Fix this by changing the pre-decrement check to a zero check on
i followed by a decrement of i.
Addresses-Coverity: ("Unsigned compared against 0")
Fixes: 39cc539f90d0 ("driver core: platform: Prevent resouce overflow from causing infinite loops")
Signed-off-by: Colin Ian King <>
Reviewed-by: Rafael J. Wysocki <>
Signed-off-by: Greg Kroah-Hartman <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 5140a87e27e8..8550d63754b5 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -467,7 +467,7 @@ int platform_device_add(struct platform_device *pdev)
- while (--i >= 0) {
+ while (i--) {
struct resource *r = &pdev->resource[i];
if (r->parent)