Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9094407rwd; Wed, 21 Jun 2023 03:00:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kBJTXVPCJTGEy6u/vpdwPVL/hNe9dvHLuJbwBJnkDLYdSn/M3cSSKs57MTvaFHwJCu4I5 X-Received: by 2002:a05:6a20:a108:b0:10c:b1b0:3ee3 with SMTP id q8-20020a056a20a10800b0010cb1b03ee3mr20705110pzk.21.1687341632873; Wed, 21 Jun 2023 03:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687341632; cv=none; d=google.com; s=arc-20160816; b=ml7lvaRSnowKiAsewEH0TJG302iAcGgrg4gmsCeDMcJ6O6tqYWBZHKPanrdaTyWL1c RZsC2qHi1sj/WNV6daOlUajkWXlGVbHU9VYX1l5gLnxAYeyPbqX48FrdLtDaQ5wt6Vwn 5vYYDi8kPxtRt4zpJMFM3/6z4cJnqXOXFrwlE9OI7syZVU07SiC5W5hM01VgPnOZZEm6 s7DCACnyS9dRjeOuvCLQgwp8iX7qwTr/VxIO0IvUeaj/uDqcN0cRs4clywEvsc47GxbX WGTqJSvDclM3wnezEy6SUz58MeJrNCIL/t5GOj9FdkRDf0gZLsHGEpudMNxHkJD7MIjB wVeg== 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=ybtO4Wog7AXA+LuJ7ppZ2BwN9dyYZ5NmmDbgKQHeLHM=; b=NIWUkRyvoQZaQSzeVu0Quk3VxTOK/EWbwDUcj8U8oMZWXM4qY/NTmaOalsal90J4Rd IQrFGjXNiZckw5iiIFS9zLp9sQ1xkO/7tDKxwUp/09QP5jHnTno8O6e39f4taF701mhC J9RlkUpGQbo0iexGuEHlbEx4jS9l6eJsv4igq9RexfZ/g9+GUU39vw7QpOV63YpEUqBx Q1UcvDLKvpxcN3PzmsOTM5JHDh6pEm+NJDXv8PqKhihZrgiVXpC6iC0sww/c/TBccWUf T/MTuFnbFlUzMfb5CA+XXkmDk0ojQIwXCZS8ZFHTBDQpX/mlTOH5uI+1HbvDq8MyFC1b ndyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=GbEYPR52; 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 i195-20020a636dcc000000b005533ed46a70si3617043pgc.814.2023.06.21.03.00.16; Wed, 21 Jun 2023 03:00:32 -0700 (PDT) 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.20221208.gappssmtp.com header.s=20221208 header.b=GbEYPR52; 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 S231223AbjFUJci (ORCPT + 99 others); Wed, 21 Jun 2023 05:32:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231607AbjFUJbP (ORCPT ); Wed, 21 Jun 2023 05:31:15 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 959AC1718 for ; Wed, 21 Jun 2023 02:31:13 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-311153ec442so4551017f8f.1 for ; Wed, 21 Jun 2023 02:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1687339872; x=1689931872; 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=ybtO4Wog7AXA+LuJ7ppZ2BwN9dyYZ5NmmDbgKQHeLHM=; b=GbEYPR52b9eyHWmMfQU9tvxe081wY8nIF6gJ+LgJ2SlgFQ61zD+2NzGNljuXKeWy24 LICZ2j4cIUIqB4M9uHH9OBqCAf81admdZooSMEzGnVTZlENGAJArH+OU0feZq4wZJOIJ Vvmyp1jnZUar0x3VDO97AP/HdoH9AoCKcyIa/32nekVLkhrKozliSJQmm6MdckAS7A1d 43G5aKpBfnpfF8e4HGgwvkwzwk0ERyZ/t+jxxVJGFEiSAhKR7nkVegtGqXe0vJySt9CZ Z0BZB4msJpteWeG4DHueVVr5CfwIUnYQExTnPDUsxSv8vYpYVsW6e2jl8xXbVPL4Qhu4 tNWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339872; x=1689931872; 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=ybtO4Wog7AXA+LuJ7ppZ2BwN9dyYZ5NmmDbgKQHeLHM=; b=j2n75eRO1PQky560vgU+tZTMIRkBaQeIaKJuM8P221feHXOIdqofbiN0oayMszajjm 6SbWZh3a0Wqt2IOWWICEJ3tsUp+f/Zkb1CQg4Wo3XoiLnwG7SfCsAPMlFxP607uwHiFz abKed74cQcJwDbyJhaiRzrkL140JqOla79OWzut3J23+YJTYqULgDh//PZOxwbwTBmu8 jBrJGp8PR1Smds2HQFJ8GpFspGLNmAg8tURmOlofhBDR3TamRSOTgT6EhnelUqJthCUy SxOVzaJftuRIJ0o4N1k+MfDOxNgrks1r7N2AgpIWcSV+qP1yAWhEuD4lnfCra7JZk3WH j3oQ== X-Gm-Message-State: AC+VfDz5yeG+s2YclFkGvuXqMCZmcR756+nJzYsVsv5YYxkBi6SUeD17 9ZMuSLY1WcsuoCXME23F5GnL8g== X-Received: by 2002:a5d:6501:0:b0:30f:c420:1743 with SMTP id x1-20020a5d6501000000b0030fc4201743mr12562307wru.26.1687339872182; Wed, 21 Jun 2023 02:31:12 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4091:a247:82fa:b762:4f68:e1ed:5041]) by smtp.gmail.com with ESMTPSA id t10-20020a5d49ca000000b002fe96f0b3acsm3977344wrs.63.2023.06.21.02.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:31:11 -0700 (PDT) From: Markus Schneider-Pargmann To: Wolfgang Grandegger , Marc Kleine-Budde , Rob Herring , Krzysztof Kozlowski Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Conor Dooley , Chandrasekar Ramakrishnan , Michal Kubiak , Vivek Yadav , linux-can@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman , Markus Schneider-Pargmann Subject: [PATCH v2 3/6] can: tcan4x5x: Check size of mram configuration Date: Wed, 21 Jun 2023 11:31:00 +0200 Message-Id: <20230621093103.3134655-4-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621093103.3134655-1-msp@baylibre.com> References: <20230621093103.3134655-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, T_SCC_BODY_TEXT_LINE 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 Reviewed-by: Michal Kubiak --- 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 a5003435802b..1cdd2675f022 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1887,6 +1887,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 a839dc71dc9b..d8150d8128e7 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 2342aa011647..e706518176e4 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 @@ -307,6 +308,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.40.1