Skip to content

Commit 8d46a27

Browse files
ISCAS-Vulabdamien-lemoal
authored andcommitted
ata: sata_sx4: Add error handling in pdc20621_i2c_read()
The function pdc20621_prog_dimm0() calls the function pdc20621_i2c_read() but does not handle the error if the read fails. This could lead to process with invalid data. A proper implementation can be found in /source/drivers/ata/sata_sx4.c, pdc20621_prog_dimm_global(). As mentioned in its commit: bb44e15, the variable spd0 might be used uninitialized when pdc20621_i2c_read() fails. Add error handling to pdc20621_i2c_read(). If a read operation fails, an error message is logged via dev_err(), and return a negative error code. Add error handling to pdc20621_prog_dimm0() in pdc20621_dimm_init(), and return a negative error code if pdc20621_prog_dimm0() fails. Fixes: 4447d35 ("libata: convert the remaining SATA drivers to new init model") Signed-off-by: Wentao Liang <vulab@iscas.ac.cn> Reviewed-by: Niklas Cassel <cassel@kernel.org> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
1 parent ad320e4 commit 8d46a27

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/ata/sata_sx4.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,14 @@ static int pdc20621_prog_dimm0(struct ata_host *host)
11171117
mmio += PDC_CHIP0_OFS;
11181118

11191119
for (i = 0; i < ARRAY_SIZE(pdc_i2c_read_data); i++)
1120-
pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
1121-
pdc_i2c_read_data[i].reg,
1122-
&spd0[pdc_i2c_read_data[i].ofs]);
1120+
if (!pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
1121+
pdc_i2c_read_data[i].reg,
1122+
&spd0[pdc_i2c_read_data[i].ofs])) {
1123+
dev_err(host->dev,
1124+
"Failed in i2c read at index %d: device=%#x, reg=%#x\n",
1125+
i, PDC_DIMM0_SPD_DEV_ADDRESS, pdc_i2c_read_data[i].reg);
1126+
return -EIO;
1127+
}
11231128

11241129
data |= (spd0[4] - 8) | ((spd0[21] != 0) << 3) | ((spd0[3]-11) << 4);
11251130
data |= ((spd0[17] / 4) << 6) | ((spd0[5] / 2) << 7) |
@@ -1284,6 +1289,8 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
12841289

12851290
/* Programming DIMM0 Module Control Register (index_CID0:80h) */
12861291
size = pdc20621_prog_dimm0(host);
1292+
if (size < 0)
1293+
return size;
12871294
dev_dbg(host->dev, "Local DIMM Size = %dMB\n", size);
12881295

12891296
/* Programming DIMM Module Global Control Register (index_CID0:88h) */

0 commit comments

Comments
 (0)