From nobody Mon Apr 29 11:02:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1605028114; cv=none; d=zohomail.com; s=zohoarc; b=GGYLL5p3TALfcXByuE7/YsE8boucBFaCFuu0JzbiV3tcAbmtALYc78VPsDmq86pGU4465xxQ36SFrPeo3//lmrmV68dBKVKNrxDvZ9pp1nCTgTJ6ACC+JET3pVRDWaDmXwxWklJRYob3J9bkQ51lrqIAAfmkBXJkRVXTf3PiCVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605028114; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3TffB06QqlKySLwwMjn9ARXLrWK2pAbyiKXjQY9uagE=; b=gMqtVzFZBOw5nD7dYQzznrXRSlH8spC2Q0a6Bz2ktAbnqGCg4EkLC6puMcYhcP4vZBqUHXDAKkXtRFXUx2zSLRK+3O8OPKYkAtyIR1BiNrdSz8qevHUycRvKdl+aIbDnv7Len6LSmYfwOtE5QGTtu8HomAXBVt2HQNLp7KBELAc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1605028114580219.2584604294999; Tue, 10 Nov 2020 09:08:34 -0800 (PST) Received: from localhost ([::1]:53600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcX8D-0007VK-JE for importer@patchew.org; Tue, 10 Nov 2020 12:08:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcX6A-0006E5-0E for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:26 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:45119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kcX5v-0008IZ-6e for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:25 -0500 Received: by mail-wr1-x442.google.com with SMTP id p1so13487579wrf.12 for ; Tue, 10 Nov 2020 09:06:10 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id h4sm17334893wrq.3.2020.11.10.09.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 09:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3TffB06QqlKySLwwMjn9ARXLrWK2pAbyiKXjQY9uagE=; b=PRlGZ4+o5dB5obVsGfLl2BgWYhLqmfbowhDHbmxTnhLpuxsvHolplIOrCaRj5t2y9K BoDPLtvLXybS7AlKB6HzsXTZ328+qJTpb5mZ1o8pzlG2g23iFAUk4qPq900yF9LQKQ7Q yt5CF4jR5KJTe3nmfGQ8V4zywOkEHjF+/mspqCWl4ExSu/WQY9p0FE1aIk88HAeeSfQq ej2K4Io6vtXs2NY5vpmnH7TGnStEKO+twrIcEPfYf8K9vYNhI4ixyRWvSfjD8J1ImoVl dNqtnXB2FtrUcSZJjpPkjOG6vdd66YKYHlYGzXp/LvfI/wG4ljtI7JveQ1PQjGLUuRhc IVhA== 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:mime-version:content-transfer-encoding; bh=3TffB06QqlKySLwwMjn9ARXLrWK2pAbyiKXjQY9uagE=; b=Ap9NtN7ZrYVuIriZIM0TG+Mo3sIuQmdAyWu65NY+lvY4ww9PV+kASNxQ63rwajmEjv xPQo1YWJIEwJS/Gyjh5K+tTNKpTdimS06ON7st4ev0bRX26HmroxrB6wxC+cP33qAKNN 6QUagCnFsPY93JX8HLfZT5j8rE37PkFu9JM20ndr9oyPxvzCsY8EJAMrKhQIFTbU5PwB rAQMbXpSSUYcfCNx1zJqO6pgNOnYlwrRXjOZouluMFwvZGrfmk4Iq44XeWJKgWS+4f4D Dn5E6rqf0HNJVvMlTBYxcHlwoyz+yAh0+GmhKxd1XXXaC3cnRwrX7tCi2/+eCz8iBcSr RMqg== X-Gm-Message-State: AOAM533aeW94Ih0gN2fsC4xd7rAoY6G8K5M73YN83JxDz253U8wODknJ WEum+KhOtPTi0ESZWvvgXLm0CYeoLt05xg== X-Google-Smtp-Source: ABdhPJwV+3dV78NStRNqd/B3+qTVt9wstn5V1KYWTPBApZFhTWJuyvSGjM4wvBNugnQOJ2gjuW3RjA== X-Received: by 2002:a5d:4ac1:: with SMTP id y1mr25693919wrs.27.1605027968019; Tue, 10 Nov 2020 09:06:08 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 v2 1/4] hw/net/can/ctucan: Don't allow guest to write off end of tx_buffer Date: Tue, 10 Nov 2020 17:06:01 +0000 Message-Id: <20201110170604.5897-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110170604.5897-1-peter.maydell@linaro.org> References: <20201110170604.5897-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::442; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x442.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: Jason Wang , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" The ctucan device has 4 CAN bus cores, each of which has a set of 20 32-bit registers for writing the transmitted data. The registers are however not contiguous; each core's buffers is 0x100 bytes after the last. We got the checks on the address wrong in the ctucan_mem_write() function: * the first "is addr in range at all" check allowed addr =3D=3D CTUCAN_CORE_MEM_SIZE, which is actually the first byte off the end of the range * the decode of addresses into core-number plus offset in the tx buffer for that core failed to check that the offset was in range, so the guest could write off the end of the tx_buffer[] array NB: currently the values of CTUCAN_CORE_MEM_SIZE, CTUCAN_CORE_TXBUF_NUM, etc, make "buff_num >=3D CTUCAN_CORE_TXBUF_NUM" impossible, but we retain this as a runtime check rather than an assertion to permit those values to be changed in future (in hardware they are configurable synthesis parameters). Fix the top level check, and check the offset is within the buffer. Fixes: Coverity CID 1432874 Signed-off-by: Peter Maydell Tested-by: Pavel Pisa --- hw/net/can/ctucan_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index d20835cd7e9..538270e62f9 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -303,7 +303,7 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, = uint64_t val, DPRINTF("write 0x%02llx addr 0x%02x\n", (unsigned long long)val, (unsigned int)addr); =20 - if (addr > CTUCAN_CORE_MEM_SIZE) { + if (addr >=3D CTUCAN_CORE_MEM_SIZE) { return; } =20 @@ -312,7 +312,8 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, = uint64_t val, addr -=3D CTU_CAN_FD_TXTB1_DATA_1; buff_num =3D addr / CTUCAN_CORE_TXBUFF_SPAN; addr %=3D CTUCAN_CORE_TXBUFF_SPAN; - if (buff_num < CTUCAN_CORE_TXBUF_NUM) { + if ((buff_num < CTUCAN_CORE_TXBUF_NUM) || + (addr < sizeof(s->tx_buffer[buff_num].data))) { uint32_t *bufp =3D (uint32_t *)(s->tx_buffer[buff_num].data + = addr); *bufp =3D cpu_to_le32(val); } --=20 2.20.1 From nobody Mon Apr 29 11:02:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1605028580; cv=none; d=zohomail.com; s=zohoarc; b=WKBsV+8CW2gilJinM6GoRBFK233Hd7EfaeMq2Ulx4zYX7hiikTWHeV2jwalvryfdXLbaEOUoxi5ty0xauI6R14hcFg3n/w/McIE6pAp0d/2ONNYRwcrMhbY+FQI9JVhbmyxPzC021pdUf44AetEFSLXT47bSbdtTzjumxXcdSPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605028580; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Jih/JPR7rNmuRwjH6MNcptpond6bHtS/vHCrI5LZOSc=; b=ZoyK5PHP6q31SNcHuVmMLTn/9nV6LQaTOCUAfnvXmT5o5QGX2Hk89wIfYoFXB4BIGDET8LuW9xlDUS4u3nwjhPvJCdS5EBh8VMJ8sKYfkFbYVUuehGdpOHYv87BMFZCftyAPooKoglJYf6lSKrYrvlALnyikT+RD0mkA/YSFxh4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1605028580470799.3326763790511; Tue, 10 Nov 2020 09:16:20 -0800 (PST) Received: from localhost ([::1]:42210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcXFj-0006IV-DQ for importer@patchew.org; Tue, 10 Nov 2020 12:16:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcX68-0006D7-4p for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:25 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:40472) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kcX5v-0008Ia-78 for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:21 -0500 Received: by mail-wm1-x342.google.com with SMTP id a3so2476800wmb.5 for ; Tue, 10 Nov 2020 09:06:10 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id h4sm17334893wrq.3.2020.11.10.09.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 09:06:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jih/JPR7rNmuRwjH6MNcptpond6bHtS/vHCrI5LZOSc=; b=Yvb7jo5su5SR6eWlRsr0+hCCDBasWisHtcJLwHfc1x1EF8IKXabH4iWn/4TeaF6oJR n/gKJPHETK+LocT3g+TuF3mNzdYRPvbt1E+6LbKempDdIFmY1VjoAVNKNRzIwsqfO7qu uw4pE2dn5Z5ulyPLuqmA803xPDEYcd/miLUEd2Fi8HuuOTju7R3XisJj+XbpxTxKzQW6 a/mC7GR+IUd6+jlIbG4ZxCf8LNjGwlWM9GQ93pqZPbluyZYnRHm8v+wtUnFi436Tmylx kVzdKDEZHSnDe3GyIyjMTc4FQ2fKlkqSBh4NbhKw11ZyKfTTT/tyb5wu07oXzvZSwD1k lg0Q== 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:mime-version:content-transfer-encoding; bh=Jih/JPR7rNmuRwjH6MNcptpond6bHtS/vHCrI5LZOSc=; b=kNljQyxsui2JYNpaY5mlDor23HzVg6nZj9oBYzzxokuLb1w8RQOiGL4Hh8LGVShtZA 4PYV8njPWraJSbmm2pPY+4ZCjItyEZAYSoTetC1DZNMm3UnymzO1Kmg/9IqXSFkp9/Wa ihS42pU0q9n0c1WoWyJ9ZOEC9UAysEF6yLAF4+KOAApZVO3hTxODPoLCyuJqNK73uPEd +3D6viw0DeiniGeFAF1Ar39h/a1c/a77aNVxR2nnpbSTFcGWf0/1pag130eXVmze4BFp tQ4z/XMgXhsoOwjodpPi8zBSnhtNjnRR43rjDPyMjr7ubymIOMLTSAetM+fG9p6eXfL4 TAwg== X-Gm-Message-State: AOAM532XRpf+7T6Ne/U4x4pjUzO/r7ya0BaZyVoKCrOZtnZv4rPs5K8G yhf8A2ta1DD0SIHoo2B4gjEh2/LL9YAlVg== X-Google-Smtp-Source: ABdhPJzSGm1YwrXJf7nngpSA06vKiFSusY3g4y6tKDnw7DqKkOBJoTRtaYGaCjDfuaAFBdhL2qYKSQ== X-Received: by 2002:a05:600c:22c5:: with SMTP id 5mr44060wmg.25.1605027969374; Tue, 10 Nov 2020 09:06:09 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 v2 2/4] hw/net/can/ctucan: Avoid unused value in ctucan_send_ready_buffers() Date: Tue, 10 Nov 2020 17:06:02 +0000 Message-Id: <20201110170604.5897-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110170604.5897-1-peter.maydell@linaro.org> References: <20201110170604.5897-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=peter.maydell@linaro.org; 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: Jason Wang , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Coverity points out that in ctucan_send_ready_buffers() we set buff_st_mask =3D 0xf << (i * 4) inside the loop, but then we never use it before overwriting it later. The only thing we use the mask for is as part of the code that is inserting the new buff_st field into tx_status. That is more comprehensibly written using deposit32(), so do that and drop the mask variable entirely. We also update the buff_st local variable at multiple points during this function, but nothing can ever see these intermediate values, so just drop those, write the final TXT_TOK as a fixed constant value, and collapse the only remaining set/use of buff_st down into an extract32(). Fixes: Coverity CID 1432869 Signed-off-by: Peter Maydell Acked-by: Pavel Pisa --- hw/net/can/ctucan_core.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index 538270e62f9..a400ad13a43 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -240,8 +240,6 @@ static void ctucan_send_ready_buffers(CtuCanCoreState *= s) uint8_t *pf; int buff2tx_idx; uint32_t tx_prio_max; - unsigned int buff_st; - uint32_t buff_st_mask; =20 if (!s->mode_settings.s.ena) { return; @@ -256,10 +254,7 @@ static void ctucan_send_ready_buffers(CtuCanCoreState = *s) for (i =3D 0; i < CTUCAN_CORE_TXBUF_NUM; i++) { uint32_t prio; =20 - buff_st_mask =3D 0xf << (i * 4); - buff_st =3D (s->tx_status.u32 >> (i * 4)) & 0xf; - - if (buff_st !=3D TXT_RDY) { + if (extract32(s->tx_status.u32, i * 4, 4) !=3D TXT_RDY) { continue; } prio =3D (s->tx_priority.u32 >> (i * 4)) & 0x7; @@ -271,10 +266,7 @@ static void ctucan_send_ready_buffers(CtuCanCoreState = *s) if (buff2tx_idx =3D=3D -1) { break; } - buff_st_mask =3D 0xf << (buff2tx_idx * 4); - buff_st =3D (s->tx_status.u32 >> (buff2tx_idx * 4)) & 0xf; int_stat.u32 =3D 0; - buff_st =3D TXT_RDY; pf =3D s->tx_buffer[buff2tx_idx].data; ctucan_buff2frame(pf, &frame); s->status.s.idle =3D 0; @@ -283,12 +275,11 @@ static void ctucan_send_ready_buffers(CtuCanCoreState= *s) s->status.s.idle =3D 1; s->status.s.txs =3D 0; s->tx_fr_ctr.s.tx_fr_ctr_val++; - buff_st =3D TXT_TOK; int_stat.s.txi =3D 1; int_stat.s.txbhci =3D 1; s->int_stat.u32 |=3D int_stat.u32 & ~s->int_mask.u32; - s->tx_status.u32 =3D (s->tx_status.u32 & ~buff_st_mask) | - (buff_st << (buff2tx_idx * 4)); + s->tx_status.u32 =3D deposit32(s->tx_status.u32, + buff2tx_idx * 4, 4, TXT_TOK); } while (1); } =20 --=20 2.20.1 From nobody Mon Apr 29 11:02:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1605028374; cv=none; d=zohomail.com; s=zohoarc; b=FCgH7qQiQz5U8hRUfJ6EWq8rOuQ7j+BV/zbnATj8LTSP9ajSaHCEqUCYcjtin+26wP1T7daI88tgwDwK5C4/N3Cd8SOU6OjsLGkqmrBXR1JHMW12i5gTLvzB3hAGLIazeN+x4dKg78DW97GfDuknC5+fO1Ra62+dVRQ/p8mEWFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605028374; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kSQkE4mQsz+5YrFfsY3dUOcYsreKD46sMKkau53xx+o=; b=d8RvfOh27PVt4Hrj1Y1WqWZXJgS7D+BpsWRBLJLK0zvOoGzoLuW5tLXpUe5Zh3cfDG5AWAeSD8hnum1BqV8bP8FCtEzi07po2FT6rj8UAP0hBsnG7D+pfFw4n7oc3Ap5276KVk6pVnRP0pCcDtKRtw9CsYn7uKI4l7taQYuQhEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1605028374818556.928921126275; Tue, 10 Nov 2020 09:12:54 -0800 (PST) Received: from localhost ([::1]:35692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcXCP-0003YP-FC for importer@patchew.org; Tue, 10 Nov 2020 12:12:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcX6A-0006Ey-HR for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:26 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:50295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kcX5z-0008Im-Ti for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:26 -0500 Received: by mail-wm1-x344.google.com with SMTP id h2so3847592wmm.0 for ; Tue, 10 Nov 2020 09:06:11 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id h4sm17334893wrq.3.2020.11.10.09.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 09:06:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kSQkE4mQsz+5YrFfsY3dUOcYsreKD46sMKkau53xx+o=; b=CoYVfKyR9xho72qKse3GoaQx9V4iQCL2Ifj3Xg6dLyX4SnE5bUd7tqoZjISskD72r+ I0TWV+Y8TQkfhyr9oiyAYuBK7hIKGome61lyvN1KerTsDQhXixaC7BCJpSzZNCT7kHvB ZbP/FpwDCzdzh/r/3SlnymfBi9f+7w9+LfV3TpDiHJo5ziJDyyI+uEdCDoXxr8Uj3diS Grc2y3JZZPR67cHah2yzWewSqaJSfnL0AF4CMu82/r8EQ83Z+buAPLv8Q2M975WNj5dt PIKFJnYebr8piu89neezzRSBzc3NK6Q7Eq5kIRFTASP4v6DWHbxR0Zx28zgqMaai9dz/ 7nsQ== 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:mime-version:content-transfer-encoding; bh=kSQkE4mQsz+5YrFfsY3dUOcYsreKD46sMKkau53xx+o=; b=AruyaGLIW3lb9Iga73IJuBWWDRDakrIF1AmaLO2Y841ERHIdO9AuG1zVuF9Ur90A4y e6/HhiIkar3U2NMwx5NfVKxjiRObBgXMFKUDpmLb/rRIz0COJ6U8ZXCMBb254Q+suphR zhJOraOBl6bpTH5fv4sUcYYgTteHi7pt2pDS94UkxM9I44Y57dDSgB5N90J6g3hsJULW vcl6BN6Y9BdJvkWc6SjXHJpyviwEqRoeDPl4pKL4tVvKhtkZ91THeVNEjFQSK25M6PyQ F57mxNturXGcs1fnJNZ/bs4mQ4ArE0hE4asS2K/8dOpa+foRWKuVIfeF3JhdWL2zZOV+ JZdg== X-Gm-Message-State: AOAM533WlSJ36NEJaSzpCiI7CLjllAvp+Sf3fMlCvxIlKhznruiFxAHE C2aMgUQUu1Rc34uPvgVT+lO/mtrzRlmjsQ== X-Google-Smtp-Source: ABdhPJwDRSFSdfkJBioSiU3QmeEe6yOeFq7/s3NVZYTXycowfhFDhPwqt9NdTcdOlh/nwFM4AD16rg== X-Received: by 2002:a1c:6856:: with SMTP id d83mr47665wmc.13.1605027970551; Tue, 10 Nov 2020 09:06:10 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 v2 3/4] hw/net/can/ctucan_core: Handle big-endian hosts Date: Tue, 10 Nov 2020 17:06:03 +0000 Message-Id: <20201110170604.5897-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110170604.5897-1-peter.maydell@linaro.org> References: <20201110170604.5897-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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::344; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x344.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: Jason Wang , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) The ctucan driver defines types for its registers which are a union of a uint32_t with a struct with bitfields for the individual fields within that register. This is a bad idea, because bitfields aren't portable. The ctu_can_fd_regs.h header works around the most glaring of the portability issues by defining the fields in two different orders depending on the setting of the __LITTLE_ENDIAN_BITFIELD define. However, in ctucan_core.h this is unconditionally set to 1, which is wrong for big-endian hosts. Set it only if HOST_WORDS_BIGENDIAN is not set. There is no need for a "have we defined it already" guard, because the only place that should set it is ctucan_core.h, which has the usual double-inclusion guard. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Pavel Pisa --- hw/net/can/ctucan_core.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/net/can/ctucan_core.h b/hw/net/can/ctucan_core.h index f21cb1c5ec3..bbc09ae0678 100644 --- a/hw/net/can/ctucan_core.h +++ b/hw/net/can/ctucan_core.h @@ -31,8 +31,7 @@ #include "exec/hwaddr.h" #include "net/can_emu.h" =20 - -#ifndef __LITTLE_ENDIAN_BITFIELD +#ifndef HOST_WORDS_BIGENDIAN #define __LITTLE_ENDIAN_BITFIELD 1 #endif =20 --=20 2.20.1 From nobody Mon Apr 29 11:02:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1605028694; cv=none; d=zohomail.com; s=zohoarc; b=WDKfndf5FuvuVrfKH6BTqMNlBuA4hXbpEr0qm9/Ty973UCiOeyCbXl/WSHPk+DO+OzOLjPBV43NX021toHC1ZcKdTC8OidXRdqMg3JIkyNfc0Ev5hVqOAxA5tWoPQS01naGj72QlXsQL/PZIeo1NPzvQoYBPgP+VCQPU4yUiMLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605028694; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PYS0/6U6l5yAr2j+rxA7ao/heFAIM+a4DJHT8NMJBpA=; b=Tr6bcOwAgc0mk154uMXVFWxc12MIfKb5s4D+wipGZABF0Oc2oJtQh7HIkjyVmvh0ImMVu8kOIswmU5maltOK/2Y8LzI/m9Q6ihGJAosrlqhi8mDX0Vdrkiz1aVJstbtRaNHXnsZmheg0ZZPgYGMqgEuUnVnxgqjwYaeVIeAuW6w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1605028694319263.5061849956496; Tue, 10 Nov 2020 09:18:14 -0800 (PST) Received: from localhost ([::1]:48434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcXHY-0000S3-Ne for importer@patchew.org; Tue, 10 Nov 2020 12:18:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcX6C-0006Hq-Jt for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:28 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:32931) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kcX67-0008Jg-LE for qemu-devel@nongnu.org; Tue, 10 Nov 2020 12:06:28 -0500 Received: by mail-wr1-x442.google.com with SMTP id b8so13509862wrn.0 for ; Tue, 10 Nov 2020 09:06:12 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id h4sm17334893wrq.3.2020.11.10.09.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 09:06:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PYS0/6U6l5yAr2j+rxA7ao/heFAIM+a4DJHT8NMJBpA=; b=rmXdDxBCvNuHWaP5i/CQUZ5H16ZooT1rXqccvbHJ24vX9dSBM8qvIq3zu0ZH6pd0uA aXgcaFuoCKJvrhsnpsoBa0tmaNxxIYxXnbH/znOtHfhf7peLziH+3jnYa1xa8QsgeKQm cKM30t8fPA78NDcw/KizaxBmZG0Gsx6iQQrtDEOH4291I+ONbbcekL/zHjVZxITLzUS0 X+LfZXkzMTj9UHj//jRMVAbfnF/+BlyQjHvYPY7f2nwK79oqJmcWs2PjxW4aoOgzPn0a nMklSAuXnWeO1588c7UEOiB9ScFboTLlpcn4rYz3XT2gMiZy7GDwjNI+mrM2D8rLi6bp n1bg== 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:mime-version:content-transfer-encoding; bh=PYS0/6U6l5yAr2j+rxA7ao/heFAIM+a4DJHT8NMJBpA=; b=szxp5Uuo52aydmTYZtx+Hxn0fY3TBOUsTCjPu5b8YGFIshpSCJhOWvHjxpwnxegTvQ i7rUQu6uGbkJvvScypsmy9QGEEV7gBX67AeD+miIrlCVp0kQtuHAJDwUeYSeHYpUOIV5 KyM7aV67QbWh9lfSu7RhiHGzwIAqJiUwVjbM/zdYDu1VRksJSy4Tcl1PI+d6Afx9j3zg 4rAnlVEr3VoruKfP03Gi60K5dVT1TNC0ghhJooxgvFg3KkOoSX9ipn3i7OXIQ5KcflGx e77T6O6IerMUC6cag+PYmI9arjsDX+tEWh50kPW/jmQJSacB6VlvxFiLStaxosr37A2D 3JHQ== X-Gm-Message-State: AOAM531sCybmj45rGwkdWd8P0DjHbQSsfLztx4w4srs7gs9V7o2k9XlF WstkyEiThZ8lQqj2LX0arMogtxs7mrsbyg== X-Google-Smtp-Source: ABdhPJwHFZ48BmYm/z3mnNr5on0wagUFOpws31j4TV1UzatJX0AYZn7BhaetDMV9cxH/Ndn0gVf20Q== X-Received: by 2002:adf:f881:: with SMTP id u1mr26664333wrp.103.1605027971803; Tue, 10 Nov 2020 09:06:11 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH for-5.2 v2 4/4] hw/net/can/ctucan_core: Use stl_le_p to write to tx_buffers Date: Tue, 10 Nov 2020 17:06:04 +0000 Message-Id: <20201110170604.5897-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110170604.5897-1-peter.maydell@linaro.org> References: <20201110170604.5897-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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::442; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x442.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: Jason Wang , Vikram Garhwal , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Instead of casting an address within a uint8_t array to a uint32_t*, use stl_le_p(). This handles possibly misaligned addresses which would otherwise crash on some hosts. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Pavel Pisa --- hw/net/can/ctucan_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index a400ad13a43..0ef528eb879 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -305,8 +305,7 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, = uint64_t val, addr %=3D CTUCAN_CORE_TXBUFF_SPAN; if ((buff_num < CTUCAN_CORE_TXBUF_NUM) || (addr < sizeof(s->tx_buffer[buff_num].data))) { - uint32_t *bufp =3D (uint32_t *)(s->tx_buffer[buff_num].data + = addr); - *bufp =3D cpu_to_le32(val); + stl_le_p(s->tx_buffer[buff_num].data + addr, val); } } else { switch (addr & ~3) { --=20 2.20.1