Received: by 2002:a5d:6790:0:0:0:0:0 with SMTP id v16csp4264947wru; Tue, 2 Jul 2019 14:54:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/GBTKYUYQVnPYml//LP1CZZfD3WiKKRBQtsFG6aQpAtflcvyNVfkpbKW8RucFIiEMLRdO X-Received: by 2002:a17:906:e91:: with SMTP id p17mr5905384ejf.217.1562104441160; Tue, 02 Jul 2019 14:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562104441; cv=none; d=google.com; s=arc-20160816; b=Re22J+3JBGmvpZXC3mzT2+z7k8iSwoTmejhDews0m/RvRByF42uzShWrTjI5GUL9da uxRx/gGnlr0PlQRTCQ/x5VOyW5MwlSB1QgawI6lAFPMt2MM7rfu19ybMwGN705lYJkCH ntfe/jnvlkwJcgy9w7M44NaaTROyGzWApYr9qfRNXK5Iggc5R3kV1Yds2W1lfwiCizfd vCfc6NqhkR9CsFPQLuwAUVTFs+MlL1UdxBoc3QQFzaStCHecrA0SRdfJQo/QjC/d4or9 hbc7cObvYNE4mU79OGGLo694xKpatJ6hBcc33MD4DFFTk0GChe35YWqZuaz2OZPQBDGh woBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:mime-version:user-agent :references:message-id:in-reply-to:to:from:date; bh=lXR3qZeUBi2HBtHpZHd/B47rPacP/HYPw/OvUskbrbY=; b=wxieYqPCGfW343X8rVMqhAcak0nAg9h3DlqyFM8WrjbHxD/yfBtdn0ybhTj5qjKFxi ohEPfwElvC0ku34nlfCC2OGP+qDShFlzJ8V/JQ9erpuvghN4F2yWxNJAbtL4eUtoWDrj HzjKUnTkgnohUb6ReqUgkUoTZB52X66CxWyt46Z3A0+KpCWFHvKKvhEzTE1iYLnTaVvP csQ4aLuc44sS7lAfttjkfEe2kZmt1w2/5vGggh4a2rZUmd7F3AAI1KR3o2N30OV8PaMa ie67cR6eyH7SG+lva/R711FvaoHlv3TNLTwvXXJH3iTNm2GNXkEYDcYg/UtWT7kr3S3f btmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z50si233855edb.13.2019.07.02.14.54.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2019 14:54:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1]:57834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiQiu-0004lz-9I for alex.bennee@linaro.org; Tue, 02 Jul 2019 17:54:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53922) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiQiD-0004jR-Kd for qemu-arm@nongnu.org; Tue, 02 Jul 2019 17:53:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hiQi9-0006Ea-01 for qemu-arm@nongnu.org; Tue, 02 Jul 2019 17:53:14 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:14065) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hiQi8-00063e-F7; Tue, 02 Jul 2019 17:53:12 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 2A5337456B8; Tue, 2 Jul 2019 23:52:53 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id EDA597456B7; Tue, 2 Jul 2019 23:52:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id E247274569A; Tue, 2 Jul 2019 23:52:52 +0200 (CEST) Date: Tue, 2 Jul 2019 23:52:52 +0200 (CEST) From: BALATON Zoltan To: Peter Maydell In-Reply-To: <20190702163844.20458-1-peter.maydell@linaro.org> Message-ID: References: <20190702163844.20458-1-peter.maydell@linaro.org> User-Agent: Alpine 2.21.9999 (BSF 287 2018-06-16) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:738:2001:2001::2001 Subject: Re: [Qemu-arm] [PATCH for-4.1] hw/i2c/bitbang_i2c: Use in-place rather than malloc'd bitbang_i2c_interface struct X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: sQjjj8WgdET2 On Tue, 2 Jul 2019, Peter Maydell wrote: > 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 > --- > This isn't the only problem with this code : it is also > missing reset and migration handling and generally looks like > it needs proper conversion to QOM somehow. But this will shut > the patchew complaints up and seems ok for 4.1. > > Disclaimer: checked only that the leak-sanitizer is now happy > and with a 'make check'. I've tested the ppc4xx and ati-vga parts with AROS and MorphOS and these can still access i2c devices so I think it works. > --- > hw/display/ati_int.h | 2 +- > include/hw/i2c/bitbang_i2c.h | 38 ++++++++++++++++++++++++++++- > include/hw/i2c/ppc4xx_i2c.h | 2 +- > hw/display/ati.c | 7 +++--- > hw/i2c/bitbang_i2c.c | 47 +++--------------------------------- > hw/i2c/ppc4xx_i2c.c | 6 ++--- > hw/i2c/versatile_i2c.c | 8 +++--- > 7 files changed, 53 insertions(+), 57 deletions(-) > > diff --git a/hw/display/ati_int.h b/hw/display/ati_int.h > index 9b67d0022ad..31a1927b3ec 100644 > --- a/hw/display/ati_int.h > +++ b/hw/display/ati_int.h > @@ -88,7 +88,7 @@ typedef struct ATIVGAState { > uint16_t cursor_size; > uint32_t cursor_offset; > QEMUCursor *cursor; > - bitbang_i2c_interface *bbi2c; > + bitbang_i2c_interface bbi2c; > MemoryRegion io; > MemoryRegion mm; > ATIVGARegs regs; > diff --git a/include/hw/i2c/bitbang_i2c.h b/include/hw/i2c/bitbang_i2c.h > index 3a7126d5dee..92334e9016a 100644 > --- a/include/hw/i2c/bitbang_i2c.h > +++ b/include/hw/i2c/bitbang_i2c.h > @@ -8,7 +8,43 @@ typedef struct bitbang_i2c_interface bitbang_i2c_interface; Maybe this typedef ^^^ can now be moved to the struct below instead of coming first (or even written in the same line as typedef struct { } bitbang_i2c_interface; as there is no need to have both struct bitbang_i2c_interface and the typedeffed name available). But I don't really mind, so Reviewed-by: BALATON Zoltan Thanks for fixing this. Regards, BALATON Zoltan > #define BITBANG_I2C_SDA 0 > #define BITBANG_I2C_SCL 1 > > -bitbang_i2c_interface *bitbang_i2c_init(I2CBus *bus); > +typedef enum bitbang_i2c_state { > + STOPPED = 0, > + SENDING_BIT7, > + SENDING_BIT6, > + SENDING_BIT5, > + SENDING_BIT4, > + SENDING_BIT3, > + SENDING_BIT2, > + SENDING_BIT1, > + SENDING_BIT0, > + WAITING_FOR_ACK, > + RECEIVING_BIT7, > + RECEIVING_BIT6, > + RECEIVING_BIT5, > + RECEIVING_BIT4, > + RECEIVING_BIT3, > + RECEIVING_BIT2, > + RECEIVING_BIT1, > + RECEIVING_BIT0, > + SENDING_ACK, > + SENT_NACK > +} bitbang_i2c_state; > + > +struct bitbang_i2c_interface { > + I2CBus *bus; > + bitbang_i2c_state state; > + int last_data; > + int last_clock; > + int device_out; > + uint8_t buffer; > + int current_addr; > +}; > + > +/** > + * bitbang_i2c_init: in-place initialize the bitbang_i2c_interface struct > + */ > +void bitbang_i2c_init(bitbang_i2c_interface *s, I2CBus *bus); > int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level); > > #endif