Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5833223rwj; Wed, 21 Dec 2022 07:35:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXuQ8nZHqoEspmE3IKfo7tNQvouM4nu8ac4oRiUGzt5ZRvd01+riRJbzcd8kTF1GKgKED+ud X-Received: by 2002:a17:903:3311:b0:189:c380:7c7c with SMTP id jk17-20020a170903331100b00189c3807c7cmr2526055plb.23.1671636927251; Wed, 21 Dec 2022 07:35:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671636927; cv=none; d=google.com; s=arc-20160816; b=CGPvqo0bYv9MBJbRFGxklygwHRq/hIX1ORovfTmmVt7S0GeAvyy7sj+LJKfryaXz3H KZ7b3kEKd0E/dt4n4mvTizD9mSmb1NRjWm3P1RF5kZmdMZlMPHAKEzA9v+WpJ7wA38vB rLjsSBSRsXw+uYvw/iPPQ9wfx1pRQfVO7cwsiFOpsbo8xXLHW426yTyyLT9EhySTojQg IlLvNrzUH/ohPYKTtVyN1CRUxyp+C/39AwlNRFqf362IHsazPd3ZyxmRun8UDT2Xcc3z mmFEXcWeRg656HdvaaZVFU4RRLG36hAJd2qwWdfV0bmdD9RQKiF2j/phf0pC+9gDR3pb FAPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mDXoKkBf3QKLFoNBUr2onp8tCGWeovhpj/ofZ+JjjAU=; b=zR6xK9qcsKuXzqgk1O7v4EeQWRRDVFmmeiWzBPguZHDb9pjQIp7x24+km8WpVFmHGD HHwg0x0apH1gWllya1bsonNcAAryESAYkmO+vOLMHYMFpEmDzTTX+NN9Il/5FSqTLi4O OGv8309irVD4xp9ZXqZeK3/udqlslQnBIb68RZgHkrt+Jc81f3vWM77yOK72w/TEe44p Zw3dEHSWnL7wLJOO7DNmeiSDWyvinM8WdKNo9wdEHgoGfWuhZKlQ/JRYhAr2H17ioOY6 JgxCHwwmRvyYpIpLx9AtJY7M2Bu5F+2fKNwpKgbMXOW1jpYL1HDEEi986xl9Aid+owHt jxYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=TMhjNigS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a170902c1d300b00189bbc95db1si16082512plc.11.2022.12.21.07.35.18; Wed, 21 Dec 2022 07:35:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=TMhjNigS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234602AbiLUPZx (ORCPT + 69 others); Wed, 21 Dec 2022 10:25:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234535AbiLUPZr (ORCPT ); Wed, 21 Dec 2022 10:25:47 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A34610BB for ; Wed, 21 Dec 2022 07:25:44 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id a1so7451607edf.5 for ; Wed, 21 Dec 2022 07:25:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mDXoKkBf3QKLFoNBUr2onp8tCGWeovhpj/ofZ+JjjAU=; b=TMhjNigS1DyIwH8CyjsHocZyaHTt7KyK/ZCjumwTN9EBxfeVWy11UJZ/hucZ2QgmKL i9+S6Mr5k3JlxoN74cBxQBq5gFNneK9tZoVKVuhnXkRB+1GzIbXAOID2fxatGI5h++TP Zg9ZUwqOFDAJMcdoLKzmPTzBXPps2BJltJYupb2iQNZHydtKxPrU6WqFRuRBLXcQKyyd RSGOLfNeeYDV6fqcRTz8VyNhfGn9nhcgt20R8gwBN4q/t2Qht1mRCwJLS7+fMZZ79ntP IbRv940LZ2xjde+/NVeGOgUh4xPCi4R9M9R3FJQF2QijNknp5xw1uMDXBgb9s5+22ovo TWNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mDXoKkBf3QKLFoNBUr2onp8tCGWeovhpj/ofZ+JjjAU=; b=Wta7mCLfXbZUJ5cVlE04zzv1AQ2zMSUJnA4xY1dPX7NvwqVQPSEPuWmdR/ns0Hs3RZ 8Qv1WpC/jXQhhxrkk+qb2xnG1jKbpERDuky+/P+VcasAYprGW7Q7A/C9/gXLDBmNkhB3 WAVTjjjU0d853xRGmYoz2NQzLjSwBNTCGEKcwLOMQz04LgCMpyvNuLKRAq04pQF2vuDO JbA0jcU8fs2qkYRpkXOHft0sQcqAB4Qy9qSHeQL0+2UCJDJQ0q2GJA/aQb9fNA4GIQlQ R9Jdy35E+Nt5MBwOf2TqkkhhDL0f7SxaKRTCLOnDJtKsDjteKU7bq/5Gij/yeGMqkvMi 6Qzg== X-Gm-Message-State: AFqh2krKUKZDgaEYH8E01PPY2OEov4mLwdFsUFmB5YmAetE0OG7p9wbI HOYlsl9/ORKFGWxQuHdUlyGnCg== X-Received: by 2002:a50:fd10:0:b0:46c:97c2:8d75 with SMTP id i16-20020a50fd10000000b0046c97c28d75mr1720946eds.21.1671636342810; Wed, 21 Dec 2022 07:25:42 -0800 (PST) Received: from blmsp.fritz.box ([2001:4091:a245:805c:8713:84e4:2a9e:cbe8]) by smtp.gmail.com with ESMTPSA id n19-20020aa7c793000000b0045cf4f72b04sm7105428eds.94.2022.12.21.07.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 07:25:42 -0800 (PST) From: Markus Schneider-Pargmann To: Marc Kleine-Budde , Chandrasekar Ramakrishnan , Wolfgang Grandegger Cc: Vincent MAILHOL , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH 02/18] can: tcan4x5x: Check size of mram configuration Date: Wed, 21 Dec 2022 16:25:21 +0100 Message-Id: <20221221152537.751564-3-msp@baylibre.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221221152537.751564-1-msp@baylibre.com> References: <20221221152537.751564-1-msp@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To reduce debugging effort in case the mram is misconfigured, add this size check of the DT configuration. Currently if the mram configuration doesn't fit into the available MRAM it just overwrites other areas of the MRAM. Signed-off-by: Markus Schneider-Pargmann --- drivers/net/can/m_can/m_can.c | 16 ++++++++++++++++ drivers/net/can/m_can/m_can.h | 1 + drivers/net/can/m_can/tcan4x5x-core.c | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 56f07f2023dd..f3ee21ce6109 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1860,6 +1860,22 @@ static int register_m_can_dev(struct net_device *dev) return register_candev(dev); } +int m_can_check_mram_cfg(struct m_can_classdev *cdev, u32 mram_max_size) +{ + u32 total_size; + + total_size = cdev->mcfg[MRAM_TXB].off - cdev->mcfg[MRAM_SIDF].off + + cdev->mcfg[MRAM_TXB].num * TXB_ELEMENT_SIZE; + if (total_size > mram_max_size) { + dev_err(cdev->dev, "Total size of mram config(%u) exceeds mram(%u)\n", + total_size, mram_max_size); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(m_can_check_mram_cfg); + static void m_can_of_parse_mram(struct m_can_classdev *cdev, const u32 *mram_config_vals) { diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h index 4c0267f9f297..d2c584232c1a 100644 --- a/drivers/net/can/m_can/m_can.h +++ b/drivers/net/can/m_can/m_can.h @@ -101,6 +101,7 @@ int m_can_class_register(struct m_can_classdev *cdev); void m_can_class_unregister(struct m_can_classdev *cdev); int m_can_class_get_clocks(struct m_can_classdev *cdev); int m_can_init_ram(struct m_can_classdev *priv); +int m_can_check_mram_cfg(struct m_can_classdev *cdev, u32 mram_max_size); int m_can_class_suspend(struct device *dev); int m_can_class_resume(struct device *dev); diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c index efa2381bf85b..4f5a3ade6de2 100644 --- a/drivers/net/can/m_can/tcan4x5x-core.c +++ b/drivers/net/can/m_can/tcan4x5x-core.c @@ -80,6 +80,7 @@ TCAN4X5X_MCAN_IR_RF1F) #define TCAN4X5X_MRAM_START 0x8000 +#define TCAN4X5X_MRAM_SIZE 0x800 #define TCAN4X5X_MCAN_OFFSET 0x1000 #define TCAN4X5X_CLEAR_ALL_INT 0xffffffff @@ -312,6 +313,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi) if (!mcan_class) return -ENOMEM; + ret = m_can_check_mram_cfg(mcan_class, TCAN4X5X_MRAM_SIZE); + if (ret) + goto out_m_can_class_free_dev; + priv = cdev_to_priv(mcan_class); priv->power = devm_regulator_get_optional(&spi->dev, "vsup"); -- 2.38.1