Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1399631rwb; Fri, 28 Jul 2023 08:54:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlESXJw/MKUsjedrxCYVmZ/qg+b+bD6NFKF3y5mjX2X1OEprhSOmtHShUg77CLfIMR0jdGkJ X-Received: by 2002:a05:6300:8003:b0:13b:9d80:673d with SMTP id an3-20020a056300800300b0013b9d80673dmr1908863pzc.48.1690559659244; Fri, 28 Jul 2023 08:54:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690559659; cv=none; d=google.com; s=arc-20160816; b=ti3Yo2h/LWyMyf6zY0ld3K9Gg88668Rz3dmNETh4dw+T7skK7dM8W4rnTZ2LKTMZpK Ew0LCBJXjNavKC43xHwADvDT9sy3IF54IrB4wGV3LTX38P51uPNvRlR27Bs1AbgU+xiY QKdY9PEfWlBZXYj1Dmp5l16hQVFfBavWZRx2pqvuKlLdEHxZdcTUwb4tKIVHjRkMQDrJ sH17PuQX5urx/+ls2awQ48l5A2krnGIUe8EpdNdpUb7oyP7LolYF25OWSlwFRlvTL64/ Cd8XpUqZ/00ImJONBBD9d50IpGrUQelzvqo9hi4EcEaKrFUlO0pkn4NRaj7aPqFaTjt7 ZBpw== 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=mzaljnOO1Gw4qS38ZHWvBAE06zq5Umr4CoJZWfxvzDg=; fh=9frbIG+5eKvNqELn2qUZ8UP3akRIGRm6w0alHg8xR8g=; b=AoPZrD3rwukfYQ7V/nq7pIHdHrNFf+57nq1wNOtuqPabHLR0wly/vGpmHL6yr5lVhx ypf/W8TNniQoyT/v8H/sMJiX5HfJuy5TlCJHD14049X6fdSpwiDo1CyRyNAjP/HcnPs+ 5hyKOQG+43Haznrtifb3w5FK4Ogc+9y+RCNdqZe9ASJW3APn9uEdvbJl7GvCM4H3IiaK EjsdX/QRrc+AombGkWYQTDwQf9IiuLpN27CLluLl+8fXDazZpbv9e0popytlulM2iyz0 5K0Vp+bV7XPw59aD80G+aXbWcGO+ZSdJF7jy2x3jtlETkOzhxxArxI5A0uOkOz01Tlxj 4N5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=xUKyFTsS; 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 n20-20020a637214000000b0053f265b0eecsi3130153pgc.133.2023.07.28.08.54.07; Fri, 28 Jul 2023 08:54:19 -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=xUKyFTsS; 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 S236309AbjG1OUx (ORCPT + 99 others); Fri, 28 Jul 2023 10:20:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236993AbjG1OTc (ORCPT ); Fri, 28 Jul 2023 10:19:32 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 591ABB5 for ; Fri, 28 Jul 2023 07:19:30 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31751d7d96eso2022033f8f.1 for ; Fri, 28 Jul 2023 07:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1690553969; x=1691158769; 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=mzaljnOO1Gw4qS38ZHWvBAE06zq5Umr4CoJZWfxvzDg=; b=xUKyFTsSuvcbCo9x7xJzgCo0oi8PFn1TINP4lMKpkxprTf0fSFnKI6CO/S5K6BG4U4 aoSzf21spDOrbbJxqmOzt3E2ezOIXsAIegZZXaBpZ9sTRLPzZnHfC4sH6o6QWLc8Rogr +yXcap8TxO+tUAf6McFVa8Iuk4X2x1lQaF3GXWSpz64Q4LI590V++pfeW+hUbDZ/qbCK FdP4mQBw+v/PRGEN8ni/vSzX4KVKhkasOtgZvmStCpQZ5+cI1dpATaCtFOrMzXBBOSQh 9MVaZXQDFeOApmJTmwVjSyFg6Y6Vt3Z6yE8pIAkRw08w7U+eKNQ/aROZB6Tck/bZQ/SC +Y5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690553969; x=1691158769; 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=mzaljnOO1Gw4qS38ZHWvBAE06zq5Umr4CoJZWfxvzDg=; b=W/0vYm4m5so4JLFEqP1hhvok/PoHg8ir4A2c920NeMQJg95jLF/Y0u5XS6vjFDTxOY tZU/TMwaWlELr6BnkRDcOMFiex5vn/7B76pgd31K/2QsHzlf4Q9dh1z5fmSY/jBptFRB RdWiqTBqWIR3OwhCAyozns3nQ1djLr7hoCZIw4KhFyUWpYdUKnw6G576pm3mSv/LDBX9 SqVCJ/59FZCCWow833yuzVxs3ltUWr2gdhcis0tDwad7ln3ZwkvGu8LMjm3Y94CH6AV4 p3iE0hqfNewvf5Gg2Oz2ZEoWBva1DwE0Y7YsvVy3fqFrfHrhvZHZc5hxuNifWXP/iUqU 7/JA== X-Gm-Message-State: ABy/qLZb/Lqp+2Boet00roTHetY0jLFB7YHS/5hRN9wRl/UkV7dtaCfL 1oCTC3EUbmeBW2Qxowkn2/LoZA== X-Received: by 2002:adf:d84b:0:b0:317:568d:d69a with SMTP id k11-20020adfd84b000000b00317568dd69amr1991756wrl.11.1690553968837; Fri, 28 Jul 2023 07:19:28 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4090:a246:80e3:766f:be78:d79a:8686]) by smtp.gmail.com with ESMTPSA id l6-20020adfe586000000b0031416362e23sm5013681wrm.3.2023.07.28.07.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 07:19:28 -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 v4 3/6] can: tcan4x5x: Check size of mram configuration Date: Fri, 28 Jul 2023 16:19:20 +0200 Message-Id: <20230728141923.162477-4-msp@baylibre.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230728141923.162477-1-msp@baylibre.com> References: <20230728141923.162477-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=unavailable 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 c5af92bcc9c9..9210cf0705a1 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