diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2019-07-02 17:38:44 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-07-03 10:51:35 +0200 |
commit | 41742927ee37527462a13160380860653d4f1c84 (patch) | |
tree | 41744da1198ff76741c61bba6a7aa33e95b59f04 /hw/display/ati.c | |
parent | b0ee78ff31617937f44161bde7515a67c88748c7 (diff) | |
download | qemu-41742927ee37527462a13160380860653d4f1c84.zip qemu-41742927ee37527462a13160380860653d4f1c84.tar.gz qemu-41742927ee37527462a13160380860653d4f1c84.tar.bz2 |
hw/i2c/bitbang_i2c: Use in-place rather than malloc'd bitbang_i2c_interface struct
Currently the bitbang_i2c_init() function allocates a
bitbang_i2c_interface struct which it returns. This is unfortunate
because it means that if the function is used from a DeviceState
init method then the memory will be leaked by an "init then delete"
cycle, as used by the qmp/hmp commands that list device properties.
Since three out of four of the uses of this function are in
device init methods, switch the function to do an in-place
initialization of a struct that can be embedded in the
device state struct of the caller.
This fixes LeakSanitizer leak warnings that have appeared in the
patchew configuration (which only tries to run the sanitizers
for the x86_64-softmmu target) now that we use the bitbang-i2c
code in an x86-64 config.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu>
Tested-by: BALATON Zoltan <balaton@eik.bme.hu>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20190702163844.20458-1-peter.maydell@linaro.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/display/ati.c')
-rw-r--r-- | hw/display/ati.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/hw/display/ati.c b/hw/display/ati.c index 0cb1173..c1d9d15 100644 --- a/hw/display/ati.c +++ b/hw/display/ati.c @@ -538,7 +538,7 @@ static void ati_mm_write(void *opaque, hwaddr addr, break; case GPIO_DVI_DDC: if (s->dev_id != PCI_DEVICE_ID_ATI_RAGE128_PF) { - s->regs.gpio_dvi_ddc = ati_i2c(s->bbi2c, data, 0); + s->regs.gpio_dvi_ddc = ati_i2c(&s->bbi2c, data, 0); } break; case GPIO_MONID ... GPIO_MONID + 3: @@ -554,7 +554,7 @@ static void ati_mm_write(void *opaque, hwaddr addr, */ if ((s->regs.gpio_monid & BIT(25)) && addr <= GPIO_MONID + 2 && addr + size > GPIO_MONID + 2) { - s->regs.gpio_monid = ati_i2c(s->bbi2c, s->regs.gpio_monid, 1); + s->regs.gpio_monid = ati_i2c(&s->bbi2c, s->regs.gpio_monid, 1); } } break; @@ -856,7 +856,7 @@ static void ati_vga_realize(PCIDevice *dev, Error **errp) /* ddc, edid */ I2CBus *i2cbus = i2c_init_bus(DEVICE(s), "ati-vga.ddc"); - s->bbi2c = bitbang_i2c_init(i2cbus); + bitbang_i2c_init(&s->bbi2c, i2cbus); I2CSlave *i2cddc = I2C_SLAVE(qdev_create(BUS(i2cbus), TYPE_I2CDDC)); i2c_set_slave_address(i2cddc, 0x50); @@ -885,7 +885,6 @@ static void ati_vga_exit(PCIDevice *dev) ATIVGAState *s = ATI_VGA(dev); graphic_console_close(s->vga.con); - g_free(s->bbi2c); } static Property ati_vga_properties[] = { |