powerpc: Fix signedness bug in update_flash_db()
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 1 Oct 2018 16:44:58 +0000 (19:44 +0300)
committerMichael Ellerman <mpe@ellerman.id.au>
Sat, 13 Oct 2018 11:21:25 +0000 (22:21 +1100)
The "count < sizeof(struct os_area_db)" comparison is type promoted to
size_t so negative values of "count" are treated as very high values
and we accidentally return success instead of a negative error code.

This doesn't really change runtime much but it fixes a static checker
warning.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Geoff Levand <geoff@infradead.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/platforms/ps3/os-area.c

index cdbfc5cfd6f38ee85620288c14d2288808572e1e..f5387ad822798125402d76a530a6d7cc2c1733f5 100644 (file)
@@ -664,7 +664,7 @@ static int update_flash_db(void)
        db_set_64(db, &os_area_db_id_rtc_diff, saved_params.rtc_diff);
 
        count = os_area_flash_write(db, sizeof(struct os_area_db), pos);
-       if (count < sizeof(struct os_area_db)) {
+       if (count < 0 || count < sizeof(struct os_area_db)) {
                pr_debug("%s: os_area_flash_write failed %zd\n", __func__,
                         count);
                error = count < 0 ? count : -EIO;