aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/i2c
diff options
context:
space:
mode:
authorFelix Held <felix-coreboot@felixheld.de>2022-12-15 15:35:35 +0100
committerFred Reitberger <reitbergerfred@gmail.com>2022-12-16 15:33:00 +0000
commit76364fb66b0cff510659f4051b6431174860cec7 (patch)
tree02081277d291435e1b3c399ea07b64874be92e9c /src/drivers/i2c
parentd832bda32bd54b65c41db4ae945fb6a993ca055b (diff)
drivers/i2c/designware/dw_i2c: handle bus < 0 in dw_i2c_dev_transfer
dw_i2c_soc_dev_to_bus will return -1 if it failed to find an I2C bus number for a device. In this case return -1 instead of implicitly casting the -1 to an unsigned int and passing that as bus number to dw_i2c_transfer. The dw_i2c_base_address call inside _dw_i2c_transfer already ended up handling this error case correctly, but better handle the error more directly. Signed-off-by: Felix Held <felix-coreboot@felixheld.de> Change-Id: I06b6005cee0c5c43855cb5b388a9911fc286c984 Reviewed-on: https://review.coreboot.org/c/coreboot/+/70828 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Fred Reitberger <reitbergerfred@gmail.com> Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
Diffstat (limited to 'src/drivers/i2c')
-rw-r--r--src/drivers/i2c/designware/dw_i2c.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/drivers/i2c/designware/dw_i2c.c b/src/drivers/i2c/designware/dw_i2c.c
index 1e3163a736..a08036720b 100644
--- a/src/drivers/i2c/designware/dw_i2c.c
+++ b/src/drivers/i2c/designware/dw_i2c.c
@@ -857,7 +857,12 @@ void dw_i2c_acpi_fill_ssdt(const struct device *dev)
static int dw_i2c_dev_transfer(struct device *dev,
const struct i2c_msg *msg, size_t count)
{
- return dw_i2c_transfer(dw_i2c_soc_dev_to_bus(dev), msg, count);
+ int bus = dw_i2c_soc_dev_to_bus(dev);
+ if (bus < 0) {
+ printk(BIOS_ERR, "Invalid I2C bus number.\n");
+ return -1;
+ }
+ return dw_i2c_transfer(bus, msg, count);
}
const struct i2c_bus_operations dw_i2c_bus_ops = {