From nobody Fri Mar 29 13:42:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590148311; cv=none; d=zohomail.com; s=zohoarc; b=eEHlCdvu97Y6Rj+BpcS43K3RdtSVv6z5yw3SZl6vv/NFyr4xkpNiktxHIGwfhsu5lI2Cx5Naz3cp5ZbPlBZ0V1E9FwKVwPUe3NIgSjIuVEFJcvIuZNQrtxpn6gURyh8msOMh+xYxDAKT3kAFGHNxbXAGYaFbn+xx9n0fCl13Fak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590148311; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=PeC4/6Bbi6vdN3UI8jEqDsfyPpIFP8TzdU+CFw09D9g=; b=jtpaWKkSuLZ/lDuihoACvH2z4zOThLEZ+M8QWud3tZfefHfTZ11MfZJTg3yEGhY6jerv3BSX9K58IBnDi0oV4mRA0WTzvcQzVZN4KaT6B9pEyupOjRjnEQhuQxWkSupQi40auriWOuxQY9WiaM9ynx8M7hMnRtBrw2tCYGbo86M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590148311176589.5775244968223; Fri, 22 May 2020 04:51:51 -0700 (PDT) Received: from localhost ([::1]:54698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jc6DN-0004Ja-M4 for importer@patchew.org; Fri, 22 May 2020 07:51:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jc6Cb-00037V-Fj; Fri, 22 May 2020 07:51:01 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jc6Ca-0004cD-Md; Fri, 22 May 2020 07:51:01 -0400 Received: by mail-wm1-x341.google.com with SMTP id n18so9542725wmj.5; Fri, 22 May 2020 04:50:59 -0700 (PDT) Received: from eden-linux.lan (bzq-109-66-59-205.red.bezeqint.net. [109.66.59.205]) by smtp.gmail.com with ESMTPSA id m3sm9237640wrn.96.2020.05.22.04.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 04:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PeC4/6Bbi6vdN3UI8jEqDsfyPpIFP8TzdU+CFw09D9g=; b=ADKhULdRIiNbFVy02LOfvd5zmaNxrf7Z4KbicuV+8XD0qVronN+0P7D8bxRubcT5MM lWe7eLoX2Eb4Or4Q0zJ6T6ArEMh1eYC32ShM0c6MP6rKW9R7pWDB34B5CUABBzCp92Ji 9nQR88FRqpTUH4zD68crT6+oDHRVwGLDg8ZCJbpMBoLRpe5OenbHpM/hhTuwZpcb9tQa UmkdCP/VjIKuPQYmwXi85DXXhjgcL+erK/2wmhE1wu+F7rOmFsMmkEhnjsLb8tvd/Imy GLU3jU/VgzJTlltHe0niEOmj5z4YumfyGBns/DiG0YZJGSUH5ezQNKSOHX2V4AQSF3Wr NlNg== 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:in-reply-to :references; bh=PeC4/6Bbi6vdN3UI8jEqDsfyPpIFP8TzdU+CFw09D9g=; b=FcSSTqG3czcPSBYdlNImhyfOd0hwG6LzsGdGZRJaogZrTtn6tTOUYQpEH5bgEtFD74 UPOSFdplzpgPTsattl72d3UgVGgImxlYfnm2YfBfmtszDF2Tz5+kHJrXM9Wo+NYNoqNv wnfhayVcoecU5uQrFTzDj2NTVvQ+f0KnpHNTH7wxbUvoIkzVrpZHwT8T9B6XG4t6lvHT R4QPL6fNsP1lbwSPDJcYCGf3cAdfth1Opu47s3knpqD895hAJP60hnwR1DIKlgaDVOb4 FMvgzK6dUZ7OHkZhXV60IQLRE4+JJHqnuQooxE8I+NQGtsa4hT1Q02Dpqs94bmXMj0os rVlg== X-Gm-Message-State: AOAM533qIcqRZdVPwayLAe3AzPxgHAMouUZmVy91EQ5RwGhIeVbkHFtI urBd/kcEWbpdmjYHHp06qFw= X-Google-Smtp-Source: ABdhPJzzRmK9cbyw8ZhU+vxusWoRYy4Q85ElqbfHsOOYpIrcUHzI9TvsXvPlT/EpZah+81CQG6fLNw== X-Received: by 2002:a1c:3286:: with SMTP id y128mr12994051wmy.119.1590148258773; Fri, 22 May 2020 04:50:58 -0700 (PDT) From: Eden Mikitas To: peter.maydell@linaro.org Subject: [PATCH 1/2] hw/ssi/imx_spi: changed while statement to prevent underflow Date: Fri, 22 May 2020 14:50:35 +0300 Message-Id: <20200522115036.31516-2-e.mikitas@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522115036.31516-1-e.mikitas@gmail.com> References: <20200522115036.31516-1-e.mikitas@gmail.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::341; envelope-from=e.mikitas@gmail.com; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, alistair@alistair23.me, qemu-devel@nongnu.org, jcd@tribudubois.net, qemu-arm@nongnu.org, peter.chubb@nicta.com.au, e.mikitas@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The while statement in question only checked if tx_burst is not 0. tx_burst is a signed int, which is assigned the value put by the guest driver in ECSPI_CONREG. The burst length can be anywhere between 1 and 4096, and since tx_burst is always decremented by 8 it could possibly underflow, causing an infinite loop. Signed-off-by: Eden Mikitas Reviewed-by: Alistair Francis --- hw/ssi/imx_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ssi/imx_spi.c b/hw/ssi/imx_spi.c index 2dd9a631e1..6fef5c7958 100644 --- a/hw/ssi/imx_spi.c +++ b/hw/ssi/imx_spi.c @@ -182,7 +182,7 @@ static void imx_spi_flush_txfifo(IMXSPIState *s) =20 rx =3D 0; =20 - while (tx_burst) { + while (tx_burst > 0) { uint8_t byte =3D tx & 0xff; =20 DPRINTF("writing 0x%02x\n", (uint32_t)byte); --=20 2.17.1 From nobody Fri Mar 29 13:42:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590148381; cv=none; d=zohomail.com; s=zohoarc; b=hRSN1/n9PYmo6SzHVMh2fUswLc0pDjvF57AqKUD5hI/dpmwQtwiN+R3CsLfEHHTXWGSuev7ZFbLNfJqGX59bdmuuYoEArwEMUXiopCVsAHHwYKlt5VdmuXZ3p8e3rIWBBPKftINq7C2dI45bu29H2gXJaw3gm9XjAXJJhEAHpCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590148381; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ATw2AQdt0tMLUBC524HixfrRhPl572ZT8HtNHYF2xvw=; b=d45fCjnZWUNVA2+lVyrcgugotz8EABa4pmS0MMZJYDZdBynBvWjgkBa8bgE3/J7aDh5vbTekGk2RXeNKXp0nZs37+855RUKFWMrlc0m15eFMMKpAupEIrRaCYmr58K8srrsxm5J3EWtCe6Beqypo8Hqn+KhbVo6ah6kCNoHRr1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590148381120510.82913360944576; Fri, 22 May 2020 04:53:01 -0700 (PDT) Received: from localhost ([::1]:58008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jc6EV-0005pH-Rt for importer@patchew.org; Fri, 22 May 2020 07:52:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jc6Cg-0003JP-9Q; Fri, 22 May 2020 07:51:06 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:55743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jc6Cf-0004cP-Bl; Fri, 22 May 2020 07:51:05 -0400 Received: by mail-wm1-x342.google.com with SMTP id f13so8374141wmc.5; Fri, 22 May 2020 04:51:04 -0700 (PDT) Received: from eden-linux.lan (bzq-109-66-59-205.red.bezeqint.net. [109.66.59.205]) by smtp.gmail.com with ESMTPSA id m3sm9237640wrn.96.2020.05.22.04.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 04:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ATw2AQdt0tMLUBC524HixfrRhPl572ZT8HtNHYF2xvw=; b=dxBVMRpg+o021KVHz5A8ks0zutiZTujaLqO42y2jmH0xWCjP6saCePCEciz/aotlv2 auN9x41lY5UXjVFoi2hQdFPA5caXoKjxjqXL0gpC1cCvwCQVeCCQ+VHbAnxfAMkWsnv5 8BLDHzi6xsH3htbgiKiI8rnRYEwFVb8nekUuvXBDovBDHCdBA2sBbDUXdbzRrJSCIo4i AiaQox3x70+aaDcnuJ+BboGY8Kpp3zLmjwcpS0cKpQGzv71EIwK+P33+cq4UrWMF8pPQ yoHOVZrcfsjj8MmASQuZnmCLoh+Rsa0ZBTnsZAxdsOeDNlJWZXRsCP7rBOQ2/0clZ/yC bggA== 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:in-reply-to :references; bh=ATw2AQdt0tMLUBC524HixfrRhPl572ZT8HtNHYF2xvw=; b=re4ndstB6uSFYJRxJbGZTuPIqqxlJKGRQSPS3yc80tk6ohj9LsS3Ss1dTU/aCc75qt SxejqNCYZamwuh0GEFILqPhPsIOVrdz4692TZJ1Q+GO0e6O3HR9bI42N1EDpjLFHC+gU me9ZsdzP/nRPweWsXJEPryS4UPK+tE7IC2rEAHMNOkye4VBqP4+UaE8iZ6TCeuHwV93+ VECfnNXu0nq03DyNTNEOSIgIAa53kIlqWtna39+KDST0NGu/JP4FLXU4s9UbVVD0UMib gtctvv3r7uxs6i9jLUkd/EMJS4YHxSuCbW+fJ9xt4RDNHR8r3FxxBBR7hd8PyVC4/XZ7 erEQ== X-Gm-Message-State: AOAM530j8f0u7c4iX4F4gcfX8G9FWzJV4S1EFrYXy1evgjGvaWKbEotw xwWLM97tNBFSpgUoHh+yvM0= X-Google-Smtp-Source: ABdhPJx4pJZpBmySqwHifSC2uYjzqgo1cF1Z9J0UvHeHi7upWFmPmdioA+AqPcCwgKmjeIsw3Ye1TA== X-Received: by 2002:a1c:dc05:: with SMTP id t5mr13600278wmg.112.1590148262694; Fri, 22 May 2020 04:51:02 -0700 (PDT) From: Eden Mikitas To: peter.maydell@linaro.org Subject: [PATCH 2/2] hw/ssi/imx_spi: Removed unnecessary cast of rx data received from slave Date: Fri, 22 May 2020 14:50:36 +0300 Message-Id: <20200522115036.31516-3-e.mikitas@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522115036.31516-1-e.mikitas@gmail.com> References: <20200522115036.31516-1-e.mikitas@gmail.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=e.mikitas@gmail.com; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, alistair@alistair23.me, qemu-devel@nongnu.org, jcd@tribudubois.net, qemu-arm@nongnu.org, peter.chubb@nicta.com.au, e.mikitas@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When inserting the value retrieved (rx) from the spi slave, rx is pushed to rx_fifo after being cast to uint8_t. rx_fifo is a fifo32, and the rx register the driver uses is also 32 bit. This zeroes the 24 most significant bits of rx. This proved problematic with devices that expect to use the whole 32 bits of the rx register. Signed-off-by: Eden Mikitas Reviewed-by: Alistair Francis --- hw/ssi/imx_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ssi/imx_spi.c b/hw/ssi/imx_spi.c index 6fef5c7958..43b2f14dd2 100644 --- a/hw/ssi/imx_spi.c +++ b/hw/ssi/imx_spi.c @@ -206,7 +206,7 @@ static void imx_spi_flush_txfifo(IMXSPIState *s) if (fifo32_is_full(&s->rx_fifo)) { s->regs[ECSPI_STATREG] |=3D ECSPI_STATREG_RO; } else { - fifo32_push(&s->rx_fifo, (uint8_t)rx); + fifo32_push(&s->rx_fifo, rx); } =20 if (s->burst_length <=3D 0) { --=20 2.17.1