driver core: platform: fix u32 greater or equal to zero comparison
authorColin Ian King <colin.king@canonical.com>
Thu, 16 Jan 2020 17:57:58 +0000 (17:57 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Jan 2020 14:27:11 +0000 (15:27 +0100)
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 <colin.king@canonical.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20200116175758.88396-1-colin.king@canonical.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/platform.c

index 864b53b3d5980b3993d34576a807e09cef52f07f..7fa654f1288b80ffa73e11c49f7d340695d5de9e 100644 (file)
@@ -571,7 +571,7 @@ int platform_device_add(struct platform_device *pdev)
                pdev->id = PLATFORM_DEVID_AUTO;
        }
 
-       while (--i >= 0) {
+       while (i--) {
                struct resource *r = &pdev->resource[i];
                if (r->parent)
                        release_resource(r);