OSDN Git Service

drm/amdgpu: Fix signedness bug in __amdgpu_eeprom_xfer()
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 3 Jul 2021 09:44:57 +0000 (12:44 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 8 Jul 2021 19:18:14 +0000 (15:18 -0400)
The i2c_transfer() function returns negatives or else the number of
messages transferred.  This code does not work because ARRAY_SIZE()
is type size_t and so that means negative values of "r" are type
promoted to high positive values which are greater than the ARRAY_SIZE().

Fix this by changing the < to != which works regardless of type
promotion.

Fixes: 746b584762e452 ("drm/amdgpu: Fixes to the AMDGPU EEPROM driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c

index 4c3c65a..4d9eb01 100644 (file)
@@ -147,7 +147,7 @@ static int __amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,
                /* This constitutes a START-STOP transaction.
                 */
                r = i2c_transfer(i2c_adap, msgs, ARRAY_SIZE(msgs));
-               if (r < ARRAY_SIZE(msgs))
+               if (r != ARRAY_SIZE(msgs))
                        break;
 
                if (!read) {