[Qemu-devel] [PATCH 01/11] smbus: add a NULL check for SMBusDeviceClass::init callbacks

Philippe Mathieu-Daudé posted 11 patches 7 years, 9 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 01/11] smbus: add a NULL check for SMBusDeviceClass::init callbacks
Posted by Philippe Mathieu-Daudé 7 years, 9 months ago
ensure SMBusDeviceClass::init is set before calling it

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/i2c/smbus.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
index 2d1b79a689..a90d65ef37 100644
--- a/hw/i2c/smbus.c
+++ b/hw/i2c/smbus.c
@@ -207,7 +207,11 @@ static int smbus_device_init(I2CSlave *i2c)
     SMBusDevice *dev = SMBUS_DEVICE(i2c);
     SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
 
-    return sc->init(dev);
+    if (sc->init) {
+        return sc->init(dev);
+    }
+
+    return 0;
 }
 
 /* Master device commands.  */
-- 
2.15.1


Re: [Qemu-devel] [PATCH 01/11] smbus: add a NULL check for SMBusDeviceClass::init callbacks
Posted by Eduardo Habkost 7 years, 9 months ago
On Tue, Jan 16, 2018 at 10:15:45AM -0300, Philippe Mathieu-Daudé wrote:
> ensure SMBusDeviceClass::init is set before calling it
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

-- 
Eduardo