From nobody Tue Apr 30 02:45:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516831160598101.0462219281219; Wed, 24 Jan 2018 13:59:20 -0800 (PST) Received: from localhost ([::1]:49178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeT4g-00006h-DQ for importer@patchew.org; Wed, 24 Jan 2018 16:59:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeT2k-0007L1-Ok for qemu-devel@nongnu.org; Wed, 24 Jan 2018 16:57:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eeT2h-0005iy-Nf for qemu-devel@nongnu.org; Wed, 24 Jan 2018 16:57:18 -0500 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:33948) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eeT2h-0005hb-GS for qemu-devel@nongnu.org; Wed, 24 Jan 2018 16:57:15 -0500 Received: by mail-lf0-x244.google.com with SMTP id k19so7185872lfj.1 for ; Wed, 24 Jan 2018 13:57:14 -0800 (PST) Received: from localhost.localdomain (host-95-192-238-137.mobileonline.telia.com. [95.192.238.137]) by smtp.gmail.com with ESMTPSA id v17sm224721ljc.43.2018.01.24.13.57.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 13:57:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=AFjytAjbaw9c4YevwzqqN/rzGmKjbFZUk233kPWXvP0=; b=apAR0gx14IRYXfTJa0bkLx0jVEpzUNsLYtXDAdYtg1byep5WgueTezgaKe6LdLequo 2ygEDzhf0YGo4WebJVtg41qIWvlu9sJFWuUlnIuznF5wASCkui3VZTJI0JZF222L0KLC utF6k4HwxKRxn8m75p+dbLbdvXt4lRDHk3tGtGJAKT8HKHLvxwTTsN7fRjlurE0Nz2Nc zGP3MGm3nAaiBf40Dq/lqAHGBT8e4czNoLBRfaV3vBhRPmW9IPghZgKOZmk+lstOU2a5 BFsG/7y9tGMYBIU3KQ3hqKJ2bDvWNPCokO1dITkvxBg24K1b3ACkGug7K6AhMZRaScCO dGxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AFjytAjbaw9c4YevwzqqN/rzGmKjbFZUk233kPWXvP0=; b=ZErXWPoGw5eHhUBgY0J2m1jfu7gokURftEJfG/8J3bIXP8n3lNeKfI2YDGR7WOJqdI DKblHDeGJDNiELD0CpvAxdnCyTvDVMYonW9xaiEK4pzu1AYBBeAktt4H1zdZ8eML2pnz 9+6CXm49mTAXDLBV1jZB6ZV2jhEBbJ1yo2wgSFcjHcrxOZKTRMeNaTi2ZM+6nnbiTMhR uMizFue9HzswA8IMs9MlDccqGwPpn3RwuNxDFXL5vbIEdUBuyuCXEKguyhKfue5s7ISj FQVvObfBdDvvoCQz4eEu9Lijj8T7jELNcWpNg1e0WAmcO1q2savq9+t/blJrp7tvWxUc Ajpg== X-Gm-Message-State: AKwxytevOfQi0t2QFtPvSXkG50DBZEh53Mrp3CI3IeUq1QZphlU6VYXw SardHCdycUSQB2SQRVqkMwNDgA== X-Google-Smtp-Source: AH8x22586mjvA75cbAKR47fESBRNgfJ9UBFJr+ygfCsOPQ59dxPkosSUnbiQhccuuUFh8KNuCuZPAA== X-Received: by 10.25.229.146 with SMTP id i18mr4633312lfk.66.1516831033186; Wed, 24 Jan 2018 13:57:13 -0800 (PST) From: Francisco Iglesias To: qemu-devel@nongnu.org Date: Wed, 24 Jan 2018 22:57:08 +0100 Message-Id: <20180124215708.30400-1-frasse.iglesias@gmail.com> X-Mailer: git-send-email 2.9.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::244 Subject: [Qemu-devel] [PATCH v3] xilinx_spips: Correct usage of an uninitialized local variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, edgari@xilinx.com, alistai@xilinx.com, francisco.iglesias@feimtech.se Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Coverity found that the variable tx_rx in the function xilinx_spips_flush_txfifo was being used uninitialized (CID 1383841). This patch corrects this by always initializing tx_rx to zeros. Signed-off-by: Francisco Iglesias --- v3. Change to report errors on the num_busses property via the Error** parameter when realizing the devices. --- v2. Add a sanity check on the num_busses property when realizing the devices. --- hw/ssi/xilinx_spips.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c index 85c5d0c..8af36ca 100644 --- a/hw/ssi/xilinx_spips.c +++ b/hw/ssi/xilinx_spips.c @@ -210,6 +210,9 @@ #define SNOOP_NONE 0xEE #define SNOOP_STRIPING 0 =20 +#define MIN_NUM_BUSSES 1 +#define MAX_NUM_BUSSES 2 + static inline int num_effective_busses(XilinxSPIPS *s) { return (s->regs[R_LQSPI_CFG] & LQSPI_CFG_SEP_BUS && @@ -573,7 +576,7 @@ static void xilinx_spips_flush_txfifo(XilinxSPIPS *s) for (;;) { int i; uint8_t tx =3D 0; - uint8_t tx_rx[num_effective_busses(s)]; + uint8_t tx_rx[MAX_NUM_BUSSES] =3D { 0 }; uint8_t dummy_cycles =3D 0; uint8_t addr_length; =20 @@ -1221,6 +1224,19 @@ static void xilinx_spips_realize(DeviceState *dev, E= rror **errp) =20 DB_PRINT_L(0, "realized spips\n"); =20 + if (s->num_busses > MAX_NUM_BUSSES) { + error_setg(errp, + "requested number of SPI busses %u exceeds maximum %d", + s->num_busses, MAX_NUM_BUSSES); + return; + } + if (s->num_busses < MIN_NUM_BUSSES) { + error_setg(errp, + "requested number of SPI busses %u is below minimum %d", + s->num_busses, MIN_NUM_BUSSES); + return; + } + s->spi =3D g_new(SSIBus *, s->num_busses); for (i =3D 0; i < s->num_busses; ++i) { char bus_name[16]; --=20 2.9.3