From patchwork Thu Jan 25 13:43:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 125858 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1138799ljf; Thu, 25 Jan 2018 06:11:09 -0800 (PST) X-Google-Smtp-Source: AH8x225DjuSBDOjpRS+C6bRKvspclPnKKZB3vUpivhvd0v6VcIGR+hkTXMUEUQGU0AvuTuXVozzW X-Received: by 10.129.3.69 with SMTP id 66mr8349552ywd.38.1516889469443; Thu, 25 Jan 2018 06:11:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516889469; cv=none; d=google.com; s=arc-20160816; b=CL5sIE9sPiXCTm3CN6s3SbYxnJcKTNY1Onbq9ZPw2ip/issHgE2Uouf8B7GFibwhPx pepQgs56bJU7MLjHE1pRpn6WIzjmgmjYr2ctDlOx9MMPdQnbR5nCg9Zg3XgCOoGvgEet cyZNxsJkci5r72bKUtT9rZfPQlYmwegLZnEwuXl4wSlhuC9LQ1/8uZKT0hCHJgvD0Dyp DbDt1yHH2XAxgECFfBBrXXl9OZFi0lmxBqBedlt1VOcOvpvCFknY71kSniwzwR7O5jvT z8TG+axiGgzJ4YlUV6HJuT3pKhAqMjNd6nJQapFZL65IgPmKmGny233hxw+RccK0buFe OwNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=/GGz/9e+4eEJ6EWCr8Na2Dba03D8IbvX72jBzwNEFjs=; b=VwcgE+mF59wOaaJ3gELX3MXRCdI83srnvWizmuiUQmy7YE9oKlmyZM1dkbXh4mBX5D uD+CSQv4CtwCkc5WoOpRM/bOaKxHldZwx1szlQWQVx5UbuhQNYNlvdX4RFegyEeBImmy gq4+zu7LMofsezLnDu85blKIzDKWCxEqAYz+qbN6JF3skrWkBI/Y5bCHejA5JUzIblkv bIPIHewsrZYH90bjMYm7W9UlXxYEVa9rlf6/n7HwUMg4sz9UgYDvcCNZpDxDsEBwgrn0 c33FpVlTp8ZkO3NV8BmMnY0w39uPbgAhtaBBaWO8I2m+jk4HGKbvBEAiRnND+zc4+Kf5 Mz1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z7si494674ywj.349.2018.01.25.06.11.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 25 Jan 2018 06:11:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeiFA-0007Ew-SF for patch@linaro.org; Thu, 25 Jan 2018 09:11:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eehom-0003Lu-RJ for qemu-devel@nongnu.org; Thu, 25 Jan 2018 08:43:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eehol-0003Dx-W3 for qemu-devel@nongnu.org; Thu, 25 Jan 2018 08:43:52 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:45996) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eehol-0003Co-OW for qemu-devel@nongnu.org; Thu, 25 Jan 2018 08:43:51 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eehok-0006yS-Eb for qemu-devel@nongnu.org; Thu, 25 Jan 2018 13:43:50 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 25 Jan 2018 13:43:28 +0000 Message-Id: <1516887809-6265-21-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516887809-6265-1-git-send-email-peter.maydell@linaro.org> References: <1516887809-6265-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 20/21] 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Francisco Iglesias 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 Message-id: 20180124215708.30400-1-frasse.iglesias@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/ssi/xilinx_spips.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.7.4 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 +#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 = 0; - uint8_t tx_rx[num_effective_busses(s)]; + uint8_t tx_rx[MAX_NUM_BUSSES] = { 0 }; uint8_t dummy_cycles = 0; uint8_t addr_length; @@ -1221,6 +1224,19 @@ static void xilinx_spips_realize(DeviceState *dev, Error **errp) DB_PRINT_L(0, "realized spips\n"); + 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 = g_new(SSIBus *, s->num_busses); for (i = 0; i < s->num_busses; ++i) { char bus_name[16];