From patchwork Wed Jan 25 19:50:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 48274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp456081wrn; Wed, 25 Jan 2023 11:52:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXsBPeMJQk3+8vFzpft+5Dw02S1BXOYEfnIxlgPG9kJ4rfy03Nvf4LK4e3e4IC5kF7RfQQB6 X-Received: by 2002:a05:6a20:3558:b0:b8:8d2a:d37d with SMTP id f24-20020a056a20355800b000b88d2ad37dmr33112805pze.10.1674676324784; Wed, 25 Jan 2023 11:52:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674676324; cv=none; d=google.com; s=arc-20160816; b=CCiBUP14ExLHSwZWpetlJF8E8bCA1glLARwVJdw9vZM9Jhc+40pRMTbKJut3pb72aB 3sMNwMsnTJcURcow91VZTSM4Dx+qZGDPs1cJ6GD5rUb7AHPhODVX+8KphQxBW3l881hJ XSKA0yyWCyaXmx9WPKBYHW1VqTnwZG0isc5Ep78JHH4eZMtd99+WNC3Cr9tHpR9kiy0N 1yEn3JmkXHEOsZMik93RxXisHoyk9JefR11RRBDTjzUaj9ymgmo8YkszZfk+FnwKqupT NdXiOMDJz0bP/grkvwrewqX5ngZ7sQLKL52V5awjM4egtJWvQ+kD5PthLiEvltGRYniq 5Ang== 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=49DCUG0FS6JWgdUUPYZw1kraoVWOTArEkjTgYYh32tM=; b=nPqIrBlcujO8wM/HwChvN1w0aTZpvH+8EThQh0fF685Bi2yKU7+uAuHFOS3OSa/+Tt HknGFTRhnYn6mt8AEEeBtlZ3NJl7rsmdG17gyHa0Mtu9YVASVVmOiJtClvMwQ9ZerYHR ytxKPPGIiBN3QIJa+hzxdjKS8u/u0LXK1qa4QBhcveqIetZ2UFrJlYh779GQgFc14pWK /8E8RF1Lyd+g70EeHBKPiWUxfUXWLdCMAMd7F2X7Zcx9b7EBuQRdWjgu9+8aBv5cgoyP nDebFzp1AfJ6ry1ZshNyekOT2Yp1b6b1MXpbl2VAbgNjnJo76ADkMj9WPRw5C/X+Bloy nFcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=T3x6Slzy; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h189-20020a6383c6000000b0046ff26f21f0si6058858pge.503.2023.01.25.11.51.52; Wed, 25 Jan 2023 11:52:04 -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=T3x6Slzy; 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 S235764AbjAYTvR (ORCPT + 99 others); Wed, 25 Jan 2023 14:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235501AbjAYTvJ (ORCPT ); Wed, 25 Jan 2023 14:51:09 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4557589BD for ; Wed, 25 Jan 2023 11:51:07 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id az20so50682119ejc.1 for ; Wed, 25 Jan 2023 11:51:07 -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=49DCUG0FS6JWgdUUPYZw1kraoVWOTArEkjTgYYh32tM=; b=T3x6SlzyLZpgEUFsbjMT4SA+6d24DwTx7kCaFHQK6NA+tO62hkIfFFUC5i9HlGvCiY VO1SlLpwDGSuZfJJKYhiD+S0j0eVMaIL4ca2k/orI5EVJl27fYkjEu0M3tSnkawNjJlw oeAC6uAjZTp8awX53JRC3TjOu0yIv8IpLIP9JBNSM1Uj1sMjYltGPuojFVVBQkvtB8yw 1a+O+3D6ZFz/TbnfTmouKhL3+9tY8pUtJdA88EzMDdPGgKJB2JFoSR2q87wUwe+rc7m8 RKMkHbwEEsN1KvzR/ijJXBB5pKGtTjkjuE5L6FVGxZAslrQUiMn1yK9WtRFlnW30bePi 72sQ== 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=49DCUG0FS6JWgdUUPYZw1kraoVWOTArEkjTgYYh32tM=; b=a6EkS6+R9Zf67saKeBo4k4hKQE/ufykJdGD4y9XWWPD0sXMK9sqndC8Zakn7JFWpFH clAN8IBR64Gv5ynILiioxovgGBQ6nchsj3nbhOa8Ns+sJv3JWt9hEGTPqDTFqbFjlxG6 MkDqn3VCYxYg1u2+qngG5wLFj2t6wZDZMajNpQxPh9vE0VpScud7zEK0ifBwFJYhmdZm A6KH8NKO8F19juwn5WVPhQdRheup+pwdEBJCfKTGDNy0zFGRZUG4MfgdaQhcJrJ7UdPG uUTqGYs6JE0YnOGOj+YSbaTiYk0UjjxyW/dvxFl/yp42KdPE4EDTVZlP4tj8UdYOwAXh 5gSw== X-Gm-Message-State: AFqh2kpE2jStFZvpGk0NdbTCfCS/yYplHueRt8sT9IsrylCejKQDpBeR jeWOPIBOTaDtXivlmr1xbsvPqA== X-Received: by 2002:a17:906:3515:b0:7c1:1b89:1fe0 with SMTP id r21-20020a170906351500b007c11b891fe0mr33115318eja.65.1674676266354; Wed, 25 Jan 2023 11:51:06 -0800 (PST) Received: from blmsp.fritz.box ([2001:4091:a247:815f:ef74:e427:628a:752c]) by smtp.gmail.com with ESMTPSA id s15-20020a170906454f00b00872c0bccab2sm2778830ejq.35.2023.01.25.11.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 11:51:06 -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 v2 02/18] can: tcan4x5x: Check size of mram configuration Date: Wed, 25 Jan 2023 20:50:43 +0100 Message-Id: <20230125195059.630377-3-msp@baylibre.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125195059.630377-1-msp@baylibre.com> References: <20230125195059.630377-1-msp@baylibre.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756025401878981996?= X-GMAIL-MSGID: =?utf-8?q?1756025401878981996?= 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 8e83d6963d85..8ccf20f093f8 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1886,6 +1886,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");