From patchwork Tue Nov 10 21:52:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Pisa X-Patchwork-Id: 322899 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp596882ils; Tue, 10 Nov 2020 14:02:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGb9RuRjdvd1BQUH2z8W+kTFihWiRUYui0LxJ9owj6VXMpKy5S4GeyqHslOZ8/zVwTv2s7 X-Received: by 2002:a25:16c4:: with SMTP id 187mr27654374ybw.281.1605045772261; Tue, 10 Nov 2020 14:02:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605045772; cv=none; d=google.com; s=arc-20160816; b=BX7TGA6QMbD2R6+5fI8QGU+LBmwmuV7R4TTC0NDzTB5ppjntXiYD1rluwowrmSa6Lv ytwILOxnaxc9cztD8AArv5BJ3ccEoVwNJrJnoGDiFWczyulI96LHYzoAMMyARfxKbbQc yzIOPs6zK1rChFz7kDmGl/x6WKWc0gC0RFRyFMPIg4bdMlxho4jRtpEM8UxcNWND+3s/ WjrkUT769n7oc4Ox5OKq6Jv7siG1gvndeYkc1oe2XrRCgixcW7p83EWhnysGzfbCp5Ij Zjk/XNoYUDmM2L7mMcmNsjw83qNBkYgC0PBdamiXWZFql2CU29FJAw5cZUmroIknXBO0 EEcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=RzupqbRAp9xZXyU0pb3Y8asV8zVRgn9GaQopBXem0ZY=; b=siVLBUhmBJKCPbzCHeLxjQBIkHY8jm80o6F0U+JtbKeyRoIuI4wVXOwWIdEeAJp8k4 x00aQjNNU54Lc8vJMYtuoBS0309hBizI28o87jKsGoPbmN9jxTMHnIwE85PE7ezuTXOr Lrrg7yHc00heE06wwXqSZiWfijwoxBuE29j3pzHurfncOLHAum8Y6W9P5MPLV1gfvMbN 2/O0PQgihv5YzsE6ZFmz8eCMw5AXLqGtLJJ72hCWo8P0jPvVm3w/XKVICHNikEwCaW/U 97p0cXCE+kNjvs/EFlg7sqBJUYtk8gtm4KD6HHEchbFDpVTuNNIovTPFPTTKdyaESEtD 1XQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g34si82961ybj.72.2020.11.10.14.02.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Nov 2020 14:02:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:36810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbj1-0002sz-Kd for patch@linaro.org; Tue, 10 Nov 2020 17:02:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcbbH-0007jS-0S for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:51 -0500 Received: from relay.felk.cvut.cz ([2001:718:2:1611:0:1:0:70]:13424) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcbbB-0002ce-8c for qemu-devel@nongnu.org; Tue, 10 Nov 2020 16:54:50 -0500 Received: from cmp.felk.cvut.cz (haar.felk.cvut.cz [147.32.84.19]) by relay.felk.cvut.cz (8.15.2/8.15.2) with ESMTP id 0AALrgwF095304; Tue, 10 Nov 2020 22:53:42 +0100 (CET) (envelope-from pisa@cmp.felk.cvut.cz) Received: from haar.felk.cvut.cz (localhost [127.0.0.1]) by cmp.felk.cvut.cz (8.14.0/8.12.3/SuSE Linux 0.6) with ESMTP id 0AALrgeh028093; Tue, 10 Nov 2020 22:53:42 +0100 Received: (from pisa@localhost) by haar.felk.cvut.cz (8.14.0/8.13.7/Submit) id 0AALrgb7028092; Tue, 10 Nov 2020 22:53:42 +0100 From: Pavel Pisa To: qemu-devel@nongnu.org, Peter Maydell Subject: [PATCH for-5.2 v3 4/4] hw/net/can/ctucan_core: Use stl_le_p to write to tx_buffers Date: Tue, 10 Nov 2020 22:52:50 +0100 Message-Id: <7951c8ad9a0ad6b5faf7ec7569f255fa45259590.1605044619.git.pisa@cmp.felk.cvut.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-FELK-MailScanner-Information: X-MailScanner-ID: 0AALrgwF095304 X-FELK-MailScanner: Found to be clean X-FELK-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-0.099, required 6, BAYES_00 -0.50, KHOP_HELO_FCRDNS 0.40, SPF_HELO_NONE 0.00, SPF_NONE 0.00) X-FELK-MailScanner-From: pisa@cmp.felk.cvut.cz X-FELK-MailScanner-Watermark: 1605650023.99277@snFSPGKgF+gWI/ke73RDgg Received-SPF: none client-ip=2001:718:2:1611:0:1:0:70; envelope-from=pisa@cmp.felk.cvut.cz; helo=relay.felk.cvut.cz X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 16:54:16 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=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: Vikram Garhwal , Jason Wang , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ondrej Ille , =?utf-8?q?Jan_Charv=C3=A1t?= , Pavel Pisa Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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é Signed-off-by: Pavel Pisa Tested-by: Pavel Pisa --- hw/net/can/ctucan_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index f49c76261c..d171c372e0 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -303,11 +303,9 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, uint64_t val, addr -= CTU_CAN_FD_TXTB1_DATA_1; buff_num = addr / CTUCAN_CORE_TXBUFF_SPAN; addr %= CTUCAN_CORE_TXBUFF_SPAN; - addr &= ~3; if ((buff_num < CTUCAN_CORE_TXBUF_NUM) && - (addr < sizeof(s->tx_buffer[buff_num].data))) { - uint32_t *bufp = (uint32_t *)(s->tx_buffer[buff_num].data + addr); - *bufp = cpu_to_le32(val); + ((addr + size) <= sizeof(s->tx_buffer[buff_num].data))) { + stn_le_p(s->tx_buffer[buff_num].data + addr, size, val); } } else { switch (addr & ~3) {