From patchwork Wed May 3 08:10:49 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: 13229802 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 D1838C77B78 for ; Wed, 3 May 2023 08:13:01 +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 3B8DF1364; Wed, 3 May 2023 10:12:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3B8DF1364 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1683101579; bh=d1mmm0s70maG1iaKOxL+UKeJbxEJHZ24xNV8tsWHiMo=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=b2sL2dq6OZe83LwsrgIIfA8OcH4aDItolAb/9RBC3MOF9yKjWfF7nHfJ8VEg96wtF MaWgGt0YqL+PIMs/2UPAlbRjAasOMxf2eG6uHHCZCnYz2Dc5dmxQM5UBj+uqd31xco R58gr1oShkWqcHz8WtJYl/jUfBBvQ2PqRqoUoxMQ= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id BF77CF8052D; Wed, 3 May 2023 10:11:21 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1BD0FF8032B; Wed, 3 May 2023 10:11:16 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20600.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::600]) (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 37D29F8032B for ; Wed, 3 May 2023 10:11:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 37D29F8032B 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=Lp0EW/wE ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QTqTlgYLnEMhsfYQROcOmprRN8oEy1wsfL66dIAnSiMgKXpZic+RKM3/DEub9xWO+dJDInbi2Oj64peQkWd71RX2+nFHXP15eIykKVTfUKPfdWq+/M7xSAUsnKLI7dWi/qNwFxsKJugncFQ+Ab5sphqPkU1DCnETNZQSym+sDScPK20VlF5jGQmr88wzBWD1y1LEb85rRzzYWaHL2wzdh0LgX01JEO8pgZRjgNPS7p+PNLk5i0dzDLhejBecx/dxbAUaogm/cisTyK4LjbXhjxL9u46RBAuSCKJueqWzEUUOSqg2UAMnH4egAa27jtbYpQF2uSHylfRuxCc8CkUwGA== 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=D9u3pVrV01X8R/oQ4CR59qGi9EGEww6IqRc31yoG6D6nKgaQT5M9vp2CLvY6eomBLSmKNR54EDBKLP8mJyERKvJJDWB/M7GrMDgfZ4iuXKzharZFWowopbzcPUqFmwi5NgeHVfV4QzsyZJ+lbJv9j11HjW5gVPOFh4sDXCVTZQHR2HZ5F1LWDEfLPM2OC/vIZ7Yn9S7jMXW3nMChmcOqKFogE3rTK5CyNw1oX4WPLKJRMTHxeqX/iJqvAcin5Nww85m6eQG9sSdavs89cPJNpfnjG70nP6S5XJL8IveLygT/AdLL13BF4CBK08K5RMrPOuqofJEfN/tkiiQMNcU6rQ== 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=Lp0EW/wEoyHgm7h4Ew5qRJcEO0iQjg9MhPo1o/hrqEXkjOnAxeZlAlh/hHfwdHrBv6MwQyQo68GYfI8PvnT1JyN3bkw9sT6dUMehtOexvUpM4FUtfFQIKkuia2DyP667XnSbva8npa802Mc1h5vQjE121dOZfesA1iRp1CtjCUM= 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 DB9PR04MB9865.eurprd04.prod.outlook.com (2603:10a6:10:4f0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Wed, 3 May 2023 08:11:08 +0000 Received: from VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9]) by VI1PR04MB5151.eurprd04.prod.outlook.com ([fe80::42e1:4216:edc6:52a9%5]) with mapi id 15.20.6363.021; Wed, 3 May 2023 08:11:08 +0000 From: Daniel Baluta To: broonie@kernel.org, alsa-devel@alsa-project.org Subject: [PATCH 2/2] ASoC: sof: Improve sof_ipc4_bytes_ext_put function Date: Wed, 3 May 2023 11:10:49 +0300 Message-Id: <20230503081049.73847-3-daniel.baluta@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230503081049.73847-1-daniel.baluta@oss.nxp.com> References: <20230503081049.73847-1-daniel.baluta@oss.nxp.com> X-ClientProxiedBy: AM8P190CA0030.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:219::35) 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_|DB9PR04MB9865:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b490060-08b1-434a-ceb2-08db4badf30e 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: gKoiAFxfHhWB5Gy3NX0lff7IHkHv5gHc56JewxRByijYaBWHdYQjjhxv/FJGEEHY3DdwEXYIWpafuyb9BAr5opRhHimVeuRTbiD6LKemscH8SuvA4rTKOHcxn37Jq9gTVm457Y4hZWs2xy+Mk1LrOnqHH8DY/fhaEMKtJs2bXrayLR1iRbxBBguDnoWu+rG2FIJMlDWD9bgNIFOI+8gwXFA+2uu/9EgUexJc3AvOVbH8bNOQLVR+ExCFDEsiEqjLwFhyTGKRb9z8R9Ec5V5dO7lyEvKP3Jz9KUr/Ic123P3j2A8eZqmPpFiF1BCi3ucRnvD8w+maCY3e7e/VdAdCFPsn+N4lZVP7/RosRT8GszdaF6OHt5nj8HCOomP8tE7Gm09Z2YZ72nlSFPLqppBY1LTXpoMpebbSWfPlMdlu3b4ze4Mlh3D41/3YOSBwI9FJB7oKkX1ZVvSp3wTbnNQJfwgStSCO0aGAngoXxyFoNyZe8ppSngHcY4KYhCTaoa7lca/uvEi7l5DMovKV8dlc9OGw3hIkje6a1HVPgYAEVNFn88FPbdYs0Riu1jNVVuEu+Y+rjFnYONKRWMqcXFO+VPKnpWCIWWbPL89GmPOwZEJp6zbLlwyN0ESgx+Nw7VQW 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)(366004)(39860400002)(396003)(136003)(376002)(451199021)(2616005)(83380400001)(478600001)(186003)(4326008)(66556008)(66476007)(66946007)(26005)(6486002)(52116002)(66574015)(6666004)(6512007)(6506007)(1076003)(44832011)(316002)(8676002)(8936002)(7416002)(5660300002)(41300700001)(2906002)(38100700002)(38350700002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?lX62Wea9LJqBNduakuh8fbWCu/dE?= =?utf-8?q?HwzpjT3LKUmpHQexOBM3afVJNceZhj+e0AYVFgiwUb/5J2R4PyMLlwa0Gq/wpgWAI?= =?utf-8?q?DAoBVWxq0nWtLF76LbYjzXzFqo0mGLjklIrsOpMj4qzZEBOGrzSAtlWzCGLB71dfe?= =?utf-8?q?0ljCuy57aKmD1Hj0ngPKvikf3T8IXV2zComorANPWOS6VK7aZ+RLRG6HKTqNNlflJ?= =?utf-8?q?OEBdYMHPDwZ8sHxtHDQUXAv+elW68O0ZQoU0ayNpy11dZCE+ppZtuK2R3xJPJeR9V?= =?utf-8?q?zPwjyUfMXZj0DsvFWmVv/lS/TUFCw8Ebs1dl/WZKbW+iljUvPWjrbdLMFukXj0gZ3?= =?utf-8?q?GjHqvKs2yAVqu/NprWfqFOJiR6ckHCAcrSj4YoGSQyNzj7K3EsHBANS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+3AXkfHPY6t9wUqIxOq60?= =?utf-8?q?bTv07k3mrNQxBlDbs0dvzk9iOUkEHSGv9qI5N2L7WYEHQr3/8oqo7rBEUK89xBFUt?= =?utf-8?q?YBPTkWcYMcAcm+g52c0JLQlxY/b++4WzWucTiNFwAgtDB+PEV4mzpvLeNNKWeTjv2?= =?utf-8?q?fqIdwVPH/9lSCIRKcAZqeo1x/tQ8uRkfiat3csG+bNStfPaLdjEoJdFINZycqaRtE?= =?utf-8?q?r5hrijSgS2TliXTZK+xpMNpU5AA0PtbpOK7YCDxM+ORN/2KhTkoOpsv+XMOZsxz+O?= =?utf-8?q?oDJRuWODLI7c?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b490060-08b1-434a-ceb2-08db4badf30e X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5151.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 08:11:08.4182 (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: Kpfy4lJV8SZ7TSiSS8U9gvcq2I5U0qGjLzo73+lwHn09r4jLPB5SmMBixFRnz/j5VTWXXHDCaNOr6BDLBJdqzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9865 Message-ID-Hash: LDRPLZDFD7AZ7Q7PR6ZDVB3O55L7FS7R X-Message-ID-Hash: LDRPLZDFD7AZ7Q7PR6ZDVB3O55L7FS7R 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 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 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,