From patchwork Thu Mar 14 13:35:18 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: 13592447 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 DCEECC54E60 for ; Thu, 14 Mar 2024 13:27:37 +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=tOafxq2pcJxBKhqf/S3S3gPGC2+bN17DMqGq3iQQm3A=; b=SZcWth1HhHLZQUTlke232l75cp WLXRh7aVIHspWyu7iTZvau4k3qGrWNJYtqkXLgR13PLOhdjEtqclSK9epVKBlNIyNquOLpuisE6yQ dJ7k4BqT3Cu4nsPkopvhgDdbuBbtuBPvGPokC2jalnT8nkzHcJJ2KDt+4sQmt9LBtGAxdGdgTcz9r ceC3AlDU72o3JcXArUZPG6TKNw3lBpAOae5bNiUnwYSuZVLd2pnd1Yn6c4Lzks74042P/Z+xnY5Tn m1yRgJdlhN3dtlg94iG8j4x65a1KUoo0zwFtEtsKMf3qIbFplT1sYBRpxpLRbx2TdrFa/8nbw/Uka P8eTjafg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkl7F-0000000EQBS-3WnJ; Thu, 14 Mar 2024 13:27:25 +0000 Received: from mail-vi1eur04on20600.outbound.protection.outlook.com ([2a01:111:f403:2611::600] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkl7A-0000000EQ9h-2nss for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2024 13:27:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D/I18MYCOba+ITMNpKFXky5/qV1a/5cbB9O0Q1eJJhH2tXbJbFmaVu3/9XOCGjytr4v93cCfDFr9JLC8pFY+1DCnHSGpEFjDQIHyMUuuw9KrPgh0rigTB+jLfhvFf8gzGQBwmegHKIPnAyDsFZyZhfwKVUHiiW/705H+fvfQK0RWirsy0uMwPBy7cyY90pDRcEOE7apETlaiE+oLeLZUcvrB10jgF/MZwxCifZErxD8Nl+ycUX1cOm5GgnxF9CowpYXLcSAvMndRnbT7rkxhMYq3ePBL4f9DQNxfdOcY2+Jnr9QmisZ/MC2ithD+p8GkKnf+o42xaqJQw9S+zcISkw== 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=DkhFzy347CReKh8Y/3De5x5m9e7u839I/9k6SdaIf8U=; b=Wzi8I1PEgs6w++cy2ImwhcNzoOrUHl6fUrpaY4EVn1+hcZ0kK90EnxCrNBRPHcwsTmgN0IQXiMmkvLdfmMt8BKf0VYLewN9ndq5MO31skyxAlGZVSPld1t8dqbCgShMvuKU33BgJF17zc7L+jrQGaXoUzkG8l4TFoMCLcGPqNRAXYqZ7S9j9OPCJh/PE96/ydb2DT/pKSILwGPkOZHgJREEy84x3gNPy7VK41FCJQQjF9rlmEp4/uHcZNCzC0D+Hp2Evdvq+2bkq0oZaFEQ5QHTLvCU9fSy+gZshGFquJ0lIzBYAxE20FvsY0vSO41HR08FOLuwhDStIfJ2+TCChRw== 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=DkhFzy347CReKh8Y/3De5x5m9e7u839I/9k6SdaIf8U=; b=BPpRTPWPL293Tza8Ny6nUgjHlAD7lk4LyGTqYuRvHDQ555lng1PrSibREfpS+TLQQjgy+NIRSEmNlchrLXyjPI+0s+TNOm+3FA1LH1V04niQCZXqhdo94G26SFqyK6PR6UBuQrUnup0Iy352JKGc4I6+Zr0Ab/lriU1zLLQ3RWk= 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 PAWPR04MB9861.eurprd04.prod.outlook.com (2603:10a6:102:381::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Thu, 14 Mar 2024 13:27:14 +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.7386.017; Thu, 14 Mar 2024 13:27:14 +0000 From: "Peng Fan (OSS)" Date: Thu, 14 Mar 2024 21:35:18 +0800 Subject: [PATCH v5 1/4] firmware: arm_scmi: introduce helper get_max_msg_size Message-Id: <20240314-pinctrl-scmi-v5-1-b19576e557f2@nxp.com> References: <20240314-pinctrl-scmi-v5-0-b19576e557f2@nxp.com> In-Reply-To: <20240314-pinctrl-scmi-v5-0-b19576e557f2@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, AKASHI Takahiro , Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1710423327; l=2653; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=dKDsMHnM+cuvfvX6K6tAU3ADCasBJe+OHaz6qBQ1Tuc=; b=4xzM3YkXuTqYU0tEDo6x/HN4gsRKw3cpJZgM2pUwWmhzTcBuCmBTTPCH+IZBUrrpdGdNWuVQ8 6MyD12S/yYnCjWetyg8RKWlUcjin4Jf8siW5hQolqJ7mOHzFtszNtL0 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR06CA0188.apcprd06.prod.outlook.com (2603:1096:4:1::20) 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_|PAWPR04MB9861:EE_ X-MS-Office365-Filtering-Correlation-Id: 2640a9d6-c38f-404d-f731-08dc442a75fb 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: N5VTujBtBoO/i+cA10llx2BsBHIOkUQ/kQV2Ev0E/7x4JXhCSmSux6L+r1sdil4gduW6DPMgs812ypiNg+on03kzFubcJfOEq5cvUOJSaiR6psLiTLZeZeoXy8HW7cpwoj8hZVjXUtBECCw068mWu4t542197KD/yP5G9knFCkb0wmbLya44B3wY649nFvnqSi2sGsjQ+e044BV4yjKYmOXQ43weY6xdY3TSQ3j3sD/thbBvLrLN/GqgejwKpwYrLivn0m8IWXzCSiM3dl99bLrVIze1t0cXkMuRifWGmU2UlV93QetIJZ0IYNHsTnmUHXiTDrLCx8sigOLWor0lk+hCm+W4FGo5IoPb0CJmD6bqMou17cRbjEvhGDeCUfKBGLbHGZXn5aJ3UD/R7lT6Wvm4DWjW3a5j8qYxFLxmCgvFykpfUfrk0PpD91hfYXQn0diTddVew5vVGuu4J7yYLrqH/oz6Xp18k3JzwG8w+2MyiKgjIKo9m7vdy0Sd4g97+lgDvwF77oJ27T+kFji1yc67flBXf9mw1ZD2heJdK9MdFSJg8y6CUnFgsGhsHvo/rh/YRHttVJpyl/c4HeL0UXTGz11NoyzjMNB0Qf9Pf0RoYlFJYvDKpPDuxS8kYvmf6TTBkw59l5pOj34CFtMinLPRDWjSyuuIpVQnSjwKS5p6VHrSMUoOVGmsD7MUelvEFjYwDkFv1TyTlo8umn7JuRETT5gans/ENyBxeFcjjW0= 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)(376005)(52116005)(7416005)(1800799015)(38350700005)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?wF+0KEwoOvQxpdHb/ZxCiXWHhpVr?= =?utf-8?q?eOpnOB0kYrSWW5dcEI9offwcTHufWITLX+EaZVCDvP8jcpGCQmW4QpobQJ9s5umYY?= =?utf-8?q?r7sYS34epA8wtwUFi9DKxItGAf4Na0UBI5aAW3rbMaIW97KV7hv/Luxa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SPTiwb/Sw2nATC0RTz58xft+uQwYNvPD7J4hevHsYUvEgW9pTbrlS/DbSTop8Rdy?= =?utf-8?q?6CtRr5SJJ7/XZ0VNX39EfREUL3fdJczkmqQmTGd9bbRSyYnoRm0EHWy+uwnWS5wtj?= =?utf-8?q?FpChIM1bqE3Z8D4wXRK5GLk6jc5VdmOnABkiXMPLHpPm+G6GBuJBZVOWeXQatGCc2?= =?utf-8?q?ykfsWC5rRfHPAGnQTe4A1mRcmE5FRSULsyn/uV8Z+J7y8Hx40Qwd9dxStIaNhI/kQ?= =?utf-8?q?+VSE24k82+e8cJWYaymVCCfenICut9noeteHv8pZ8fE0MV4kX38f7SRP7PDTiOrIf?= =?utf-8?q?bfc5YsT6kf7pA01fXuJgd7/jEfC9OcVYu8pZ+WMkPCo/vgfkC7hdNCuTBjPTe2n+g?= =?utf-8?q?i7scBiz3Alf12YfxU9fWv73FidTVVikqPu2JG/8ODsu1JDz1/v9gHf2AKAlxxqQk1?= =?utf-8?q?wTTAmV757A10HIpTEYFBPQL+UjBiF+ap8zTO1whvyqTE+xc79oT6X822JF602bLCF?= =?utf-8?q?5vna69l4sLWb?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2640a9d6-c38f-404d-f731-08dc442a75fb X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2024 13:27:14.0136 (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: YWnfXaZZPbqlvaphSEnMaLnzFdlKpr4wJg30PWA4kiHrjt1WPCVIZNpC1WJddCu8kfJnaPqMkakWrb7e3lZucQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR04MB9861 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240314_062720_754381_9DC6620E X-CRM114-Status: GOOD ( 11.67 ) 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 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 2709598f3008..415e6f510057 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1488,6 +1488,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 @@ -1799,6 +1813,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); }; /**