From patchwork Mon Apr 15 08:50:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13629652 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2A35C04FF9 for ; Mon, 15 Apr 2024 08:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=e0DIpwe1cfUSziWyx8/FWqmWZ8qaEVa3LK3dNBykAVA=; b=4fm2RsGwfz78H41SUrTKadC+XZ reA0GsP6D77ZI1aEmZgRyLlS9uhy0JwyXr01xNBBrmNg/98ZdmD4gas8Y+m9eIZ8DGHRiOTZfnvXc A4S/1wTA0q60bSXuRNTyUtG+qyixN7Gsec1ncN/d9vAADnhU6ACEp7aFz51emjCuu7t6MdBe8/3Cx PIj1wue77qFP2NZeKegGkaa+1rKCkmh+JuioqlMfdnQxnrq5Rg4sDYltK+Z5ng65WwSsv3Bx02+i5 RtFcRt/T5us4+pjYDNnJbr/xD6qq0/sW1oOB3OnEn3VpWWRgqsurqt1Obwcr/h9Z58TAdWrW41Px0 H8+QbScw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwHvk-00000007a9C-1K8B; Mon, 15 Apr 2024 08:43:13 +0000 Received: from mail-am0eur02on20600.outbound.protection.outlook.com ([2a01:111:f403:2606::600] helo=EUR02-AM0-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwHvc-00000007a4V-0xuB for linux-arm-kernel@lists.infradead.org; Mon, 15 Apr 2024 08:43:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TNk7i+YE7bKCjOzWQM6/OFAeBS9JyrKZ4pbVhkM4DIqwxNbEXnaPBqG9a8pSxR/cfdt0FzIipquEmYXbmkaS+IgfKLRV+r/okZgAmC7vwnmPb8mESz59TpyFLffUZLc5oqPMevzSmsj9XUA6X0XB/pRVP+QWe68EWaX3D797FMqJHO9U5smHZZqwssZgdxBfuNg+NwMVRqznV36UApymPBRndhZQ5/2SjO2UOgnXsMexwY1qSUJrC8F6TGwrn+/BqcE7dUfU8uuIf6zTtEGi6+byMk7Zm8nwhrwteCIRyLQLIPCjAOp/AfOv149O43yr869Zer0qrNhCfHt1duXODA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=y32EPUygoezOrwpSdGDK5Cezq+RoDLA6Ci/XuseYkwM=; b=eKj13Kwd94Qhfr58iaVlkeiEQPISRtLXhjRee5cbqsBEafmKf09CQVbtlYL3J9GUY1jvWqjiQNtXr7UpRIL5IT9jc7DuvRP+BHEZYFHxGJhd8ey2LT4H0ChB9i/KMW1kwLHyiWZwE78h/rUdttpvgrTHL8sLzTD164x3s5c4xGDA+wDbUzJ17rvZ8F8pBlqwQEhbDq/FcZoolDet1NLqHGuIMaIuNKk8Nr+5ImXa0ano88s8kJ1u6HAh8HaTMReHlWF2wQ4N1epmjomrodwAXVSNtmM3VdxIi7d8U5IBdbHCQZ9kotRJsJczt4UbI5jPrM1g8xSJ1pQeEcJnm8mdpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y32EPUygoezOrwpSdGDK5Cezq+RoDLA6Ci/XuseYkwM=; b=EP/al6OQL8mP4oJZFsDGz1o0lgiGMtvKeusDxti31LVKQ89MirqywjwAQrHNPZtTbknJyQFFNcoCB50qC33m62JfKUS4vQvyo2VQ6vVLK1mtwrPRA6NxQPkBxO7RWo0sOOHgcWzjvubjRy6155BWoiVp74eXDQwInuL+v1bG9tQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by AM9PR04MB7506.eurprd04.prod.outlook.com (2603:10a6:20b:281::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Mon, 15 Apr 2024 08:42:54 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d%4]) with mapi id 15.20.7452.041; Mon, 15 Apr 2024 08:42:54 +0000 From: "Peng Fan (OSS)" Date: Mon, 15 Apr 2024 16:50:49 +0800 Subject: [PATCH v10 1/4] firmware: arm_scmi: introduce helper get_max_msg_size Message-Id: <20240415-pinctrl-scmi-v10-1-59c6e7a586ee@nxp.com> References: <20240415-pinctrl-scmi-v10-0-59c6e7a586ee@nxp.com> In-Reply-To: <20240415-pinctrl-scmi-v10-0-59c6e7a586ee@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Dan Carpenter Cc: Dhruva Gole , Andy Shevchenko , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713171061; l=2695; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=fC1f9Mz+AZ7lC+TNU94i2E/beyKrQPUiXgoBP0YzZ74=; b=q5GWIty/C0+zNWWjGsIah4qVnecIS9Ayc3PFWTIfTzo9dwsUsAQQo+LAgNGgyPjWdAe4NVBgZ lPug89jxOmvBEdjNO9GSpJkQX/WE9Vg3PT2WG31FWj4ndQrDSUsPE/8 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0011.apcprd02.prod.outlook.com (2603:1096:3:17::23) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|AM9PR04MB7506:EE_ X-MS-Office365-Filtering-Correlation-Id: 455b1994-0774-4da6-138f-08dc5d280ab0 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1oW3xd2QTJQvQNf2tfx9vtAqhCKPvTYaU/DOrwApDn3fq3PBxKvrEAEoN9zfxBJeRO3N5JxISBED1OI75rxCGpO5o/QYG1wRwc4NqcAn2hjxAE9zNNrO7KDkHccf0Yp855V3Q2qoWCDpF1qH1+lEjYabbKD89wTQEObwMq339JZYTlMxK/gKXpdvcsi7k+QnY5oduNtAvBxPZmeWkdbgPm7S/8JSb2ahPxO+adhb4LHRTtetrHXCs+ZOAFOXMaV6YQoAmX+TghZo6LDCT0w6SiVcPGzsgzdYNZwMg7CypNgIYjdQuIg6rlgwwq4XQIE37R9Ckg8EZW4QUs1ECJN+b6beRP8KqbWfyye0gB2n8nflTHihtOuGPmT9RcIOUlatN3enKLJ7l0drGFWM2zrRmycAg6mOjTxq7R/PAttyhgko/LuGHCLt63r4QC+ZHVN6TlxcUUmXsEMRnOKPVmqYVth7xqbJb9mXqiDAdwwze+roBPE+qi0oualjv4EGpHkQ2LFQuSrXKliiiRGqwkToGOqep2Eh840lbIlb0oICfis2O1Avb1wIYH1wpYzDWJUmbi4lcIZSQtpPvC3KNIPNul9pFdETXQNVpvJUc7ZPCdjqvWpcc5luQ/XdvwMcdF2iGTXuv2u3grsVYAolGHeFDd0Pq+pGdZwjQnC6d9VZ2SairDx41nxUpax08MUf+CDTBefvkkZZLJJQJRJJrW7Ap2F/286YFiDdkyOPXHFke0Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9417.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(7416005)(52116005)(376005)(366007)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?6GQLPpJQfYLY2/Qp9gXQrA4rQ5B7?= =?utf-8?q?JzPYupiObyhlpAJVXg6UJ/L1Xvr5Vzfm0Ax0LzsPtBQaDzjgqZ1c7rkmlmL2qhkYH?= =?utf-8?q?QvPoxGwN8gzhqIn4sLoQpDM9Tu+V/FkBV7VCblBwStCN2QZBG6SW3FbnQWWwnS/iG?= =?utf-8?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WEyASaJRWJc9fDifS7+SDCknLolwhljhXEpaD/Hicsv8Bo4rWVQwV5wwQi5?= =?utf-8?q?8bkj4TY+6VwgYoy4/P9EK5YFe4BXQP9Uxx9Rx4EdO8qodfYKUnKsB0iTmxClOt4ut?= =?utf-8?q?BKmH9yFqz0eJkkYjk3wy8clfzDgsELAw0ZbuwoKhuawfNC0ly3loZmBcKbfVuHmU7?= =?utf-8?q?HSNsHtlAkuMU/RSYpNwjAImwTFK7mV6zCpk8W8lfc9m6c9EmkycHYNQyIUQo1jh2m?= =?utf-8?q?k3nAOIsJO7oNGIF59UpAI8uznuy1p13r2CEJv9vORv8DNOT0aO54uZBP5QoFsQZ8j?= =?utf-8?q?a2I0XTL5jCIPG1j55Nz/aMe6hNrNXW+VxqZMvqklmmgbV54Ms0wvbHkZuFU6YDlMS?= =?utf-8?q?si49HoDRTi0BUaXfRUIwS/j0hGrbeLEYQUGBxrrV+6j27rCgOMRkRY7ndN8Lk3+y7?= =?utf-8?q?0LfEjkpAyImCnzp1DHEdFOpnff0ADUyvwYBdqv/VfUchQuantMS+SrezFqf7Xfiqz?= =?utf-8?q?/D26flwyhDKK?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 455b1994-0774-4da6-138f-08dc5d280ab0 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2024 08:42:54.0925 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HGEMAkTUl2yEsZDfjGx72mVJlCiixm2WKAPwbx3uiZOC/A1MOwI2cw0J1rPzTMbmRsFKofGdrZw/cdJ/9laWqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7506 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240415_014304_335032_D191279C X-CRM114-Status: GOOD ( 11.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peng Fan When Agent sending data to SCMI server, the Agent driver could check the size to avoid protocol buffer overflow. So introduce the helper get_max_msg_size. Reviewed-by: Cristian Marussi Reviewed-by: Dhruva Gole Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/driver.c | 15 +++++++++++++++ drivers/firmware/arm_scmi/protocols.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 36e3eb50a8d4..a1e0e8fa4bb7 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1537,6 +1537,20 @@ static int scmi_common_extended_name_get(const struct scmi_protocol_handle *ph, return ret; } +/** + * scmi_common_get_max_msg_size - Get maximum message size + * @ph: A protocol handle reference. + * + * Return: Maximum message size for the current protocol. + */ +static int scmi_common_get_max_msg_size(const struct scmi_protocol_handle *ph) +{ + const struct scmi_protocol_instance *pi = ph_to_pi(ph); + struct scmi_info *info = handle_to_scmi_info(pi->handle); + + return info->desc->max_msg_size; +} + /** * struct scmi_iterator - Iterator descriptor * @msg: A reference to the message TX buffer; filled by @prepare_message with @@ -1848,6 +1862,7 @@ static int scmi_protocol_msg_check(const struct scmi_protocol_handle *ph, static const struct scmi_proto_helpers_ops helpers_ops = { .extended_name_get = scmi_common_extended_name_get, + .get_max_msg_size = scmi_common_get_max_msg_size, .iter_response_init = scmi_iterator_init, .iter_response_run = scmi_iterator_run, .protocol_msg_check = scmi_protocol_msg_check, diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h index 317d3fb32676..3e91536a77a3 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -258,6 +258,7 @@ struct scmi_fc_info { * @fastchannel_init: A common helper used to initialize FC descriptors by * gathering FC descriptions from the SCMI platform server. * @fastchannel_db_ring: A common helper to ring a FC doorbell. + * @get_max_msg_size: A common helper to get the maximum message size. */ struct scmi_proto_helpers_ops { int (*extended_name_get)(const struct scmi_protocol_handle *ph, @@ -277,6 +278,7 @@ struct scmi_proto_helpers_ops { struct scmi_fc_db_info **p_db, u32 *rate_limit); void (*fastchannel_db_ring)(struct scmi_fc_db_info *db); + int (*get_max_msg_size)(const struct scmi_protocol_handle *ph); }; /**