From patchwork Fri Apr 16 14:20:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quanyang Wang X-Patchwork-Id: 12207819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76A76C43460 for ; Fri, 16 Apr 2021 14:22:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4085F610FC for ; Fri, 16 Apr 2021 14:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242273AbhDPOWq (ORCPT ); Fri, 16 Apr 2021 10:22:46 -0400 Received: from mail-mw2nam12on2089.outbound.protection.outlook.com ([40.107.244.89]:56161 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235300AbhDPOWp (ORCPT ); Fri, 16 Apr 2021 10:22:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A0VDfuBk9ij7v4Sx3k6GqhXc8MwlzNzGRcB/xbVq7fkUmgGB8psiVDwlOp9p2BkythrY7x6Q6oPPLvzYOv8Caaa10nn6MtoL4bEeSjmLG6z8d8MpUGJg9fqHFY6KJDptPw2qjVkF4PJWdlL/Ljfe/GlXMivE/ANvQ1ZIOI/XMD8/Zrc7Q5WXoU+1m6R/veA0h9kxY5Osegcg40XD28F7EcV+XNeEQ4SZegWi0A5fOj4NPc7C9ewal/kN2eq0F+SWBOBcIbSRSflhMk3s/h5CVi+lm2MS+9DZYA+Y0oIbamddl7SneB1klEanMgQqLSUyPELSDx2OpEMDy4ihdd3OuQ== 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-SenderADCheck; bh=M/VHzESPyjV8fkVOcutFrKHaOw4oAKVGuUsCnUXpXpE=; b=ZwsGmtiBrm3ssBlu+IvsfdwN/KfsWh8s2xMNMm8IoG3Jz/z/ygSaC5DsMXdYAVMMPIUyIu3If9uHYQQ9BVrP4eK1cqQMfzLf5FgMUIJ/PlgcmRn+5T5VzPX2HNQa2y8Iol0lG3yFAUok50JY6gzXWfnQSBk8igXf544EALKeR7rGb9sjRn/N9E1Ngeh/TJPk9Aafme0Fz9HMfsM9SqTpQ4uZFYYraC4Gnve0EAGGtjiyxnbCrDtLUlOFNvK/lHLLD7L5+eU9nt5ueCI81Lj5rScQ/C75Q2OQUZ39CCda07u1Msvj6QE1Vb25hYVucAdOSWe427tnvYFIm2oKzBJd0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M/VHzESPyjV8fkVOcutFrKHaOw4oAKVGuUsCnUXpXpE=; b=dcGJthAb6n4Rf2SlZY9nIrw9Sa1ULkGVnR/KI016HbRmNqe3BpjutcXvWYVR7KnnJLnA3zSMNsOipnWAA1t9op3N5s5u8t82hBNMRRmRTY/D8dGgDtbPEInHYRxwb9/gY1h8/NDIu9tGOthEKD0+o71thpo/v9zrrisM/A4VdEk= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) by CY4PR1101MB2264.namprd11.prod.outlook.com (2603:10b6:910:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 16 Apr 2021 14:22:15 +0000 Received: from CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725]) by CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725%6]) with mapi id 15.20.3999.037; Fri, 16 Apr 2021 14:22:15 +0000 From: quanyang.wang@windriver.com To: Mark Brown , Michal Simek , Amit Kumar Mahapatra Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Quanyang Wang Subject: [V2][PATCH 1/5] spi: spi-zynqmp-gqspi: fix clk_enable/disable imbalance issue Date: Fri, 16 Apr 2021 22:20:43 +0800 Message-Id: <20210416142047.6349-2-quanyang.wang@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210416142047.6349-1-quanyang.wang@windriver.com> References: <20210416142047.6349-1-quanyang.wang@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) To CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-qwang2-d1.wrs.com (60.247.85.82) by HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Fri, 16 Apr 2021 14:22:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d17bedf-974b-40ed-c739-08d900e30894 X-MS-TrafficTypeDiagnostic: CY4PR1101MB2264: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Otln4KfR/aNvWIEsCTU9hfAd2M45mzPiie2tfmAUZI2YGu8u4z8uchLlgxTFDUfl9S8a1zBDj6EbbzlOfrcxsjEFITQlNmLnh0gJ8wtB3LiCdKMtGNX7RelP3fj7ZhIcTRtGEkNHr0FqvKmdI4wvbEs6S69NJH8wc8CSjO3dOacTcI6C94TcrC3ahUp62fXco6j++43c4RCKWH8f72YyRAusdnnSfmiTfsboadH2zRD1z+ZBe6m2u4yAExBgpsVjG62wfqtF4GLyrbg2O0i1pGT8S4UBBwCVG/boke+O2id3sx2BMdpP/8zri7SiOoEm3p+KcEXeY8QpfKl/MAe6FkC9dYt/ZuOmXmnVU+KYxq7i1K8xVSmm77VJ9VccKvpRONjTqFyHnjpyv/pQhz4lbDbBkTezeCNn9oD5JAtrIJMUF3F4K80F8Z99RUuaWBJ0i++iZ5hZjUE4T2vK+OhkPR9Rz5uw5X8GV/3TGWgpSraP7XwSYiTu0s2NqEv7hIXkBAqk6SGlEE5bCh6u80iRRLLkHd/oexWHKciomyao1M12YBeT2AUbvVlR2Ee6jcyOTCs+M2RUaIndF9y6GLhy9V+OUOaiQAb7715DdrKMyqYLiYFkNXbMMqsc152UQGBdeOKgJSHtlCEYzXnbX2Uwy6fhDUjCvl7DJn2qEr0X4NI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB0071.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(366004)(396003)(39850400004)(346002)(86362001)(186003)(2906002)(38350700002)(38100700002)(316002)(6506007)(9686003)(6486002)(83380400001)(66946007)(8676002)(66556008)(66476007)(478600001)(16526019)(5660300002)(4326008)(26005)(6512007)(1076003)(52116002)(110136005)(956004)(6666004)(8936002)(107886003)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 9JbiplKsAlJ3FDtIyTbAudCFLGIvTAgyAr4+O4E5XuL2ShKSuA7g9n3ry3wg3fJYQdNTmmjTh3mMjqJCSNCahjcZP101Ty98kn7BPjCAb5+9SUoFaGej36yUkVYfxCMtXUKJKzuTKex/kLfs5TAU8eH+JQehGzrRiwhckAWOa419Fdnn+mmQXRtrcMNrSRgPvF1UYqY5iHgToxN9QhQjNnlS6LFJeXUoX0ensatYZt1uBRtIjBtZzaEoAICiQC1ToFjd2WZzlW14hQYNbg9x5sgkPR2P5DP+zV/TH+ofmpFzm/Tw6zAh0CraKL8Z9pwHzO23igmbmli5PwGTPDxkinQAPhHrfBcm66f+9Z5Y2EZuOnA3vO4HMZlxdTTcQ0gG2Khb2SUtrKCJoOq/6Zgi089ALEXhB65R42voaYtG+m5z9+q4iGeRH/kzTPV9nfVpGpUAG2qixw+xLkgbHeI8MMsgf86X+Fr6okmCbEbyUEdmQcHzJNUFaK7Aj6OnMH3f1LWRN6IBymldHvHdIib/gUerGp4olchQK5EDkXpuEOdm9gGYWS8HOJhJaEhu2Fzf9P/J+hfoWLWjjR1IIjyUKAeXQmRJaPrLBo31YmqKdGR0O5tGPkKCv3LXEB68wfMOhJTER5b675afBie8eHiYmk4/NGDP4m/hLnosR2fIUEdjLhuKDXhDM6hVfvjBZFiva3gw5vbD40Y3adFXXQ27Lg/iKG9Bphw1RQVbNL9TAVYJAAK4tQswHyTqGsrYL9QDnXYKBjidga2IJudUwLS3fjx6OOqyoy3ZfnCFRpb0wpjvN1ysPvZgAJp2H9u+5M5V+siuoVTaFiIc/2K/21hEglE2QdEZ0+EBwn4aEgoDwYk0IXFqDlCqzb88lAFrvJttNGAuQaB9YMG1dQ6oUqjajA7sVxv0sIimENe+ApBJWT5uN/MQlCUOLbFGQQuws8OOG69J2TB8tZZwck1/30lKcHANMIL5nEaZWDbf3KNPRIVb1wK0/pK0XpXZ7OOKLUuQ5vdLR08qBVFHQ3ODfgiQ464OoAClApisz+e36e3O2qLGmB0OuLLUjE+EC6Rh3CWAxmWDMnpAdEmn5jZynQHjFZtOFBMB970P9AA/1L4VVw+rkNIZPBkMIzTgZzsyenuvJ1Sk2/glsXn79Ckbui4E77hPDdiFhVaxbHQKoGp1WZBbxN9Izs1cNunZa3oSf5kZMaKGko6XtCYHkH0crTVai+0mH71/LwteEjRFpk25DReMulJxJKhH7QftxD+XB4yJWHZMxblGA/KBZYU60Pt+gKZeRODRDSqvTg7/PQa+VRWb8mEcpHQfIeujzwcO96GL X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d17bedf-974b-40ed-c739-08d900e30894 X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB0071.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2021 14:22:15.3079 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NDg+vQdM5JhzM6cuUV5PdfjC0b5yUUdm3U/CgiSDIFq7nwrnmCmS8Gxqak7v/sHKOFwAjMqsZ2k0F1dExVWPaAK9S8oI2gnwtICsMR0D33M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2264 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Quanyang Wang The clks "pclk" and "ref_clk" are enabled twice during the probe. The first time is in the function zynqmp_qspi_probe and the second time is in zynqmp_qspi_setup_op which is called by devm_spi_register_controller. Then calling zynqmp_qspi_remove (rmmod this module) to disable these clks will trigger a warning as below: [ 309.124604] Unpreparing enabled qspi_ref [ 309.128641] WARNING: CPU: 1 PID: 537 at drivers/clk/clk.c:824 clk_core_unprepare+0x108/0x110 Since pm_runtime works now, clks can be enabled/disabled by calling zynqmp_runtime_suspend/resume. So we don't need to enable these clks explicitly in zynqmp_qspi_setup_op. Remove them to fix this issue. And remove clk enabling/disabling in zynqmp_qspi_resume because there is no spi transfer operation so enabling ref_clk is redundant meanwhile pclk is not disabled for it is shared with other peripherals. Furthermore replace clk_enable/disable with clk_prepare_enable and clk_disable_unprepare in runtime_suspend/resume functions. Signed-off-by: Quanyang Wang --- drivers/spi/spi-zynqmp-gqspi.c | 47 ++++++---------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 32e53f379e9b..f9056f0a480c 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -487,24 +487,10 @@ static int zynqmp_qspi_setup_op(struct spi_device *qspi) { struct spi_controller *ctlr = qspi->master; struct zynqmp_qspi *xqspi = spi_controller_get_devdata(ctlr); - struct device *dev = &ctlr->dev; - int ret; if (ctlr->busy) return -EBUSY; - ret = clk_enable(xqspi->refclk); - if (ret) { - dev_err(dev, "Cannot enable device clock.\n"); - return ret; - } - - ret = clk_enable(xqspi->pclk); - if (ret) { - dev_err(dev, "Cannot enable APB clock.\n"); - clk_disable(xqspi->refclk); - return ret; - } zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK); return 0; @@ -863,26 +849,9 @@ static int __maybe_unused zynqmp_qspi_suspend(struct device *dev) static int __maybe_unused zynqmp_qspi_resume(struct device *dev) { struct spi_controller *ctlr = dev_get_drvdata(dev); - struct zynqmp_qspi *xqspi = spi_controller_get_devdata(ctlr); - int ret = 0; - - ret = clk_enable(xqspi->pclk); - if (ret) { - dev_err(dev, "Cannot enable APB clock.\n"); - return ret; - } - - ret = clk_enable(xqspi->refclk); - if (ret) { - dev_err(dev, "Cannot enable device clock.\n"); - clk_disable(xqspi->pclk); - return ret; - } spi_controller_resume(ctlr); - clk_disable(xqspi->refclk); - clk_disable(xqspi->pclk); return 0; } @@ -898,8 +867,8 @@ static int __maybe_unused zynqmp_runtime_suspend(struct device *dev) { struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); - clk_disable(xqspi->refclk); - clk_disable(xqspi->pclk); + clk_disable_unprepare(xqspi->refclk); + clk_disable_unprepare(xqspi->pclk); return 0; } @@ -917,16 +886,16 @@ static int __maybe_unused zynqmp_runtime_resume(struct device *dev) struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); int ret; - ret = clk_enable(xqspi->pclk); + ret = clk_prepare_enable(xqspi->pclk); if (ret) { dev_err(dev, "Cannot enable APB clock.\n"); return ret; } - ret = clk_enable(xqspi->refclk); + ret = clk_prepare_enable(xqspi->refclk); if (ret) { dev_err(dev, "Cannot enable device clock.\n"); - clk_disable(xqspi->pclk); + clk_disable_unprepare(xqspi->pclk); return ret; } @@ -1136,13 +1105,11 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) goto remove_master; } - init_completion(&xqspi->data_completion); - xqspi->refclk = devm_clk_get(&pdev->dev, "ref_clk"); if (IS_ERR(xqspi->refclk)) { dev_err(dev, "ref_clk clock not found.\n"); ret = PTR_ERR(xqspi->refclk); - goto clk_dis_pclk; + goto remove_master; } ret = clk_prepare_enable(xqspi->pclk); @@ -1157,6 +1124,8 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) goto clk_dis_pclk; } + init_completion(&xqspi->data_completion); + mutex_init(&xqspi->op_lock); pm_runtime_use_autosuspend(&pdev->dev); From patchwork Fri Apr 16 14:20:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quanyang Wang X-Patchwork-Id: 12207823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6983CC433ED for ; Fri, 16 Apr 2021 14:22:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4711F610CD for ; Fri, 16 Apr 2021 14:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244179AbhDPOWr (ORCPT ); Fri, 16 Apr 2021 10:22:47 -0400 Received: from mail-mw2nam12on2089.outbound.protection.outlook.com ([40.107.244.89]:56161 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241677AbhDPOWq (ORCPT ); Fri, 16 Apr 2021 10:22:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=al4Kp7w/6wPLdmsX2wZWoQ1DR3wC/Bfodpeiw0UtWezNqpYYFQnwTRnmcsHmWNByb57Mhl0J9i7cED3xATwgDAjEFh1jg4WKbPNxI2tuHK37LNA3irMLtbJAkMZa9588h2PP8ld50fVux3LfZVXd94A34uJXhpOag4OmD0SqYxaCcuQpusHXyOe0mS6V7oCJZYAFLTKQRp5+p+er1eUHhnrMkGjBrt1CilSsSbLHPqWuxyYxWGe3F2eI+wgl78lDmvEsRxJGxRQfqirb/J52cttX27KtTQQtoYbGRIZSmBP0Lp8UNa+vddKv3wDTbxFWxvkbbwtznF6CZ1TPIfx7+g== 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-SenderADCheck; bh=4I7CUAfjMk3+NxBTFO1XpfCTeNf9E04NBBFxWYxq4ps=; b=kvRtOET2RYwXSNSnSlBA6OF+yO8ryd2r6xN6tnnCqMXFBuVh3PQYN6kRUbuRedCkOCd1WKNIoufKCvDOz59ll443TX2xyPwo3NJaDmEyj6AQ82jixONMl8GrPz0ns1k+hQYgK/WDkfvn1pgRPOeHQ+9kydWqCbM4DUlQO2zBk3tIxOtPYqgHaO8yJdJLFV1zGHBz519UkYK25vcPabsU3utR6yWpgpj5CEsQhUmRHx+Y+EZNP72Qy6Wewayq+e11OzBg73xvPMDiPzmU/ZuaFM4VINxZMeaFiQ/Fjgr9hLb/tZPSrJtCeDhfFj+wJ7pOYs65uapgomSsQzeA2TH/dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4I7CUAfjMk3+NxBTFO1XpfCTeNf9E04NBBFxWYxq4ps=; b=Mwl7KJc7uGGCgxyxSURNKiO4ndZcqtOzV4J7Ip29fj4Sl5pVcMEoqFj49rzbXf9ewh0GhCqwAsCimmO62JRcN83MC8eBqahFo3ZS9Y1/7wDVdnKIvrgE1k4kgn9J4fLG+tw7j5Lyp3wEcn776WMIyIC+kql2lAEbwCctYd7XCfQ= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) by CY4PR1101MB2264.namprd11.prod.outlook.com (2603:10b6:910:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 16 Apr 2021 14:22:18 +0000 Received: from CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725]) by CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725%6]) with mapi id 15.20.3999.037; Fri, 16 Apr 2021 14:22:18 +0000 From: quanyang.wang@windriver.com To: Mark Brown , Michal Simek , Amit Kumar Mahapatra Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Quanyang Wang Subject: [V2][PATCH 2/5] spi: spi-zynqmp-gqspi: fix hang issue when suspend/resume Date: Fri, 16 Apr 2021 22:20:44 +0800 Message-Id: <20210416142047.6349-3-quanyang.wang@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210416142047.6349-1-quanyang.wang@windriver.com> References: <20210416142047.6349-1-quanyang.wang@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) To CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-qwang2-d1.wrs.com (60.247.85.82) by HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Fri, 16 Apr 2021 14:22:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9aee7060-f483-456a-57e9-08d900e30a2b X-MS-TrafficTypeDiagnostic: CY4PR1101MB2264: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1FRJAs/xyhahm09BTRYVYUxZu3OHLVJnDGftTITncsmkmm6PAF9zqPCh5pnMXeL2uzWwqjby6l5Ee/hiHa+5ye4OBmplXZPK5NE5zOOxh8ehkH99aeAHNDa0zc5H/bQ1/keliLK7L8KJvvs3kXp8au87H4UdZwL7CQLwqOTXNGej2S/n5Uad0/bCPUxNevl2rxTSSY2szDOSaTPRAEs5sqhfGpSPtN5tBeu19SIn337Wy5zvmLp0MydPt/3+VbK5fbThYz0qKY9/j2YBXuMfpQkvSiMawxZiP4OYQLAhis2QXrSQ1mVyM9G2aTwOwdvzTCE/CNcPYXZ45573ezJlYf66dBG+U0hYo8I9VdOu3sIKmh8tfn7XdJGXsmC4nfd4PBMgeyrbjDCgXmCL15UW8C2d6Rza7okGQY6vH07Y6dZ2edbtwiAhXnaEXZlB+HlWZwThqrGBa3LBldqRNk5FLbZtSRwXS3WmndOV12/Aeg/+MILbS97l/XKMa/N0S+gFmEkL/lhAtxj1tPHajKKSTuwUWTbt99eP3yqSA6TDV5dpmYGuSJomxCOvaPDNCWW11pSm/FrHMnVvn71o4wsQ9HL+plkgMX2Q6PUCVF6DtD4gSbJioR2CWsQGbdedcYNL94PAtT/sZMBcGcP4bo+h89U7JXeuwXdtUofq/3C7zyM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB0071.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(366004)(396003)(39850400004)(346002)(86362001)(186003)(2906002)(38350700002)(38100700002)(316002)(6506007)(9686003)(6486002)(83380400001)(66946007)(8676002)(66556008)(66476007)(478600001)(16526019)(5660300002)(4326008)(26005)(6512007)(1076003)(52116002)(110136005)(956004)(6666004)(15650500001)(8936002)(107886003)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vODrabnWduXzr+IsIYCsanQMb4PQxXyTClncF/N6EnSl95BOKuBLl2lZLKKnQy6kGUJaYGZRenCecF7e3Yxi9t13tCKK758SXV0HGCwDmypV+gGD/WOgjewjcll5AekrCv7ecH51Zk9p8ioR6k7LaejmCwGc6I4DpVsEK/csjZcmiIebu+1PvmFpCACMTb2skbl0KIgFcuY8JS10JTtD18J/cDKqqSD5nP8B1VNhhEclqttq0PicD4qUIUyYW6qcpTttrJsdabW4yu6aAvC651cktSY0VITMLZuilzo7h3zYP6oJkt+4BlB39uLw8NknEGxFNOtu9LJ5/h1hGPCtLByseCUagh4sTr9EmzdF2gIPwgk/U8kBqwvLJD4hrRRqukCB1tgRlIdQz5HTmFUf5Mafk3+hnsd/polW4QLDs5Aa+l9JL/DqQ4r+SeFEgCUaEaJ7Vs3zUavCoU6QkTz+oLY+qIgKzBPuWK8BDx0C95+xrjXwXBeIYb8PnjaQWaTCDUlId+b7dTVAWA+AcNlJ1L9qxUblD3VeziJa2SOJSOv8hxWWlBgI3c3gv81t4ToOgxJBM/qY6kvMb8SQmEo8R57KeYm2AkXNvWZQLGwtU8PG66tgLpppEkPdcYTQbrAE4/ca+Q3FCv/Ys0lNESG2POYHoLYM1MSn1ubLa7trsan79ZBOworgMh0hYlJ7LumrKVTsn06T/muSFkrwRWwLrLmrNxutF5lkdjJ4Hjn+NDpgAyGbq45Tgh30UVdJPq4bYNKOZ1QDO5f6cmkBrD2TtKKhjKsBZGcGQcu7qxyhDaOZBpEv/EvIHllrPZNbJu9crq/DgfCHygvzkhU58JZd2RVnKK5NVpVkmYvjqoiuUEuo/FTbXyCSYHzoz9faKlocjIymLILdc95qDrew0ujzXXaX6lwmCks6v4bkDDIuFgB8/qhHdMJMMd+MLKxBx0RSc181rB4sSkehzHMF+/bwtS5iXiHgXjS+azX5Fy97yVHY7mZXINAfpROgpeXZmrDBwCgG9vAP+Nx/rP5TXX0IJFTP1ob7/Tvogdqg47no6xGeKRWd9xH3/xz+2mKnurhE8IpFGPYL5PTndupNpaxIjhNL10/TAjArPcdc+4G+hK6gHSWhh29OXUx7yP3vtreimDwhPamUVLgKoXBFTNLFTShQObu/xtB8Z+BF9LEYaWsMt9BMcnHVXimfN6KyDW1l7PZnmidC+0lTH49lbQdPSiUH1r60Rp9lO4abnZEU/ckNtZqXsEmsq89c6nqcPtKJIjcoXt9Zq1UN/UL7ippNkvdFMlWWiCQqYdUvZriy8oRF0/uDZxiS0Xpcqii20ilp X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9aee7060-f483-456a-57e9-08d900e30a2b X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB0071.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2021 14:22:18.0073 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: aVEVTaKp0w8dqGSJ+U5fEXzLPyHAU8n3ImG8nKEtmevGrmkuI3CL/QDIra1jjqqBafegeiGs59dUkvp0W57AH4dhLyziYA0+aj0ajiFMb8A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2264 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Quanyang Wang After calling platform_set_drvdata(pdev, xqspi) in probe, the return value of dev_get_drvdata(dev) is a pointer to struct zynqmp_qspi but not struct spi_controller. A wrong structure type passing to the functions spi_controller_suspend/resume will hang the system. And we should check the return value of spi_controller_suspend, if an error is returned, return it to PM subsystem to stop suspend. Also, GQSPI_EN_MASK should be written to GQSPI_EN_OFST to enable the spi controller in zynqmp_qspi_resume since it was disabled in zynqmp_qspi_suspend before. Signed-off-by: Quanyang Wang --- drivers/spi/spi-zynqmp-gqspi.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index f9056f0a480c..1146359528b9 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -157,6 +157,7 @@ enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA}; * @data_completion: completion structure */ struct zynqmp_qspi { + struct spi_controller *ctlr; void __iomem *regs; struct clk *refclk; struct clk *pclk; @@ -827,10 +828,13 @@ static void zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, */ static int __maybe_unused zynqmp_qspi_suspend(struct device *dev) { - struct spi_controller *ctlr = dev_get_drvdata(dev); - struct zynqmp_qspi *xqspi = spi_controller_get_devdata(ctlr); + struct zynqmp_qspi *xqspi = dev_get_drvdata(dev); + struct spi_controller *ctlr = xqspi->ctlr; + int ret; - spi_controller_suspend(ctlr); + ret = spi_controller_suspend(ctlr); + if (ret) + return ret; zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0); @@ -848,7 +852,10 @@ static int __maybe_unused zynqmp_qspi_suspend(struct device *dev) */ static int __maybe_unused zynqmp_qspi_resume(struct device *dev) { - struct spi_controller *ctlr = dev_get_drvdata(dev); + struct zynqmp_qspi *xqspi = dev_get_drvdata(dev); + struct spi_controller *ctlr = xqspi->ctlr; + + zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK); spi_controller_resume(ctlr); @@ -865,7 +872,7 @@ static int __maybe_unused zynqmp_qspi_resume(struct device *dev) */ static int __maybe_unused zynqmp_runtime_suspend(struct device *dev) { - struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); + struct zynqmp_qspi *xqspi = dev_get_drvdata(dev); clk_disable_unprepare(xqspi->refclk); clk_disable_unprepare(xqspi->pclk); @@ -883,7 +890,7 @@ static int __maybe_unused zynqmp_runtime_suspend(struct device *dev) */ static int __maybe_unused zynqmp_runtime_resume(struct device *dev) { - struct zynqmp_qspi *xqspi = (struct zynqmp_qspi *)dev_get_drvdata(dev); + struct zynqmp_qspi *xqspi = dev_get_drvdata(dev); int ret; ret = clk_prepare_enable(xqspi->pclk); @@ -1090,6 +1097,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) xqspi = spi_controller_get_devdata(ctlr); xqspi->dev = dev; + xqspi->ctlr = ctlr; platform_set_drvdata(pdev, xqspi); xqspi->regs = devm_platform_ioremap_resource(pdev, 0); From patchwork Fri Apr 16 14:20:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quanyang Wang X-Patchwork-Id: 12207821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3543C43461 for ; Fri, 16 Apr 2021 14:22:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F1346113D for ; Fri, 16 Apr 2021 14:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244156AbhDPOWs (ORCPT ); Fri, 16 Apr 2021 10:22:48 -0400 Received: from mail-mw2nam12on2089.outbound.protection.outlook.com ([40.107.244.89]:56161 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S243200AbhDPOWr (ORCPT ); Fri, 16 Apr 2021 10:22:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ah6ebubNZczza3DSQN+BwGBAgh8PkNIxzmLV1YZqTNT4mBzNwxDTB2KJFNbSYH7Y2JuA8sGTnfahj6FHuIl7OqiB3f0gX66axSGWcxU6MRGpDfdR7b2w+cCIn5pd+xb6lC73bka1mW0R5jr8kzGSCa+S2GvXRwGSo5SDF3zrJx7bVZSxgjsQqYKGh4u0d9fFfnjq608htggG87B7ZBwALbjoYQsGaPeRNemLZwUy2cLfOWK4bgE2ExiVg0JD4sURqU5DtgEfHMSGcHdRLBnxGdIYMCtQ0v7czCKJGW32I8xfmk+mAOXBMPnyzBIysHVS63ZKfgQF5mO7yrDHMB2fTw== 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-SenderADCheck; bh=ZK2JV/4Ry5rEqiLLTPLjTpFF5XMXFyKUYVE7Bkdk8HU=; b=Tl0WL9sHZ+fhBSejaVutU/GUAYf/Y+ZFwPrsr0gELInu5+xEa0u5OYo52A0GKg6fWRjt8Qb4mlDxt5SCvMgiu/8rWtGK/atVY+kQUtKetMK/Zl2nVywaP8Z2N8q1XvL+sdwC2IoNEyjUnCTpF0hrjrD/gFhaOXFO01nzQC8GdMNLGBb/wwizTd4n4P43AV5WWvukz/WMDWE5eAZ4qeiyFmZnda0SuL7svAypSZ1QyrFppkY+XcaTeaOtm8uRG/iyPU9ZspzzpIBeMaWqiAwge3jpOYKNsg6SaFTM87HNPKUk796LXqN+o/p+W55TqHBri9tOiCYNY2g3QTE2ikdx8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZK2JV/4Ry5rEqiLLTPLjTpFF5XMXFyKUYVE7Bkdk8HU=; b=EFqkaeNYzFImGl7DxTqQwr6SODrYehJM16umSmprLq2srVuLNHLrsIjMZWDJAA8cNWJTx95wW3HDE+pT/gESAXhJHzcx9/x8Psp+7ZJ77qHSlF5Xjstl4Jqf8yeVCjkysfTqKMO008WUajd9HwMBmtj4Hct+zROJKGJo1WSBhVc= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) by CY4PR1101MB2264.namprd11.prod.outlook.com (2603:10b6:910:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 16 Apr 2021 14:22:20 +0000 Received: from CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725]) by CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725%6]) with mapi id 15.20.3999.037; Fri, 16 Apr 2021 14:22:20 +0000 From: quanyang.wang@windriver.com To: Mark Brown , Michal Simek , Amit Kumar Mahapatra Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Quanyang Wang Subject: [V2][PATCH 3/5] spi: spi-zynqmp-gqspi: Resolved slab-out-of-bounds bug Date: Fri, 16 Apr 2021 22:20:45 +0800 Message-Id: <20210416142047.6349-4-quanyang.wang@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210416142047.6349-1-quanyang.wang@windriver.com> References: <20210416142047.6349-1-quanyang.wang@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) To CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-qwang2-d1.wrs.com (60.247.85.82) by HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Fri, 16 Apr 2021 14:22:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 721bc683-cad2-45fa-bd02-08d900e30bc3 X-MS-TrafficTypeDiagnostic: CY4PR1101MB2264: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vv0Tr0WWDONrHwBBWFE3oP1iuF3InHwwcYpN6LeJCGPsazWmffyoFUwoJZ1p229lZyIh/D9+xGfePnnr3Tr/xxlehtx4y1MBSPoqrTsKzoMG9FWY2Nz9g/dC0LkASlAj/lmfifbUymSQ+2f1/fzYd4+537GpWAMTS2I3l4GAaFS8QpCEp0wiPaDf2lC8v4JdQPRaJpHeanw9PIiMbG+XfoUiFy+L1M6HKPoadcI19EuPUajWp6QCLZ3HMkdfZ6NBcvMg2t5b148kihDPf9VUWSzGQ2UThTTNYhYFj1hvxjDRf6opMdkWKlipK5Qm0Nlh1g6qvrDETFlAjNdb7ck0LQLHh/u31OxLi5l3hJJrBXeUfLg6JofZvq6KZmzhDmNagCOtxBlax64Ob8abHNKZ7jsgPBJAp3SB5VjI+zyrpuK1JT9iil4zB3v2F1Snz1KuZ9zuPDkjRrNJv7Mp7B5acEMYPC5DBSXMRxAGUQ4/f7A0WXM6BQBNh4BbzssVvh4GiQKbhed3q57sERjkfacs1GfCvlKjUvtGQrxAzXSB5qAtXXgYlpqAX1Gao/G+4QGuEhSCIb4xGvEPKwFkr3oBFeM5HjmjAW8newjO+e1gf1EA9oU/pXQ2d3QwaRQVxvA9lzPJs3CkshyxvgwcfwJAhh3CP/ku9dcTmaf9gl+tUNI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB0071.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(366004)(396003)(39850400004)(346002)(86362001)(186003)(2906002)(38350700002)(38100700002)(316002)(6506007)(9686003)(6486002)(83380400001)(66946007)(8676002)(66556008)(66476007)(478600001)(16526019)(5660300002)(4326008)(26005)(6512007)(1076003)(52116002)(110136005)(956004)(6666004)(8936002)(107886003)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: t+QXsiscE4XcfvIp0rDiFuV/xfegs7BPijmhszyNhFox+BPj4HZ/heJPBku2IUj7TG0Ghd15b91M5LyQUqkJI5Hu8YHZK5N9bySaoctZJU3oTXDZ2miQhdCmCpttZXNFD5hFzPE1XcdkoM2zv+y46RdTRv0pvQ5ZJDCiaoMdBnlDod/lq4vo0Jb048clGDlwN1l2DsVJJO1csQeLiQVreH9nZ+67l1QgLQFzv+0BLABdsqo4pwCPwrDJwc21h3hKCO7/ZSsfBlJbKqDYa2ocn7goR+kfCc07DDMv7YTcmDcZ62cJgUfXLPCLcrPVI66vcKCloVWtHWDlke85y8a5+3+i1+b+KUZWl0aqtULTKjV+sY6lxjKjCm6iVGp/e78SsjB9QDwWdfQzMq2jY8x1JtWBOim96+jPG32N0qaLpq11LIYG5+Hu1HnQJmoaa3pTwJwZOArgm4jn3HDE/wChdo67LTD7cOcdF+Ejj6bo9ra4p1WiI9SFsY8QWdAxjmlsevtCqx6EW4jDFXTukAWM5JxGbRKMQrSqYYLhpXqVXtKIoCn8+tdfv8HZ9+15Ih/FoBhGxpkABnpTnZ7uMputZzCSLmupGdHpSsA7xGCHpQZQLj/plo97OOdGSrvgdnYcx3xdrDXRWtud1ruMBE/MSfDAywrMSKaTZJFzLzZB1gwfgHXLt9j/RKOjkEF/Yaifz8lLj9yZaYZj+TYxRpS9ZkucCKiE8IprV/NnQQjsHSUBHGMO9iEV9mthgWPTRKDpSvK+Dl1UprpwR8XPBJy6SURJ8+8bTgVvrNdN+AgHfCUPMmtIj8X5XtDQgwP2W1L3/Lpe/P+IsxDibMLQNTWjt2XaZoAo51b3ymfg6GPyPdfFmfwzfB1WmRHGccvYX23qRxKRSKpllCuYrPDe765jdG5q/y5czu1ZtWVz7AUtXT6M8ZltbuEmDRc4/nE5xpzqedCvaZLXlsYmrQ3pF++tSbhhbh9z+E385jBFkcZKh7NVyfUQEicZaQDGvO35Zvt7peG0hY5cPAvp94ohWYPrzn1vNv2vn868vBF8UQXaFhUHIxyl7pmqeAPO7BNcsquAhKN0GzoKMTypHNVdJjP+LdkHTlfxVxte8N9DtE+P4uw5phkagnOEKqLs9nVAMRlcA+ZAqvcIWRcGu1y8IexW4EbIPKopOuMFmj3U/sMuKeRjm8/JsnqUnuzuBUAFvhQVqeH812NjEiIwx2j0RHrNvAuZ5U5h9InFVoIkUfw+aust8P59gbZwJ4F/zf+z8UgPeAbYQNWIWJf4dEj6sw90l6mjz4jxVmlZPjcjFA+WV11ywWttf6XV1dnIC7Jj2EyQ X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 721bc683-cad2-45fa-bd02-08d900e30bc3 X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB0071.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2021 14:22:20.7337 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: awl/vHQ/0HQcKgIuhY7xzevHvtVcA1qINFlQiipOm06d7xpR4n6VYkH4h7aPTcpBUAkjFRAM9+k/zb3cpji5++sFoPwi5Qn0X0734K9ahI8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2264 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Amit Kumar Mahapatra During a transfer the driver filled the fifo with 4bytes, even if the data that needs to be transfer is less that 4bytes. This resulted in slab-out-of-bounds bug in KernelAddressSanitizer. This patch resolves slab-out-of-bounds bug by filling the fifo with the number of bytes that needs to transferred. Signed-off-by: Amit Kumar Mahapatra --- drivers/spi/spi-zynqmp-gqspi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 1146359528b9..2e2607b5dee9 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -509,17 +509,19 @@ static void zynqmp_qspi_filltxfifo(struct zynqmp_qspi *xqspi, int size) u32 count = 0, intermediate; while ((xqspi->bytes_to_transfer > 0) && (count < size) && (xqspi->txbuf)) { - memcpy(&intermediate, xqspi->txbuf, 4); - zynqmp_gqspi_write(xqspi, GQSPI_TXD_OFST, intermediate); - if (xqspi->bytes_to_transfer >= 4) { + memcpy(&intermediate, xqspi->txbuf, 4); xqspi->txbuf += 4; xqspi->bytes_to_transfer -= 4; + count += 4; } else { + memcpy(&intermediate, xqspi->txbuf, + xqspi->bytes_to_transfer); xqspi->txbuf += xqspi->bytes_to_transfer; xqspi->bytes_to_transfer = 0; + count += xqspi->bytes_to_transfer; } - count++; + zynqmp_gqspi_write(xqspi, GQSPI_TXD_OFST, intermediate); } } From patchwork Fri Apr 16 14:20:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quanyang Wang X-Patchwork-Id: 12207825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6F18C433ED for ; Fri, 16 Apr 2021 14:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9882C610FC for ; Fri, 16 Apr 2021 14:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244676AbhDPOWv (ORCPT ); Fri, 16 Apr 2021 10:22:51 -0400 Received: from mail-mw2nam12on2068.outbound.protection.outlook.com ([40.107.244.68]:56545 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229706AbhDPOWt (ORCPT ); Fri, 16 Apr 2021 10:22:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aCMWyoiwqg10YWv1CzGA1Et2+76XXM7JohWrDNhHyo8R2wOka1XvDsrvIyt+giGGWBYKXsG+1YT44/J6kMeCAn2IUesmqFu0Omx2eJyRO3sbG1ySeVQssWmG1lF7rLFBQXEzWpTObjU6t+9R1G18/g16KmB71MVY7+Y8JyppiojBKhgGgZyVAG3VvRDE61DfdC+aPZMpjaauvwfcuflRe6azoRhFiMO6QTQqTpw7dhSGXf5zu6iCV992bwFVrm36Sj6WLv/jsW7xUuuZATW/EF47B/1PM7OXGzH/C/bCcBlGEZhOl8d6IwOBVbW8KrQG3KaLYc1GZJ1sBGdvB2RCkQ== 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-SenderADCheck; bh=zo9txHMoK5YhgrjEZmAchCVCugiRePlNVRloyfQWHPI=; b=e+iep/x8mEI0dKjDoHPB70xBqpOtM1B7pOZvCZqAHpfsM5TCssCkp/Q9Jwyz7BpcrLv1aJz42wi9Q4jiiB7/v93bv8AFmwJoyUJ4d4zWCyZMreBUr5GfgymWtqS8WNJXXQMTZV8JKt3tx0fvtWuml3bUdZnXTQAxjyaGrAKLLLGhYavirjiygEzEQ/icZ3/zB/11yiy5KInawGKN0AWw7xRhctWeHIQWdYKUfmIRtRx32yj6qB/IQlg3f4kDvnHfapKE5d14aUpug3nHHKkiuw2/9JfkQ04fHPi9s5zeYrWq0pCKSilTmwdDodruwuePEzc/epXPFR6jtyGn4B+J+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zo9txHMoK5YhgrjEZmAchCVCugiRePlNVRloyfQWHPI=; b=IZhSYKX3PRL3IEXSYsUPQd2Uo3jZ6n6ULEPQxVZHrSqX9ZfEQqU5dl0ZoI6F0wzO9TZfwSTaPtlhWXNg4vYtmdf21/16S7aaSYf1n3We3WRkXJvnXldy+EyZEOJqvKe7KHn3W/nc2j+aZohmC/DaUOFW9UdzFsu3LdO/wEHjFQ8= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) by CY4PR1101MB2264.namprd11.prod.outlook.com (2603:10b6:910:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 16 Apr 2021 14:22:23 +0000 Received: from CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725]) by CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725%6]) with mapi id 15.20.3999.037; Fri, 16 Apr 2021 14:22:23 +0000 From: quanyang.wang@windriver.com To: Mark Brown , Michal Simek , Amit Kumar Mahapatra Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Quanyang Wang Subject: [V2][PATCH 4/5] spi: spi-zynqmp-gqspi: fix use-after-free in zynqmp_qspi_exec_op Date: Fri, 16 Apr 2021 22:20:46 +0800 Message-Id: <20210416142047.6349-5-quanyang.wang@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210416142047.6349-1-quanyang.wang@windriver.com> References: <20210416142047.6349-1-quanyang.wang@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) To CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-qwang2-d1.wrs.com (60.247.85.82) by HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Fri, 16 Apr 2021 14:22:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b75fde8a-91aa-4546-f934-08d900e30d76 X-MS-TrafficTypeDiagnostic: CY4PR1101MB2264: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2oYT1sa15t2KEomKpdkPlaDT+3js/A5ynYNk79+oYXT+uupE5UyeJUngw4rDf9uiQF3hVf0c+FudXo7yJHf1c2o0QmBz/TE/mu4040QoZj9rsIyZ9cUERnaiovxb9U/lIS1+3FCVdxPp/Iqj8h8ObPj+oFd2P8ita5SG3SnaFbB1VuaznxTIYOaqcVm3ijGG302LnDnYDO4WBHVu5RClgMtNACADrz1X4EB3wtnSnW3yfoXtnpO46zGHRYnNhK2r01h7OEQN2slNTqnbQBchQvotwSyfyYIUnHdyE6Dk2Y4uO06R9LcICsuO/DWemLlVr1ql5J4egbKaFzeeDhDuY+xfOSoRXU/1In467zIviTa4rl4OWhpoxUNor6F7xUndQLON5xxEjebqs9wppoVR6DVbZLqbL0u2nH3XgkT/oPrpCB2xlVN9VtcmdYe6Ys6/5A81aoCuZyynvtZau7QsVZxvuQUqXJPYh7cx8ZJk5jkiySvbq3dSComlr9yvzhAmVqYLL1PRuFdlFmWBe4Q6WAG2o4wfHZGHY3hg7Qo6ADelWztx9PVDu0kTi3bsnvfpysXZTiMLozZ6xT86WAMf/iaIlc8MN24bDEhCvdrnYC3HkN0/pmqahKJsMJdNVi4CXiBUKY7Rx1BY/abLTjPiew== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB0071.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(366004)(396003)(39850400004)(346002)(86362001)(186003)(2906002)(38350700002)(38100700002)(316002)(6506007)(9686003)(6486002)(83380400001)(66946007)(8676002)(66556008)(66476007)(478600001)(16526019)(5660300002)(4326008)(26005)(6512007)(1076003)(52116002)(110136005)(956004)(6666004)(8936002)(107886003)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0sOjiBr9NKM/9TCDQA7Q6oJt7uSlDoaLgre/PPY+vf+JQPgqyIolYqat+6xOsLa1/0BHnfA86SkNxXdEX49nfr9q9EKUWMthKdRWZgAYJqpyKpz1UaQqx1BY/qO1xsHd6I2xu+LLBqPw1CkQ8bemBCLqJjE/yvlx1MMnUaM126AK/nCdCQmmfxk8wgyh3HBhWW823qGAsnMq5UUOZO8b9OE2ro5W9zIlQKaoWfB4rU8GVSHprMCw5JL/UIKWx03tC/u70KDSZ8NJaZZ3NXgnth4YV2KJju9a9JTKWKFQe4p7vnpNWZ5gqq4v5nUnccKrv26o8g0maa3F4WDnkXATYz+RfimyqkYPECqzhExhpJ7WaKBmtgAG4FtBguzrVgSUQqpaO9nvnd6lRXbsU2NcEuhwiuUcC0PfiG4unSgLSYtqZ0XYU/e0dzE53/3k0glR5aKPMnfkNolbsRNC0qlm0FwPmGAcLqI861/rfJIaw6dP3ATC1bG3v0n6lvPKYDyOxTAoLR3yt2jkvaCU8U24yx9UndK0Pa0CTCBFV3xNInvYrKJX9imCfMa/6SW/3gSusv0comJDZrFcHTkrFcgaqarJ8z+AnYyVNZMCR0gsqjWflw3zDP0k+9IVXjwjXdoZCRfoQbmbvk3eZk8oCXFfSQPop/bHll3AyLFcaLGsaVMZig9WXC8MWctjrIevBb18aYdXXambnKAuC9n0+hcnsK7h36O3LCkfZcjWVnNR3yOavLx4Z6wQbLh8/mvC14AADKlDthQpMpo710Uy06nR5WfjkSMX1VG8wtZ6oX74iIm/AEdReOYHIQVgc+gHcd/qNQ2cP5RpjcmOl+uJ0a3JLLboATe0hgQAW9tOag3Vihjoq4cNB8xG/KeC4ap1OpIhqSOg7c3YUqj9NIw6wdKMFEEs6xpTiugnDLitXNVMtiemEUlXJavLux7AJNy3TOGThS9iLExugRTgNHi59qn3sblLIOh+ro5ZRKO84nKVF7SBYrOyUsyjgsRpMlBX/rj316ZQTipwpXuqC2ca/te8AreA7ENxd2lyhDeHxkxpYAnAG0YpXJWxZjGlOfeT/jf/u33T7nXyQbCFmxzhVuoQ6A+iz4YwI9KfEUudhOF0tBzIGpddlMTEk2fNwNDWN4QyK0637EGPsY4bMd9K83U0UfVpILE5mXPDyxAvkl2vlzrQ8PTNGRr2uL1JeJE7Zb7xZR/U39MGpcbLdm4AxIXkWE8QHGXBn9cqJgh54q0Pw1gdVoz/EAAsQZvRAZnYJM/mJkoLCKxOgx9QhOOYdrjtGKtE3hP6HDaz3wpmyk/pBBJo9Wghm99M12fn7oIypB4C X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: b75fde8a-91aa-4546-f934-08d900e30d76 X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB0071.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2021 14:22:23.5481 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dmHlRdvHtWFuLHxnneOULwJyBROl9Zp30qGElwRYAZVsyXvrb84njWiC0kFQaR8StR1rxb/WIaPrZzcfIIVOA4QeDla5HePS8z0+c7HdMwE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2264 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Quanyang Wang When handling op->addr, it is using the buffer "tmpbuf" which has been freed. This will trigger a use-after-free KASAN warning. Let's use temporary variables to store op->addr.val and op->cmd.opcode to fix this issue. Signed-off-by: Quanyang Wang --- drivers/spi/spi-zynqmp-gqspi.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 2e2607b5dee9..419bc1e6358b 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -928,8 +928,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, struct zynqmp_qspi *xqspi = spi_controller_get_devdata (mem->spi->master); int err = 0, i; - u8 *tmpbuf; u32 genfifoentry = 0; + u16 opcode = op->cmd.opcode; + u64 opaddr; dev_dbg(xqspi->dev, "cmd:%#x mode:%d.%d.%d.%d\n", op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth, @@ -942,14 +943,8 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, genfifoentry |= xqspi->genfifobus; if (op->cmd.opcode) { - tmpbuf = kzalloc(op->cmd.nbytes, GFP_KERNEL | GFP_DMA); - if (!tmpbuf) { - mutex_unlock(&xqspi->op_lock); - return -ENOMEM; - } - tmpbuf[0] = op->cmd.opcode; reinit_completion(&xqspi->data_completion); - xqspi->txbuf = tmpbuf; + xqspi->txbuf = &opcode; xqspi->rxbuf = NULL; xqspi->bytes_to_transfer = op->cmd.nbytes; xqspi->bytes_to_receive = 0; @@ -963,13 +958,12 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, if (!wait_for_completion_timeout (&xqspi->data_completion, msecs_to_jiffies(1000))) { err = -ETIMEDOUT; - kfree(tmpbuf); goto return_err; } - kfree(tmpbuf); } if (op->addr.nbytes) { + xqspi->txbuf = &opaddr; for (i = 0; i < op->addr.nbytes; i++) { *(((u8 *)xqspi->txbuf) + i) = op->addr.val >> (8 * (op->addr.nbytes - i - 1)); From patchwork Fri Apr 16 14:20:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quanyang Wang X-Patchwork-Id: 12207827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00572C43461 for ; Fri, 16 Apr 2021 14:22:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D132F610FC for ; Fri, 16 Apr 2021 14:22:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244703AbhDPOWw (ORCPT ); Fri, 16 Apr 2021 10:22:52 -0400 Received: from mail-co1nam11on2061.outbound.protection.outlook.com ([40.107.220.61]:29089 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244696AbhDPOWw (ORCPT ); Fri, 16 Apr 2021 10:22:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V+rW5bsTS+hAp7er79LsJSnl8Gx4nZvDU5TVkKfP1STVpPcHarsIxaNi3LPhAGz7v4aigDwfVyWD4NNvh6bAiCIGsAqwVDyg/L2csfFXb8THha76Y2//riDMxZwDTuSRWEP1615Wg+v2QntKiE1TdIVntY9m0/bAQsUr9RXSXuASGFYPSgUG1FRi2PfbA2UtxlpteFBAiJskHFu3Kbd3Sr50r3Ytvgzdi6lT9qz5ydspVoGjKz58SBHzAh0g6BAVA655uMjEBP5l/yP8XVNNCUQWJURSjTa1TbGWnu/tZRM/c1FisYrbXsYEnpaF/BG5+vXKZssSMdo0ygkrs6mi8g== 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-SenderADCheck; bh=lEEseomfkt/2DJqbH8TTqFjQdRgIigv5Y586PQH9HzI=; b=bE2gNBjE26eXhLGgUdw+KPKZp/P4CRTKGfdxFEwC4ZqaNC2nLHSvVYDsyPxDC9vjBtSeq67k3yIM5IUlznFPcPA5VEHBP3lR37dFCm8lNHcYO3KXO6ae6GJMf65Cv6cQinuVgscVufWuZfr0DX1K5uJxgxR5uKGncQATIgjJ2do79B4dYfFEhMOG3E8Sk3H1gMMQ8lwLtcqP4NyHTumo+ufqDcp0k0ggA0Bi43kff7KXlmDwdfaeCSz5+K3V+nQ2q7o7cmHzm5jaWjDZr9Vrh98NIRAx9D8YAMHmXQa5+14vXzSvehC/L9phQuBkg96t9cdCzVuEukJl5KaXbjApxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lEEseomfkt/2DJqbH8TTqFjQdRgIigv5Y586PQH9HzI=; b=DBcoQ0NV863uk/23xkqFaFd3GtooXSZXb/y76vAVvBImzeiaFnDUDb7c3kdaJk2auI2jt/M4Lbl4RewLF3zbJCFC19KH8UvLSSlgM/Tyv3kECg+CtdvrHzqIof0wH9gYjcTDkmF25PC2jZJjko0CV8wE1cpj7S4X45UkNjjLZhE= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) by CY4PR1101MB2264.namprd11.prod.outlook.com (2603:10b6:910:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Fri, 16 Apr 2021 14:22:26 +0000 Received: from CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725]) by CY4PR11MB0071.namprd11.prod.outlook.com ([fe80::f45f:e820:49f5:3725%6]) with mapi id 15.20.3999.037; Fri, 16 Apr 2021 14:22:26 +0000 From: quanyang.wang@windriver.com To: Mark Brown , Michal Simek , Amit Kumar Mahapatra Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Quanyang Wang Subject: [V2][PATCH 5/5] spi: spi-zynqmp-gqspi: return -ENOMEM if dma_map_single fails Date: Fri, 16 Apr 2021 22:20:47 +0800 Message-Id: <20210416142047.6349-6-quanyang.wang@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210416142047.6349-1-quanyang.wang@windriver.com> References: <20210416142047.6349-1-quanyang.wang@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) To CY4PR11MB0071.namprd11.prod.outlook.com (2603:10b6:910:7a::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-qwang2-d1.wrs.com (60.247.85.82) by HK2PR02CA0147.apcprd02.prod.outlook.com (2603:1096:202:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Fri, 16 Apr 2021 14:22:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 97494371-f883-4191-6bbc-08d900e30f09 X-MS-TrafficTypeDiagnostic: CY4PR1101MB2264: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M0PssXsM8sDSzkKBFvt2afBWdd3C2F63HVVIndKD5j1JnAe2ftnP3OtwWDivWcd0ItHw2AJcRCrBNAvRupZ5xRRsCpnajrAxPeeXLwMDNVgBtkwozyh1eY/tao4GWIlP8LcMENlG+mi5NEDl32ZYa9Y9udQgS1CtnrkZkSJrz5U0aUaex+kD739qhB3rN1cAT/eMzhW6FVZzCkYrjlT/Ooh88RogNL1G1tZJnxMBr8ZDnrJOYFmdBNgBEPXCLwsNRQhvxxtU79HSDhEy1gbrHA9j2PWk88+HWuKTLVNvjr391vW4im0AQd6B+sjY63U7Dp58Z3fCgVsjzoNmtp50x3tu5HNsydXoIR/JkxNpoYMkabJeZyHSXJKNYDA1Wvh7AtpmVJoABiNJeu5RuaEGe1G3gDzstIhFhSP8ZPzOQORgACYNLTBPIzbLwyCeTSAVZXAv4OpEeHYjRC330jrYwfkV/+T+FrYueC8wOSRQB7bMOIi9yW87aPnQh/MFoyL2HZXjxOOzniCO+F7HD9xWuFUmniW7SMegmDCY/99YzC8uxDnPA72F1z1YuljQjVglrU00W+Z3/pS9dzebMTVARm55dRpWKL2f+ZzxJ17SXL65KRIncYXY4vEOI3HiuNaoX7DGhQqSoGYTBvAwNmF0Pw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB0071.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(366004)(396003)(39850400004)(346002)(86362001)(186003)(2906002)(38350700002)(38100700002)(316002)(6506007)(9686003)(6486002)(83380400001)(66946007)(8676002)(66556008)(66476007)(478600001)(16526019)(5660300002)(4326008)(26005)(6512007)(1076003)(52116002)(110136005)(956004)(6666004)(8936002)(107886003)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Cv/yTRUX2QunEK//59kSOJL9G5wV51AQGYd76dP4TNkzLoafF0+I6PH2zsRPgmnkj7qArX3FvkJCos9BiW+L/7x41QPqRin/w2yu+ERvg21nu5GVyqzE/URVY0TOmmMqsWGEvUFPRM6k52dayUOqiMMdlr1F8v7IVXw7949YP9s3/Bqp0xD8QWYkITfnx+9bczw14JJm3ys1ZZc/KawzBcfO5FTMj/cO8l25uGDpffvpxQxDix64Q61yD1jaVAIWc+hPQBKrnMxArE1Sztupe5jmjorBviFdSS/TBY+6VkmyLHLY9zEJV2+fR85etdXBzQHCPtVaKLeIvnfHYkLfbkvvaCRG3/wzMCmZWcD8IsGXrEr3INcmX5SzURiO97QTCI5SXeGWjI0itVYOYzuICWPcAZZC8OThmRDFcbDJi4/G/SBHziFpv1lOiYAoz/8Rb3crm4mopVri2MLtWyedBuKFpvWDvi+WPp0XK2T7DUXT4LKNcP00C7D6aWJy8gF9eiW4Dszx5mqEfAgVwUo7joZpfWNaVHklFsibSEDPwIMg/zX6YQGNjSuC3La3JWM5UKSwyGaTetOcWLDjZ1Kzzla3yugOX0UVlxGf7Lx/JOTRLgGG9/5PalPylYec9+0X35YHAwxEZ4ZFXZExsoJhjDSBHG/sWkMaDkUg3RSWS///m4pqUrFAhUeNObK+w42iDpaILlgHdr7MCo3XBToORTrV1XhaFzufDNojxz5RuZQDJO93mfdzayZVaS/6qCDo4Shw7mwEAtnb3SusN+pi5ZO+Ug7i95oRPpya4HokvGH3A9nErHJfwKZO+sZEDph94s9QUzdZjrvQ3ufpQMRSsQxBolHrJAbu93olHwzRYDx1fXDoZ7ZSnzT8ZUBKGA25anBPMUlmWRo/b/ohlaBIqEfeIPqenEjMyDAZ+gi5YEDFn3DP4WTXp96NBtjBeEMbQhvkeW1kV5E5PFmVSSwwARU9UOg4mD4kDpXFmvaVETB2uN60sjUEqL79hQOenArJKwrkuWXCGVSgGBBZIQ2mDe9XOrCqx8ei6GUp8I2SfEF/oTJYiukASzT764BaT6AoDCGLd9cD8TRDppRMgRwcHOTU3zEBTEdxfGRbvfDjXE8Nd18buxh0NK8hiuYvMU+a9qncbkAOOOZLO4/4pWrGzpX9EvWRTuPsqKlK+kYeEY7ZtvrVmoqXZPfG0NuVVVqo5tRWxqjdefkIV+0asmnGaw6v8CKwTIt9Vm4DlVz4GDULGciDveXVNDSLoCZbevpNRscw4L/efQfJLLZ/uPDOncRWzFrBWjVmsi5B3rspf9TkPSvovLyy2kkAoyo95BU/ X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97494371-f883-4191-6bbc-08d900e30f09 X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB0071.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2021 14:22:26.5744 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +tJzrjZvql/ijI16JyfAFgwbuoDRHGM97qPlL2TUeY9WO5/p/IoOsi3w8jFtlouCDMLFjlaY5Y1bw/2t4HTaxUlRo5/5CDCtNnf6dCBl8Tk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2264 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Quanyang Wang The spi controller supports 44-bit address space on AXI in DMA mode, so set dma_addr_t width to 44-bit to avoid using a swiotlb mapping. In addition, if dma_map_single fails, it should return immediately instead of continuing doing the DMA operation which bases on invalid address. This fixes the following crash which occurs in reading a big block from flash: [ 123.633577] zynqmp-qspi ff0f0000.spi: swiotlb buffer is full (sz: 4194304 bytes), total 32768 (slots), used 0 (slots) [ 123.644230] zynqmp-qspi ff0f0000.spi: ERR:rxdma:memory not mapped [ 123.784625] Unable to handle kernel paging request at virtual address 00000000003fffc0 [ 123.792536] Mem abort info: [ 123.795313] ESR = 0x96000145 [ 123.798351] EC = 0x25: DABT (current EL), IL = 32 bits [ 123.803655] SET = 0, FnV = 0 [ 123.806693] EA = 0, S1PTW = 0 [ 123.809818] Data abort info: [ 123.812683] ISV = 0, ISS = 0x00000145 [ 123.816503] CM = 1, WnR = 1 [ 123.819455] user pgtable: 4k pages, 48-bit VAs, pgdp=0000000805047000 [ 123.825887] [00000000003fffc0] pgd=0000000803b45003, p4d=0000000803b45003, pud=0000000000000000 [ 123.834586] Internal error: Oops: 96000145 [#1] PREEMPT SMP Signed-off-by: Quanyang Wang --- drivers/spi/spi-zynqmp-gqspi.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 419bc1e6358b..328b6559bb19 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -733,7 +733,7 @@ static irqreturn_t zynqmp_qspi_irq(int irq, void *dev_id) * zynqmp_qspi_setuprxdma - This function sets up the RX DMA operation * @xqspi: xqspi is a pointer to the GQSPI instance. */ -static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) +static int zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) { u32 rx_bytes, rx_rem, config_reg; dma_addr_t addr; @@ -747,7 +747,7 @@ static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg); xqspi->mode = GQSPI_MODE_IO; xqspi->dma_rx_bytes = 0; - return; + return 0; } rx_rem = xqspi->bytes_to_receive % 4; @@ -755,8 +755,10 @@ static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) addr = dma_map_single(xqspi->dev, (void *)xqspi->rxbuf, rx_bytes, DMA_FROM_DEVICE); - if (dma_mapping_error(xqspi->dev, addr)) + if (dma_mapping_error(xqspi->dev, addr)) { dev_err(xqspi->dev, "ERR:rxdma:memory not mapped\n"); + return -ENOMEM; + } xqspi->dma_rx_bytes = rx_bytes; xqspi->dma_addr = addr; @@ -777,6 +779,8 @@ static void zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi) /* Write the number of bytes to transfer */ zynqmp_gqspi_write(xqspi, GQSPI_QSPIDMA_DST_SIZE_OFST, rx_bytes); + + return 0; } /** @@ -813,11 +817,17 @@ static void zynqmp_qspi_write_op(struct zynqmp_qspi *xqspi, u8 tx_nbits, * @genfifoentry: genfifoentry is pointer to the variable in which * GENFIFO mask is returned to calling function */ -static void zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, +static int zynqmp_qspi_read_op(struct zynqmp_qspi *xqspi, u8 rx_nbits, u32 genfifoentry) { - zynqmp_qspi_setuprxdma(xqspi); + int ret; + + ret = zynqmp_qspi_setuprxdma(xqspi); + if (ret) + return ret; zynqmp_qspi_fillgenfifo(xqspi, rx_nbits, genfifoentry); + + return 0; } /** @@ -1031,8 +1041,11 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, xqspi->rxbuf = (u8 *)op->data.buf.in; xqspi->bytes_to_receive = op->data.nbytes; xqspi->bytes_to_transfer = 0; - zynqmp_qspi_read_op(xqspi, op->data.buswidth, + err = zynqmp_qspi_read_op(xqspi, op->data.buswidth, genfifoentry); + if (err) + goto return_err; + zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, zynqmp_gqspi_read (xqspi, GQSPI_CONFIG_OFST) | @@ -1159,6 +1172,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) goto clk_dis_all; } + dma_set_mask(&pdev->dev, DMA_BIT_MASK(44)); ctlr->bits_per_word_mask = SPI_BPW_MASK(8); ctlr->num_chipselect = GQSPI_DEFAULT_NUM_CS; ctlr->mem_ops = &zynqmp_qspi_mem_ops;