From 76364fb66b0cff510659f4051b6431174860cec7 Mon Sep 17 00:00:00 2001 From: Felix Held Date: Thu, 15 Dec 2022 15:35:35 +0100 Subject: 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 Change-Id: I06b6005cee0c5c43855cb5b388a9911fc286c984 Reviewed-on: https://review.coreboot.org/c/coreboot/+/70828 Tested-by: build bot (Jenkins) Reviewed-by: Fred Reitberger Reviewed-by: Eric Lai --- src/drivers/i2c/designware/dw_i2c.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/drivers/i2c') 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 = { -- cgit v1.2.3