Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp717099rwd; Tue, 16 May 2023 07:00:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gwEZzbwG3Y5wcxXSNRUNDEkwf2JhhNLCNB+C01LZ7VWxefmAucUqVDoxmi6dobgYueflR X-Received: by 2002:a05:6a20:1614:b0:103:d7da:bfc5 with SMTP id l20-20020a056a20161400b00103d7dabfc5mr24355827pzj.8.1684245646055; Tue, 16 May 2023 07:00:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684245646; cv=pass; d=google.com; s=arc-20160816; b=ik/ILACI6iBfFnvRMO2FOcxQd5WGMz1rfUpqmlu73om2S61r/zv74Wc7gCYpb2Ro27 9d4Fze97enHbywifPffeJ9BzKGAuuqOkE0gmV0DGjjzWIYEaUbc8XSQa1zkt043iOg/+ Red7z8MDM7nwIXyjEbXiJfGtgmyxsI3L05WhEPLnLT3j1MlDZFGjfTQ7heI6htiaedLb JgJkmTn2kAc1ocSw2JZtKGF5Ztb9PGsCyDz/gm9W2LZ5X/9zz+5joeNfoqePAyS5CfZt sxNQwsTEHBMdJFuEQCioBUIgKaYnq4kVyv3mBpRKlAmoq/o6JX/fKlxtl1NIQbwHTnF4 8ssQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VdJB7DfPMN5TpI2aSmxNRf/xXhSL2fePyA3eXXbmOcQ=; b=LZGyEQvdsCc8Gu+YMLjoNvhu5g6j2EzhcnJ48X9vqnFVe+/sq2nmx8MnZ/vaCPbI6u 1qMA6B6RjfSTpEauArtH6w1Lwr7yJnMsT//5UASQlXR+X6zc80BexXw9NEHgeyetfC+H 2Wu9foGR2ewqrZVx+XV2N40BTAtDoRIxE2UEly/JPwIjQLvuq/xOwBF06AeWqH4B/tTC a77uiQDS2OFaN4tc6Jy+xCuiEBYN8mdoqne/nunE03yjGbXAF2xTDcMVtQNMg1u3DRGX fuB26IgzrpA3rW61guOn6Dpk55tjwfrj0Nqw//Qa2H5uFLVu1XYTR8/akPPmn0MGkOAq xYrA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=N8N1gm5g; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p20-20020a639514000000b00502e7406695si17333076pgd.316.2023.05.16.07.00.27; Tue, 16 May 2023 07:00:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=N8N1gm5g; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233678AbjEPNY7 (ORCPT + 99 others); Tue, 16 May 2023 09:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233683AbjEPNYx (ORCPT ); Tue, 16 May 2023 09:24:53 -0400 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2061.outbound.protection.outlook.com [40.107.104.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EB6B3AB3 for ; Tue, 16 May 2023 06:24:42 -0700 (PDT) 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> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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?B?UHRrNG15TjhCeFBsSWwwNW9JRGszdndNb3pnb3p3MW1uT0xBbWh6Sm1ESU1h?= =?utf-8?B?WlArMFNCMXQyS3o3bWpXL0lORWNtQ0ZRUitCVFkrVEsvYVBxMWdwV0t4TkZ1?= =?utf-8?B?dmZ5cUxkbnpUSEFzUTFyZTd3Mk9kNHpwOWkza2ZaaUxHN0lmQzhvdHBvVU1u?= =?utf-8?B?N2ROU3luejZPYVQ2WDlJNks0ek1iMExEMkVTWHA0eERKamlpcy82YkVnWDg0?= =?utf-8?B?QW1JVmNYN2NHbjdCZk1wMGVXSHRQTE1DbUxFeU5wK0s1WGs2UHpkQVRBMmtU?= =?utf-8?B?TFJxZVZsWXM1Mmw5RHVhV2dUNERpaEhCZUxJSCs3NGRwWjFKcGkxa2EvcTZ0?= =?utf-8?B?NWVGZE12SUJ6RUtIYVQxNksvb2J2K3NEUTBqMEtYdGJyK0xPNnZ3cmFhcjBB?= =?utf-8?B?MUU4ZDZ5VlVRWDIzRFQzTkI2V1ExamRZSHh3elJRcDBLOXBzdVdaUE1JUStH?= =?utf-8?B?d1M4RldLdEdZUm45dkp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-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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.25.1