From patchwork Wed Jan 17 21:34:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francisco Iglesias X-Patchwork-Id: 862606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AJQMJ3QE"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zML3l0jYXz9t3w for ; Thu, 18 Jan 2018 08:35:29 +1100 (AEDT) Received: from localhost ([::1]:35753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebvMk-00060T-U5 for incoming@patchwork.ozlabs.org; Wed, 17 Jan 2018 16:35:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebvMP-00060C-Ul for qemu-devel@nongnu.org; Wed, 17 Jan 2018 16:35:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebvMP-00027U-6e for qemu-devel@nongnu.org; Wed, 17 Jan 2018 16:35:05 -0500 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:33094) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebvMO-00026s-VV for qemu-devel@nongnu.org; Wed, 17 Jan 2018 16:35:05 -0500 Received: by mail-lf0-x242.google.com with SMTP id t139so9083417lff.0 for ; Wed, 17 Jan 2018 13:35:04 -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=sMpmwUTezepkoFO2bBQpY56cVWeuLtLUoKqsxJyp4lI=; b=AJQMJ3QEPt0urQIOEzPwDu9gLPInOlyM3JM5FHBk6Ddog7yOLM9HLO99F8ORJ+imEk JVqmCvyiT/2sSV+qvhRV1y2bS/qLcQG8z2syFsPQ7dP09xeLIrByIV21t6qvTYy8uXCn JrSNoW6+HZglTmUacIbokiROiqQ+QF/5gMlnP04+bxBGAPXfIzOfn3QHx46LNMlpXl5D V459rvyuGtO7wDVX6WzlCGGGpp8Cv1MIHUdXyVp+8GnOmsdQESduNGXlxMTXhkw+J3i0 oGiMtRqEloAl6dv9PHlbPOp9xLgTYiFVRnTnH+nCOlxTFPAn9V6AKQRq1fqzcfdWLe1R +Vvw== 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=sMpmwUTezepkoFO2bBQpY56cVWeuLtLUoKqsxJyp4lI=; b=oa+v1AkpqZqtedsxUUJ4kqa7tFnbAPOtMbS/7JFR+ysv+2811vyqHSD8D6WyEsgI0U hh0ejExO5nBjfirxUb9t5/TX8sw97IaXRrudlrdrCQlhtDzudyEaVOg1xJ5RcATn50UF CvJE4hVr/dTzRAYY1GYtAFBqR2/Reqmolmj4m0N7cBazUObq6Sqq9JAYTuVglnQSXkqK oS9h7DcE5m8KOn9A1cizMO2sYtdZdscqclkGyXjI/YQTt/0/WVBIBTdKd+bHixynusm1 OhilzvU/DPuWtBdivRBrmHySd5rdEupKESKMbI8T0FsFRFMNhjxXhNMKbn2uThcudlD2 PVQQ== X-Gm-Message-State: AKGB3mIGcSvmgGgbMOW5PTgJW2R+drJ+cRxAEhA4/N+ZzAqh3Kn4WUtz D4b8NyOtHztlf1KhEg3ZN6cAvfFP X-Google-Smtp-Source: ACJfBoti7mUiEqFI5jaiFQkOYqhppWPNZTO3tMvNUTafetfldOirkyXHOXTYwLzrwCgqTnZZ1KQ2VA== X-Received: by 10.46.1.33 with SMTP id 33mr21607341ljb.128.1516224903045; Wed, 17 Jan 2018 13:35:03 -0800 (PST) Received: from localhost.localdomain ([2a00:801:381:80a7:748b:b075:ea53:9d41]) by smtp.gmail.com with ESMTPSA id w143sm945280lff.52.2018.01.17.13.35.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 13:35:02 -0800 (PST) From: Francisco Iglesias To: qemu-devel@nongnu.org Date: Wed, 17 Jan 2018 22:34:58 +0100 Message-Id: <20180117213458.17560-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::242 Subject: [Qemu-devel] [PATCH v2] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- v2. Add a sanity check on the num_busses property when realizing the devices. --- hw/ssi/xilinx_spips.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c index 85c5d0c..12f1de9 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,14 @@ static void xilinx_spips_realize(DeviceState *dev, Error **errp) DB_PRINT_L(0, "realized spips\n"); + if (s->num_busses < MIN_NUM_BUSSES || s->num_busses > MAX_NUM_BUSSES) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid number of spi busses requested, " + "will default to use one bus\n", + __func__); + s->num_busses = 1; + } + s->spi = g_new(SSIBus *, s->num_busses); for (i = 0; i < s->num_busses; ++i) { char bus_name[16];