device/i2c_bus.c: Check pointer for NULL before using it

Found-by: Coverity Scan #1489753
Signed-off-by: Martin Roth <gaumless@gmail.com>
Change-Id: I4f3794cf17875cdb35010c79a6537a4c13a18224
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78615
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-by: Felix Singer <service+coreboot-gerrit@felixsinger.de>
This commit is contained in:
Martin Roth 2023-10-23 17:47:03 -06:00 committed by Felix Singer
parent 9bcbdbf9e4
commit fab89b34e7

View file

@ -11,6 +11,8 @@
bool i2c_dev_detect(struct device *dev, unsigned int addr)
{
struct i2c_msg seg = { .flags = 0, .slave = addr, .buf = NULL, .len = 0 };
if (!dev)
return false;
return dev->ops->ops_i2c_bus->transfer(dev, &seg, 1) == 0;
}