From patchwork Fri Sep 16 10:35:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 606431 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 45140ECAAD8 for ; Fri, 16 Sep 2022 10:36:15 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 87565164D; Fri, 16 Sep 2022 12:35:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 87565164D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1663324573; bh=8e4teflWLD/CWIiwz6ZoiTHl/6OFrq0rkB+9h4MpxvQ=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=QBRWc4HLm+UaQIsoygGDrT6Urs2Uk0GFF6Mt8cGjuNWOt6ly+79rXnhs1N/h52/n5 tCF03tWzimiCTqzP4UGIlKc/Gl+2+DT9lmAPwpZodKquKXqaUsdN80zR39pdkTDzi5 UtUSFQu+uBCk3Xpc7xgHTFv0nqc0l7B1OWZyfsTk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 297D4F800E5; Fri, 16 Sep 2022 12:35:23 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 28F07F802BE; Fri, 16 Sep 2022 12:35:22 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 130AFF800E5 for ; Fri, 16 Sep 2022 12:35:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 130AFF800E5 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="QlEdKJm1" Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28G4mEDq002644; Fri, 16 Sep 2022 05:35:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=06y84B2zg0NNkNS46/H8foYFWp+a7npO/FgDpA0VjSI=; b=QlEdKJm1iEg7YrzEZfvOTR8YIEt7t9j/H9G1AGEHZg2TzLHknv9/WV9lawmTN22zkL+x 3q4+JTVixXuD3UYCJQ7jjKBVEPzPiGug/S53hN7Xu3YGpSHq78IH11uw/lYSCYUE9p/e V3Z1KgfWUnXjPdca2RzcP40Kdm3142fFxBRAER3G7yx+sG06pJDcEPhk585lc1No1rSL 2wpHGEdG4gOZkY0jn62JSS+qtTahcfM7t6E7dEzh4+uQpWrpXd1llPShgudtfGiISYy9 AroHzWHs9f/we6tYB0q6ciNeOUrHwz4I8VMY8/3SzNFmP/iAF3vdg/wPZrCd37NSpS1w NQ== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3jm92qgycb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Sep 2022 05:35:13 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.12; Fri, 16 Sep 2022 05:35:11 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.12 via Frontend Transport; Fri, 16 Sep 2022 05:35:11 -0500 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.95]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 03BF7468; Fri, 16 Sep 2022 10:35:05 +0000 (UTC) From: Richard Fitzgerald To: , , , Subject: [PATCH] soundwire: cadence: Don't overwrite msg->buf during write commands Date: Fri, 16 Sep 2022 11:35:05 +0100 Message-ID: <20220916103505.1562210-1-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Proofpoint-GUID: SSj2ik-bRFGeaMqKbQA7NedWI_lObQKm X-Proofpoint-ORIG-GUID: SSj2ik-bRFGeaMqKbQA7NedWI_lObQKm X-Proofpoint-Spam-Reason: safe Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, Richard Fitzgerald , linux-kernel@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The buf passed in struct sdw_msg must only be written for a READ, in that case the RDATA part of the response is the data value of the register. For a write command there is no RDATA, and buf should be assumed to be const and unmodifable. The original caller should not expect its data buffer to be corrupted by an sdw_nwrite(). Signed-off-by: Richard Fitzgerald Reviewed-by: Pierre-Louis Bossart --- drivers/soundwire/cadence_master.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c index be9cd47f31ec..3ef472049980 100644 --- a/drivers/soundwire/cadence_master.c +++ b/drivers/soundwire/cadence_master.c @@ -544,9 +544,12 @@ cdns_fill_msg_resp(struct sdw_cdns *cdns, return SDW_CMD_IGNORED; } - /* fill response */ - for (i = 0; i < count; i++) - msg->buf[i + offset] = FIELD_GET(CDNS_MCP_RESP_RDATA, cdns->response_buf[i]); + if (msg->flags == SDW_MSG_FLAG_READ) { + /* fill response */ + for (i = 0; i < count; i++) + msg->buf[i + offset] = FIELD_GET(CDNS_MCP_RESP_RDATA, + cdns->response_buf[i]); + } return SDW_CMD_OK; }