Received: by 10.223.176.5 with SMTP id f5csp821397wra; Sat, 3 Feb 2018 11:03:57 -0800 (PST) X-Google-Smtp-Source: AH8x2249PsTnPZ0ndLmLjQCMdRK/QbORRZ2IbUO5fdArF+3xomQxtoa5ZEyORCDWtR1DCAkrU9Rw X-Received: by 10.99.120.199 with SMTP id t190mr33609974pgc.180.1517684637191; Sat, 03 Feb 2018 11:03:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517684637; cv=none; d=google.com; s=arc-20160816; b=OYE0xrBExzZeZLq7lNqr+/dcj9yUsNufzPty8MfDV31jT37lCoTlFb0A86D2rY+gRP e0zcgYItJi3u5Ib7j/SpyEO/gvB4b28ppLM2geGAAvWFJVfVjtvtj1h36znPzpCohMjG Wz7zIe1EZPi11czZn1xRLQcc2m1k+mNJyg+EpkOYPyD9/QlqpBLMVRzaIDQXOkiOJOhF yIdi6WV0PQ5utAofSAz2mh6+bHCZ8vZLGMd4tDm1yVG5/CXr1ydQaE/DB3BjEVxUeMzY nFY+kOH/yrDlS2xkta+nr80c67gk4nxHhKsh52M4cOAI90hw/ztEGNiZktSQIYLyRzIJ Bi5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=/QW/Krh3nJ0Qc6Lzj66dusfxWpESxCDof1hLZg4lJaU=; b=da3ZLkv74O8wxL0SagdGm8MPwlHkgWjr8FA51HwGEoUh9tL6IO39S7AjcoeRGVe8ma XMBhNLMJlwUEF4es0owZu820v4gIMannQhPxsJTXUIX25xTguXCgx4mrw09CWdvDEhtZ csSW5kyFwhu5ExTvNCZdPYb80TS/baL3zw9oii8e+rb3kkEEmYjQanlwsGN6PtkcaSsD 7lInREY9SfaosGhzvJ2DZsZopi9KcJhygqvbCIhUvWIQFAzIc+AeB1UCbshHgmGcTRSs jIjEjw+TfAripeq76Qaocxs2ji+fi3/0SP2QGZKN3n0O9wq7UnT0I2DT/QER1SOkz80/ EbBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=khneY+7D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21-v6si4153277plo.46.2018.02.03.11.03.43; Sat, 03 Feb 2018 11:03:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=khneY+7D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752873AbeBCSBU (ORCPT + 99 others); Sat, 3 Feb 2018 13:01:20 -0500 Received: from mail-co1nam03on0122.outbound.protection.outlook.com ([104.47.40.122]:24267 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752669AbeBCSAe (ORCPT ); Sat, 3 Feb 2018 13:00:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=/QW/Krh3nJ0Qc6Lzj66dusfxWpESxCDof1hLZg4lJaU=; b=khneY+7DbZBvNVPq6pWtz1SqqVgnhc86kbV0FHMmAX9wh72RRYhLWgVmwOymaoYgDnEZd5In55aeca1fz+Cpqo6PyJ7IRusjdskIeypN3gedp18SZFw7awmj9zV1PzlNDCQnoI6/ZPMxWp9xFm9DQo7/ryz4jnIpc/F4CTyejuU= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1043.namprd21.prod.outlook.com (52.132.24.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.506.3; Sat, 3 Feb 2018 18:00:30 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:00:30 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Andreas Platschek , Vinod Koul , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 005/110] dmaengine: fsl-edma: disable clks on all error paths Thread-Topic: [PATCH AUTOSEL for 4.14 005/110] dmaengine: fsl-edma: disable clks on all error paths Thread-Index: AQHTnRjfJNsvGoIm+0qCjJ8Rw5Gowg== Date: Sat, 3 Feb 2018 18:00:28 +0000 Message-ID: <20180203180015.29073-5-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BL0PR2101MB1043;7:jq+3RlCKTRqG1fC8LBGNzHVlVv1p5B84EE7rVcQ2LJqQpgPhSUH148NTJDTI1r1nNhy/a2UrLz44BgVcqDsqum2W/O2CusShI/FD7EBetspy9/wCTQoc3dPLLaKTzPeLfl0l+BAYSodnlC5GXeJda+XQF484HIq7VOETw+G9vKIJg/zXVY5+kQqt3wPgyr2Zntz22rDJJD6KnlAX073lhFeUbmJhneicFzdIPpWkBRbj6UbD9jTnTSOmmJ4EDO1l x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: cf606aaa-94d1-45c2-dc54-08d56b300386 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1043; x-ms-traffictypediagnostic: BL0PR2101MB1043: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3231101)(2400082)(944501161)(93006095)(93001095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:BL0PR2101MB1043;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1043; x-forefront-prvs: 05724A8921 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(376002)(39860400002)(366004)(346002)(396003)(189003)(199004)(59450400001)(10290500003)(186003)(6486002)(14454004)(1076002)(102836004)(6506007)(76176011)(26005)(6346003)(66066001)(10090500001)(5250100002)(36756003)(6512007)(2501003)(110136005)(99286004)(54906003)(478600001)(53936002)(72206003)(6436002)(316002)(305945005)(7736002)(2950100002)(2906002)(5660300001)(4326008)(106356001)(86362001)(97736004)(25786009)(22452003)(2900100001)(3846002)(107886003)(8676002)(8936002)(6116002)(3280700002)(105586002)(81156014)(81166006)(3660700001)(86612001)(68736007)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1043;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: GdRD/4s+ix0pTxajQWBsSvZoJCTSqlwrlxu2wDslSQPdas85sHmzrFZCCbPSCsyjfsd+KkvkUCAUETTQt33mSQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf606aaa-94d1-45c2-dc54-08d56b300386 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:00:28.4721 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1043 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andreas Platschek [ Upstream commit 2610acf46b9ed528ec2cacd717bc9d354e452b73 ] Previously enabled clks are only disabled if clk_prepare_enable() fails. However, there are other error paths were the previously enabled clocks are not disabled. To fix the problem, fsl_disable_clocks() now takes the number of clocks that shall be disabled + unprepared. For existing calls were all clocks were already successfully prepared + enabled, DMAMUX_NR is passed to disable + unprepare all clocks. In error paths were only some clocks were successfully prepared + enabled the loop counter is passed, in order to disable + unprepare all successfully prepared + enabled clocks. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Andreas Platschek Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/fsl-edma.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c index 6775f2c74e25..c7568869284e 100644 --- a/drivers/dma/fsl-edma.c +++ b/drivers/dma/fsl-edma.c @@ -863,11 +863,11 @@ static void fsl_edma_irq_exit( } } =20 -static void fsl_disable_clocks(struct fsl_edma_engine *fsl_edma) +static void fsl_disable_clocks(struct fsl_edma_engine *fsl_edma, int nr_cl= ocks) { int i; =20 - for (i =3D 0; i < DMAMUX_NR; i++) + for (i =3D 0; i < nr_clocks; i++) clk_disable_unprepare(fsl_edma->muxclk[i]); } =20 @@ -904,25 +904,25 @@ static int fsl_edma_probe(struct platform_device *pde= v) =20 res =3D platform_get_resource(pdev, IORESOURCE_MEM, 1 + i); fsl_edma->muxbase[i] =3D devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(fsl_edma->muxbase[i])) + if (IS_ERR(fsl_edma->muxbase[i])) { + /* on error: disable all previously enabled clks */ + fsl_disable_clocks(fsl_edma, i); return PTR_ERR(fsl_edma->muxbase[i]); + } =20 sprintf(clkname, "dmamux%d", i); fsl_edma->muxclk[i] =3D devm_clk_get(&pdev->dev, clkname); if (IS_ERR(fsl_edma->muxclk[i])) { dev_err(&pdev->dev, "Missing DMAMUX block clock.\n"); + /* on error: disable all previously enabled clks */ + fsl_disable_clocks(fsl_edma, i); return PTR_ERR(fsl_edma->muxclk[i]); } =20 ret =3D clk_prepare_enable(fsl_edma->muxclk[i]); - if (ret) { - /* disable only clks which were enabled on error */ - for (; i >=3D 0; i--) - clk_disable_unprepare(fsl_edma->muxclk[i]); - - dev_err(&pdev->dev, "DMAMUX clk block failed.\n"); - return ret; - } + if (ret) + /* on error: disable all previously enabled clks */ + fsl_disable_clocks(fsl_edma, i); =20 } =20 @@ -976,7 +976,7 @@ static int fsl_edma_probe(struct platform_device *pdev) if (ret) { dev_err(&pdev->dev, "Can't register Freescale eDMA engine. (%d)\n", ret); - fsl_disable_clocks(fsl_edma); + fsl_disable_clocks(fsl_edma, DMAMUX_NR); return ret; } =20 @@ -985,7 +985,7 @@ static int fsl_edma_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Can't register Freescale eDMA of_dma. (%d)\n", ret); dma_async_device_unregister(&fsl_edma->dma_dev); - fsl_disable_clocks(fsl_edma); + fsl_disable_clocks(fsl_edma, DMAMUX_NR); return ret; } =20 @@ -1015,7 +1015,7 @@ static int fsl_edma_remove(struct platform_device *pd= ev) fsl_edma_cleanup_vchan(&fsl_edma->dma_dev); of_dma_controller_free(np); dma_async_device_unregister(&fsl_edma->dma_dev); - fsl_disable_clocks(fsl_edma); + fsl_disable_clocks(fsl_edma, DMAMUX_NR); =20 return 0; } --=20 2.11.0