Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp399971pxb; Mon, 25 Oct 2021 10:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyW0///lAO/zQZXpikk7OQ6j0yVmCvzgg/RrGApTqJt9w9cjrVu+9jdOnt92ZaD2rmzkqtA X-Received: by 2002:a17:907:3e85:: with SMTP id hs5mr24076901ejc.234.1635182787171; Mon, 25 Oct 2021 10:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635182787; cv=none; d=google.com; s=arc-20160816; b=q65rMqhYv6CbeH97kDQNs/upidLZTBJuvJTx/pAcbSSiJa89WYtpAHea5nLo+XQ+3k fPh6cmV1FiFfU74sIhu14L1T0gmneUeKCUWApdcDl3CFPDGvUv7Hjmw62d3pg6RyV6IP 1vZQ7fqf/eAQcd3ow4mlVCjg2ZC64czqP+nSsfA1Ll7pKHLG71H9FBs7Bta9DJaRONxi R8oKiKd7EsihfyuNVgoHEOgRrWF+67G0ZzP1N90cQm3WgW5gIFRXFW6LLs+DRRQtIBOQ tJPY7brkjTVz9no9aRnNIzNuYm0m3n9kp/njyTg7aDNMSsWOiKxx/SrGnCDMDStqeaCz 4aqQ== 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; bh=vgcj1UKUPHQwqF/heDhzPcHAivhkFP29jXjfsDwqEa0=; b=KZAsJ2nhB6ltWE+meg4BrgR10sBKdOpxnU+fec0CVP8ajDue4evMiCljJLkdxbp1n1 Kb2tYOeOMV6G2+IgV7ChE0iyF/36nXiUYnty26mF1HR4tgQwisat+T8WHZTUHUteLPdr dv/CGlRfsJ03GuqXf2EdZ3syVcTT3qXbrnaikwClNNQV9ZU0MnR/3sJvP1mkJ6IeypIW 1co7wX9TFAP1eKXYerseqr/0Zbk0YV89qFzYdGYrBOsIeOPGMsO4EW7w3tQSN97rS1NM +IpXfTu0duh53l6W81tcr+8dyqKoyQBFmjvedPH+dzqYIR0fEsDUqIWSn9c8kE1fGXIh 8QeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id js16si8845265ejc.715.2021.10.25.10.25.48; Mon, 25 Oct 2021 10:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233585AbhJYRZr (ORCPT + 99 others); Mon, 25 Oct 2021 13:25:47 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:62547 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233471AbhJYRZp (ORCPT ); Mon, 25 Oct 2021 13:25:45 -0400 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by smtp.orange.fr with ESMTPA id f3gYmY0E4niuxf3gumufFq; Mon, 25 Oct 2021 19:23:22 +0200 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Mon, 25 Oct 2021 19:23:22 +0200 X-ME-IP: 114.149.34.46 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Mailhol Subject: [PATCH v3 1/4] can: dev: replace can_priv::ctrlmode_static by can_get_static_ctrlmode() Date: Tue, 26 Oct 2021 02:22:44 +0900 Message-Id: <20211025172247.1774451-2-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211025172247.1774451-1-mailhol.vincent@wanadoo.fr> References: <20211025172247.1774451-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The statically enabled features of a CAN controller can be retrieved using below formula: | u32 ctrlmode_static = priv->ctrlmode & ~priv->ctrlmode_supported; As such, there is no need to store this information. This patch removes the field ctrlmode_static of struct can_priv and provides, in replacement, the inline function can_get_static_ctrlmode() which returns the same value. Signed-off-by: Vincent Mailhol --- drivers/net/can/dev/dev.c | 5 +++-- drivers/net/can/dev/netlink.c | 2 +- include/linux/can/dev.h | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c index e3d840b81357..59c79f92fccc 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -300,6 +300,7 @@ EXPORT_SYMBOL_GPL(free_candev); int can_change_mtu(struct net_device *dev, int new_mtu) { struct can_priv *priv = netdev_priv(dev); + u32 ctrlmode_static = can_get_static_ctrlmode(priv); /* Do not allow changing the MTU while running */ if (dev->flags & IFF_UP) @@ -309,7 +310,7 @@ int can_change_mtu(struct net_device *dev, int new_mtu) switch (new_mtu) { case CAN_MTU: /* 'CANFD-only' controllers can not switch to CAN_MTU */ - if (priv->ctrlmode_static & CAN_CTRLMODE_FD) + if (ctrlmode_static & CAN_CTRLMODE_FD) return -EINVAL; priv->ctrlmode &= ~CAN_CTRLMODE_FD; @@ -318,7 +319,7 @@ int can_change_mtu(struct net_device *dev, int new_mtu) case CANFD_MTU: /* check for potential CANFD ability */ if (!(priv->ctrlmode_supported & CAN_CTRLMODE_FD) && - !(priv->ctrlmode_static & CAN_CTRLMODE_FD)) + !(ctrlmode_static & CAN_CTRLMODE_FD)) return -EINVAL; priv->ctrlmode |= CAN_CTRLMODE_FD; diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 95cca4e5251f..26c336808be5 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -211,7 +211,7 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[], if (dev->flags & IFF_UP) return -EBUSY; cm = nla_data(data[IFLA_CAN_CTRLMODE]); - ctrlstatic = priv->ctrlmode_static; + ctrlstatic = can_get_static_ctrlmode(priv); maskedflags = cm->flags & cm->mask; /* check whether provided bits are allowed to be passed */ diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 45f19d9db5ca..92e2d69462f0 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -69,7 +69,6 @@ struct can_priv { /* CAN controller features - see include/uapi/linux/can/netlink.h */ u32 ctrlmode; /* current options setting */ u32 ctrlmode_supported; /* options that can be modified by netlink */ - u32 ctrlmode_static; /* static enabled options for driver/hardware */ int restart_ms; struct delayed_work restart_work; @@ -139,13 +138,17 @@ static inline void can_set_static_ctrlmode(struct net_device *dev, /* alloc_candev() succeeded => netdev_priv() is valid at this point */ priv->ctrlmode = static_mode; - priv->ctrlmode_static = static_mode; /* override MTU which was set by default in can_setup()? */ if (static_mode & CAN_CTRLMODE_FD) dev->mtu = CANFD_MTU; } +static inline u32 can_get_static_ctrlmode(struct can_priv *priv) +{ + return priv->ctrlmode & ~priv->ctrlmode_supported; +} + void can_setup(struct net_device *dev); struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, -- 2.32.0