From 9e41bade85ef338afd983c109368d1bbbe931f80 Mon Sep 17 00:00:00 2001 From: Alastair D'Silva Date: Tue, 27 Dec 2016 14:59:29 +0000 Subject: hw/i2c: Add a NULL check for i2c slave init callbacks Add a NULL check for i2c slave init callbacks, so that we no longer need to implement empty init functions. Signed-off-by: Alastair D'Silva Message-id: 20161202054617.6749-4-alastair@au1.ibm.com Reviewed-by: Peter Maydell [PMM: squashed in later tweak from Alistair to if() phrasing] Signed-off-by: Peter Maydell --- hw/i2c/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'hw/i2c/core.c') diff --git a/hw/i2c/core.c b/hw/i2c/core.c index abd4c4cddb..e40781ea3b 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -260,7 +260,11 @@ static int i2c_slave_qdev_init(DeviceState *dev) I2CSlave *s = I2C_SLAVE(dev); I2CSlaveClass *sc = I2C_SLAVE_GET_CLASS(s); - return sc->init(s); + if (sc->init) { + return sc->init(s); + } + + return 0; } DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr) -- cgit v1.2.3