From patchwork Thu Aug 8 16:42:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_M=C3=A4tje?= X-Patchwork-Id: 13757940 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2122.outbound.protection.outlook.com [40.107.22.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E84F1646; Thu, 8 Aug 2024 16:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.122 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723135352; cv=fail; b=qz2C+U2gSU2CQc8FLzcnx25KHeypm5o2AYY0S+JF305jkL8csBG8k+1ClhFbMBt1Fogm9wAqrFSdO0nm56IU8L1zd4TBPZvLsw8DAkfCGnn1GszQEr/Dg53VbSs976aJ47Gg2tvTfvHKoP8pU08WH/G14grUy56Ti1HqJNRmcfY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723135352; c=relaxed/simple; bh=bJXcw/+v8pixev3DGbrxDJVj7iozsH7QJ/bV7c5EGmg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=Krj5JSB4lP7eOlM/MeKm0S8fJqYT2+/7l5Q3CpuC+zIxHmULlKuaGhPch1zqKF77Akaxb89jn1fU4z0+vIpn4mfnKUocqLXP0qZ20p2QdlI36MelwusocBsMJxSgDfOp/s5tMI+TZFCzEA4lN9p7cwoRt6PDgDkXecsJOAc1y3k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=esd.eu; spf=pass smtp.mailfrom=esd.eu; dkim=pass (1024-bit key) header.d=esdhannover.onmicrosoft.com header.i=@esdhannover.onmicrosoft.com header.b=EXYzXYIR; arc=fail smtp.client-ip=40.107.22.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=esd.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=esd.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=esdhannover.onmicrosoft.com header.i=@esdhannover.onmicrosoft.com header.b="EXYzXYIR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=csRrQ98vJzW4DMTpKMVcDjOyK/dX0WfVbdOw/PUPrNDZapY4NBGkk5JPtbTMAjy6bdDfiSdPgAmcCCcw2Hr3ApfuFmQDF+U7iQN/oowMKx6JLT6rN9tiTl2si8+6s/0JjueYbWdWETxFMviRtABCtf4Rdvk3iTcUg/f1alaDCrotiY3pq2a2T+wIpxi5SOhkw00pOrv8LdcCTAPGjjVvJVQglXfaVy48RmSc4FeVooMPEKx5oW77wBlwnYJ7+yjF2X1ZNV/gSo70wwwhl/eEbMEzS9KYMMu3oKO2Rd5ExiprteajY6+0Guo/tsA6E0w9xfewUmzE3qz2HhgswSvq3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=22hkwKW4f+Ugr5+IIQbXzI3JGI+hij0UgS482ya38dU=; b=idS04KLvDEbomAOPKBEZdzwm8Kkm+mcqXqCuI2be+qmyMg//TUYHA7/S0gG0ij0TiVSMerM0lNjoHUJmL7eGlOWJ9a2OJFEKxpxxKBJ1sjQJyRwt4kvdx3Y7u8q8NmrHlDPk2RG4a9ZIaRuOwMLiNAQzCWQqGmMEBaOMy9lkwCoXBoqzggBrqZ+yHXaGObCHei9BCFjNFCFZEyaPN7qYbkzOLn8t1UaYDwPZlbgIf7YYtYitTJBbbr2Ro3PBBY6+71IiF7G0tbesKMHrw22F9BXo4jxLFf1EWGcFkesFezII2wk0ECGZtqaMFUHONYPNTCgxuFklISbkUJ9RcQQYmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 80.151.164.27) smtp.rcpttodomain=davemloft.net smtp.mailfrom=esd.eu; dmarc=fail (p=none sp=none pct=100) action=none header.from=esd.eu; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=esdhannover.onmicrosoft.com; s=selector1-esdhannover-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=22hkwKW4f+Ugr5+IIQbXzI3JGI+hij0UgS482ya38dU=; b=EXYzXYIRCDSu+8fmWhieTJL1IPn27Dw5/xzz5ojhj5Vz7QanC4Z4hdn2C3MQ7evMDTOdvWFjaCJ+nMHjJey07aOMc3wxEBZjF8AZ1YyBcBi3UJRzI9VxvppjMdFLegB0vPwmSzQXUzX8ygizULHG2s/eXdIhliRGoJc7RikiOuw= Received: from DB7PR05CA0006.eurprd05.prod.outlook.com (2603:10a6:10:36::19) by DU0PR03MB9198.eurprd03.prod.outlook.com (2603:10a6:10:47a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 16:42:25 +0000 Received: from DB1PEPF00039233.eurprd03.prod.outlook.com (2603:10a6:10:36:cafe::11) by DB7PR05CA0006.outlook.office365.com (2603:10a6:10:36::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Thu, 8 Aug 2024 16:42:25 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 80.151.164.27) smtp.mailfrom=esd.eu; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=esd.eu; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning esd.eu discourages use of 80.151.164.27 as permitted sender) Received: from esd-s7.esd (80.151.164.27) by DB1PEPF00039233.mail.protection.outlook.com (10.167.8.106) with Microsoft SMTP Server id 15.20.7828.19 via Frontend Transport; Thu, 8 Aug 2024 16:42:24 +0000 Received: from debby.esd.local (debby [10.0.0.190]) by esd-s7.esd (Postfix) with ESMTPS id 928157C1278; Thu, 8 Aug 2024 18:42:24 +0200 (CEST) Received: by debby.esd.local (Postfix, from userid 2044) id 7E4D32E4731; Thu, 8 Aug 2024 18:42:24 +0200 (CEST) From: =?utf-8?q?Stefan_M=C3=A4tje?= To: Marc Kleine-Budde , Vincent Mailhol , linux-can@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH] can: netlink: avoid call to do_set_data_bittiming callback with stale can_priv::ctrlmode Date: Thu, 8 Aug 2024 18:42:24 +0200 Message-Id: <20240808164224.213522-1-stefan.maetje@esd.eu> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF00039233:EE_|DU0PR03MB9198:EE_ X-MS-Office365-Filtering-Correlation-Id: cae2accb-9c24-46e6-7dfe-08dcb7c91523 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?oMbPH2d2jn9GYg5qcJ+MEZ/5BUMU5CA?= =?utf-8?q?78U3ndLmpwkHD5jca7kb69A63XP6ETdYca7wmFH+87vMnd6wU3gyFSOVO5htJja9g?= =?utf-8?q?7EqT8Tqk468L1exiVkfMNlpcur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a3S6fNaftkwcPyqov7RtwT4WafrshUT?= =?utf-8?q?pK1mxqstueNufJ0MS8AitAllbqS0JmYuvp1e6crYzatBiECku7b/+pIhY8IXITBVk?= =?utf-8?q?qcietncDflKSF99YU/kvyou4KZUbT+n/mDPzPEGsxnMRxLhTxFA7ni9Z17/fS6HQa?= =?utf-8?q?HnUz2AW1BtLwaYlGTBZZwzDF3ciYow9ZO/V4fIHXPubFdr22XkUr52SCPooL1Uo5e?= =?utf-8?q?T7dbrSn/FNz2/9FCEpmYNvDrOfGj8WIn8uZgfGP2HIYb0azp1MtOFR/CMg8Tz1COJ?= =?utf-8?q?dLFuUvD57dQGscLZRofn2vYPyxhvgT1GljzKGnAtonDtMfo85m9tWs7wpdlvln4Op?= =?utf-8?q?OBIJaH2UvSF8QwaAC9ohXEDutRp0TBfJ7hPU38TmsECNxCP1RSc0sWxOUiUHWl3Om?= =?utf-8?q?YQ4jsrqfSlV?= X-Forefront-Antispam-Report: CIP:80.151.164.27;CTRY:DE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:esd-s7.esd;PTR:p5097a41b.dip0.t-ipconnect.de;CAT:NONE;SFS:(13230040)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1102; X-OriginatorOrg: esd.eu X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2024 16:42:24.9474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cae2accb-9c24-46e6-7dfe-08dcb7c91523 X-MS-Exchange-CrossTenant-Id: 5a9c3a1d-52db-4235-b74c-9fd851db2e6b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5a9c3a1d-52db-4235-b74c-9fd851db2e6b;Ip=[80.151.164.27];Helo=[esd-s7.esd] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF00039233.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9198 X-Patchwork-Delegate: kuba@kernel.org This patch moves the evaluation of data[IFLA_CAN_CTRLMODE] in function can_changelink in front of the evaluation of data[IFLA_CAN_BITTIMING]. This avoids a call to do_set_data_bittiming providing a stale can_priv::ctrlmode with a CAN_CTRLMODE_FD flag not matching the requested state when switching between a CAN Classic and CAN-FD bitrate. In the same manner the evaluation of data[IFLA_CAN_CTRLMODE] in function can_validate is also moved in front of the evaluation of data[IFLA_CAN_BITTIMING]. This is a preparation for patches where the nominal and data bittiming may have interdependencies on the driver side depending on the CAN_CTRLMODE_FD flag state. Signed-off-by: Stefan Mätje --- drivers/net/can/dev/netlink.c | 102 +++++++++++++++++----------------- 1 file changed, 51 insertions(+), 51 deletions(-) base-commit: ae44fa998ee280303ee5dffe99cb669e4c245706 diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index dfdc039d92a6..01aacdcda260 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -65,15 +65,6 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[], if (!data) return 0; - if (data[IFLA_CAN_BITTIMING]) { - struct can_bittiming bt; - - memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); - err = can_validate_bittiming(&bt, extack); - if (err) - return err; - } - if (data[IFLA_CAN_CTRLMODE]) { struct can_ctrlmode *cm = nla_data(data[IFLA_CAN_CTRLMODE]); u32 tdc_flags = cm->flags & CAN_CTRLMODE_TDC_MASK; @@ -114,6 +105,15 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[], } } + if (data[IFLA_CAN_BITTIMING]) { + struct can_bittiming bt; + + memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); + err = can_validate_bittiming(&bt, extack); + if (err) + return err; + } + if (is_can_fd) { if (!data[IFLA_CAN_BITTIMING] || !data[IFLA_CAN_DATA_BITTIMING]) return -EOPNOTSUPP; @@ -195,48 +195,6 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[], /* We need synchronization with dev->stop() */ ASSERT_RTNL(); - if (data[IFLA_CAN_BITTIMING]) { - struct can_bittiming bt; - - /* Do not allow changing bittiming while running */ - if (dev->flags & IFF_UP) - return -EBUSY; - - /* Calculate bittiming parameters based on - * bittiming_const if set, otherwise pass bitrate - * directly via do_set_bitrate(). Bail out if neither - * is given. - */ - if (!priv->bittiming_const && !priv->do_set_bittiming && - !priv->bitrate_const) - return -EOPNOTSUPP; - - memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); - err = can_get_bittiming(dev, &bt, - priv->bittiming_const, - priv->bitrate_const, - priv->bitrate_const_cnt, - extack); - if (err) - return err; - - if (priv->bitrate_max && bt.bitrate > priv->bitrate_max) { - NL_SET_ERR_MSG_FMT(extack, - "arbitration bitrate %u bps surpasses transceiver capabilities of %u bps", - bt.bitrate, priv->bitrate_max); - return -EINVAL; - } - - memcpy(&priv->bittiming, &bt, sizeof(bt)); - - if (priv->do_set_bittiming) { - /* Finally, set the bit-timing registers */ - err = priv->do_set_bittiming(dev); - if (err) - return err; - } - } - if (data[IFLA_CAN_CTRLMODE]) { struct can_ctrlmode *cm; u32 ctrlstatic; @@ -284,6 +242,48 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[], priv->ctrlmode &= cm->flags | ~CAN_CTRLMODE_TDC_MASK; } + if (data[IFLA_CAN_BITTIMING]) { + struct can_bittiming bt; + + /* Do not allow changing bittiming while running */ + if (dev->flags & IFF_UP) + return -EBUSY; + + /* Calculate bittiming parameters based on + * bittiming_const if set, otherwise pass bitrate + * directly via do_set_bitrate(). Bail out if neither + * is given. + */ + if (!priv->bittiming_const && !priv->do_set_bittiming && + !priv->bitrate_const) + return -EOPNOTSUPP; + + memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); + err = can_get_bittiming(dev, &bt, + priv->bittiming_const, + priv->bitrate_const, + priv->bitrate_const_cnt, + extack); + if (err) + return err; + + if (priv->bitrate_max && bt.bitrate > priv->bitrate_max) { + NL_SET_ERR_MSG_FMT(extack, + "arbitration bitrate %u bps surpasses transceiver capabilities of %u bps", + bt.bitrate, priv->bitrate_max); + return -EINVAL; + } + + memcpy(&priv->bittiming, &bt, sizeof(bt)); + + if (priv->do_set_bittiming) { + /* Finally, set the bit-timing registers */ + err = priv->do_set_bittiming(dev); + if (err) + return err; + } + } + if (data[IFLA_CAN_RESTART_MS]) { /* Do not allow changing restart delay while running */ if (dev->flags & IFF_UP)