From patchwork Tue May 16 13:24:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Daniel Baluta (OSS)" X-Patchwork-Id: 13243171 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (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 EDF1EC77B7F for ; Tue, 16 May 2023 13:26:21 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 731411DF; Tue, 16 May 2023 15:25:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 731411DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684243579; bh=d1mmm0s70maG1iaKOxL+UKeJbxEJHZ24xNV8tsWHiMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=LzFd+2+RmJNckC9tX6pOt9X83ojzI8DJv3Rr+8ont+dMaTrwYf5p6NOzDzorbRBr5 IhrTJxHkLrLsCf7Km1mawTRqvoZtO40WwgzCsFaouK7S+ZPzFw3XqY6NeB/ndQ+wRb s/F2/7wQT9p3QBhD8fFciL9avB44veV1dOEKLDnk= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 572F6F80557; Tue, 16 May 2023 15:24:39 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 18073F80552; Tue, 16 May 2023 15:24:39 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4C696F802E8; Tue, 16 May 2023 15:24:36 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on20603.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1a::603]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 901EDF80272 for ; Tue, 16 May 2023 15:24:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 901EDF80272 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-NXP1-onmicrosoft-com header.b=N8N1gm5g ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xm2xsnmGflIrPzadm0HXrCB+IXwgEJGmW+GjCBji5BSALFtSGUWiahhRgvdYXY1jjSbavliPM6felBzC82pGnvu0+WpSD68LvWjJQOE95wLGrBL47VcWl91X78kZHozhp1pjwhHGGwxQ5E0ERSnFOgZXO7ow9enMHeCuyBjcn+bjjncCpC3rBxksNo9CHCA8lYBgH94wa9S/msfu2ZsD1bmCfHI1L7ftzypAcDb6mY5s6hW9McBwlKnnVI205QNeaeng5pEZYnggte5s/0UfLP1V6ZzLx0/i0f5gj03JzxerlBNzo0F9UkMxO6u/lhiBWjN5D97fgnOlJPnqMQRJLg== 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=VdJB7DfPMN5TpI2aSmxNRf/xXhSL2fePyA3eXXbmOcQ=; b=D0LFy19i15rJaRCW0qe1zEqfZr3UZ4ZvH7Anrls34byon3nMqlX1ebt3fNxviibw7oY1y06yMwMSu50geriYxa3YQsufmkYDaZdZFxe2T9GWxyBHS3a1+/XCk6Lqst+EgmbjHfaGOoORkBmwci+nwyIOTsUTSnbbbT6gZVR8cmElGvQA4dLj4fCu/+KwDA8YZpvtyT1cQKBaQyhG/j9xIzCckyU04OYEFE9CNV8Gico/L3hg7oxvHa6SQ5VNaU3yHqUiqed+XruSNRaWYFELLw6or8W2xWetxKHfaVkcsQuDNfizMSRLtK5OAMVWs+O7j1u/L8k/MpDi2h73goKeLA== 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=VdJB7DfPMN5TpI2aSmxNRf/xXhSL2fePyA3eXXbmOcQ=; b=N8N1gm5gbxIzAdUsxUWa7WWH4wxjPapxdKyDMC4vDG+NU4UntrWWBpoZpSl+Z4HJitnv+uWI6zbpZBCvLZk6yjfi2VlAfYdWp2JfkAT9wGyUe6aAOD8Iq5WLeQoYuz+4SlbBLxzxr/BsLiSOvi8G0pxgQB6k890MrJZbixQdjZ4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) by DU0PR04MB9635.eurprd04.prod.outlook.com (2603:10a6:10:31f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30; Tue, 16 May 2023 13:24:26 +0000 Received: from VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9]) by VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9%7]) with mapi id 15.20.6387.030; Tue, 16 May 2023 13:24:26 +0000 From: Daniel Baluta To: broonie@kernel.org, alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, peter.ujfalusi@linux.intel.com, yung-chuan.liao@linux.intel.com, ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com, daniel.baluta@gmail.com Subject: [RESEND PATCH 2/2] ASoC: sof: Improve sof_ipc4_bytes_ext_put function Date: Tue, 16 May 2023 16:24:01 +0300 Message-Id: <20230516132401.205563-3-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230516132401.205563-1-daniel.baluta@oss.nxp.com> References: <20230516132401.205563-1-daniel.baluta@oss.nxp.com> X-ClientProxiedBy: AS4P195CA0032.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:65a::6) To VI1PR04MB5151.eurprd04.prod.outlook.com (2603:10a6:803:61::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5151:EE_|DU0PR04MB9635:EE_ X-MS-Office365-Filtering-Correlation-Id: afd348d5-9271-4910-c6de-08db5610dedd 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: jD1xkEDqjQwT0NWJkmIZsAiDlmwutNxa8a9y6AoHj8VGjN6BealkcjLN4hYQFOoR+sDmbG9RjLpFZzDe5nXx7SIEE9mI1Wrrc69WGws2Is4mNN20sPz5BHafR3B8ZRMBztnOCL6jfD2cBoMBKRL/604JEr7Z6361FrXVZ53xvFJQX4bWiO3sLDc7TkI3wJJP8aY9o9iuh1lbtDwaZlfYEi8NAfcU09EyKf85j5gWeEAdJVwwcAqKYa/VdvoNSgO47AxeB7MrN3zt+7tpm8L70Ua+6kkm841gRSLX/8E6xxMwXA52341lTB27GKaqCC3OgSzQys6YKpQkwbUi38O2xyypUClKwPhRMTWJWVoPhec1iaXvmEVwGFuq/eu4duRw9b9wPMzuVBjcv3mUdzRQVq1QZIDwk9ExO8M9veAc9Zv/NGKP0vmhFCRCKbvBGAV1hgLJEKA1e4geBX3bqGaPldiI77+DYOqN0QRSa2DbPt8UdmLVlrWxLcR7P+ZwLzL6fdXOFMY6IJF0dPaRQucY2iCPVjRN7iom14OKlWS46FHH2KAolrHwipKZo/iQNqLo X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5151.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(396003)(136003)(376002)(366004)(39860400002)(451199021)(83380400001)(66574015)(66476007)(66946007)(2616005)(52116002)(1076003)(6486002)(478600001)(8936002)(66556008)(44832011)(7416002)(6666004)(186003)(5660300002)(86362001)(2906002)(8676002)(6512007)(4326008)(316002)(6506007)(38100700002)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Ptk4myN8BxPlIl05oIDk3vwMozgo?= =?utf-8?q?zw1mnOLAmhzJmDIMaZP+0SB1t2Kz7mjW/INEcmCFQR+BTY+TK/aPq1gpWKxNFuvfy?= =?utf-8?q?qLdnzTHAsQ1re7w2Od4zp9i3kfZiLG7IfC8otpoUMn7dNSynz6OaT6X9I6K4zMb0L?= =?utf-8?q?D2ESXp4xDJjiis/6bEgX84AmIVcX7cGn7BfMp0eWHtPLMCmLEyNp+K5Xk6PzdATA2?= =?utf-8?q?kTLRqeVlYs52l9DuaWgT4DihHBeLIH+74dpZ1Jpi1ka/q6t5eFdMvIBzEKHaT16K/?= =?utf-8?q?obv+sDQ0j0KXtbr+L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dOl2xdbGbHnonqmwUIFoJiY3nEMoxyO2pxC+raWp79EFqbl47gUdAD?= =?utf-8?q?E6TC1fXGH7w0+1axjRmSCF7nuAxBb3xcMc/MGx0Iz1JylSZIETtGe5QQVQlFjW5kI?= =?utf-8?q?IaTUqMMLJ4tw+ZHQywIF7H1Jgxx1HUPR6xLk9bLgyyXUWk+VkE0p5yhK8pAK8kPAP?= =?utf-8?q?O8B3zdIuQDyNL5N+rdiE27INL2WKIfu+iewU22TVc0+Dhu+fwDjPczlhwZAddbSL5?= =?utf-8?q?A0a0jse5U8zyNhL14bSGXA+zeiHlEqkvQllii0WLzU0HMKuMXQrjBATxv6XM7vjyM?= =?utf-8?q?oSImx6HOMEWC/6ImB7aBq6+Qu2HUvorXSGVOjojsp7/JEZCK5f+EEEasvbgbYiih4?= =?utf-8?q?UhH0jW+lnW2sugImNPVTTz0Y7tlakR7oHeNKoCp4wGsUEO94l7mzE5H/+g9M+Gx1B?= =?utf-8?q?Z67iZ8fPbXH4T1bp2yS1JgVa4P2Acs9AQ=3D=3D?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: afd348d5-9271-4910-c6de-08db5610dedd X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5151.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 13:24:26.3507 (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: o5OzjfRBfuKrjGLXjmc9quigUKWWDSN0EcRQBJ3xoPgn2CouDtdtzaSClZV3lCZ/cLbowjjieHZOUggoe1W40A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9635 Message-ID-Hash: XSF4FG5KIGX2FAJUYCPPATMYK4UU32XX X-Message-ID-Hash: XSF4FG5KIGX2FAJUYCPPATMYK4UU32XX X-MailFrom: daniel.baluta@oss.nxp.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Paul Olaru The function is improved in the way that if the firmware returns a validation error on the newly sent bytes, then the kernel will automatically restore to the old bytes value for a given kcontrol. This way, if the firmware rejects a data blob then the kernel will also reject it, instead of saving it for the next suspend/resume cycle. The old behaviour is that the kernel would save it anyway and on next firmware boot it would apply the previously-rejected configuration, leading to errors during playback. Additionally, the function also saves previously validated configurations, so that if the firmware does end up rejecting a new bytes value the kernel can send an old, previously-valid configuration. Reviewed-by: Daniel Baluta Reviewed-by: Péter Ujfalusi Signed-off-by: Paul Olaru Signed-off-by: Daniel Baluta --- sound/soc/sof/ipc4-control.c | 39 ++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/sound/soc/sof/ipc4-control.c b/sound/soc/sof/ipc4-control.c index 6f0698be9451..c6d404d44097 100644 --- a/sound/soc/sof/ipc4-control.c +++ b/sound/soc/sof/ipc4-control.c @@ -54,6 +54,26 @@ static int sof_ipc4_set_get_kcontrol_data(struct snd_sof_control *scontrol, msg->primary |= SOF_IPC4_MOD_INSTANCE(swidget->instance_id); ret = iops->set_get_data(sdev, msg, msg->data_size, set); + if (!set) + goto unlock; + + /* It is a set-data operation, and we have a valid backup that we can restore */ + if (ret < 0) { + if (!scontrol->old_ipc_control_data) + goto unlock; + /* + * Current ipc_control_data is not valid, we use the last known good + * configuration + */ + memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data, + scontrol->max_size); + kfree(scontrol->old_ipc_control_data); + scontrol->old_ipc_control_data = NULL; + /* Send the last known good configuration to firmware */ + ret = iops->set_get_data(sdev, msg, msg->data_size, set); + if (ret < 0) + goto unlock; + } unlock: if (lock) @@ -327,13 +347,24 @@ static int sof_ipc4_bytes_ext_put(struct snd_sof_control *scontrol, return -EINVAL; } + if (!scontrol->old_ipc_control_data) { + /* Create a backup of the current, valid bytes control */ + scontrol->old_ipc_control_data = kmemdup(scontrol->ipc_control_data, + scontrol->max_size, GFP_KERNEL); + if (!scontrol->old_ipc_control_data) + return -ENOMEM; + } + /* Copy the whole binary data which includes the ABI header and the payload */ - if (copy_from_user(data, tlvd->tlv, header.length)) + if (copy_from_user(data, tlvd->tlv, header.length)) { + memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data, + scontrol->max_size); + kfree(scontrol->old_ipc_control_data); + scontrol->old_ipc_control_data = NULL; return -EFAULT; + } - sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true); - - return 0; + return sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true); } static int _sof_ipc4_bytes_ext_get(struct snd_sof_control *scontrol,