From patchwork Mon May 29 16:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 13258775 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 CA5FEC7EE31 for ; Mon, 29 May 2023 16:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=feSVJ4ZJC7g6BnidW2efeFPZ8WR9Bevc0v3Vz7xYSoU=; b=HfTpsCCZwZ0bNhictrBxv5zdtu uFXg7yWXltDM9EKyRf7oIm6NAzwXEPKL8bVchdd0Pgk0Hl9CNB5Unfz5Uhuf6nRtA+HEoc6vLnllX WI8zPsy849JjhJKPaloVOR0VyXj5CSflMF2Oo+9Vp5uMfRIOoavIHBfNQLi4qZcLqE7G/PGmfaXHn x0GTCe97CPnvDABqNcmU8DLvgbqSn/29sQ+Bun05ZU275icjoQI+RS1++AFuRIdW6SMERoGPk7CbH r/VyikHGsrTu4N7oDAY/Xg6KTi6cyXn4AuoCivTSTJP+uSvBcNzpVHWcMx+7VuIV3i2JR2nZGn42n xqM1d/ZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q3fdO-00B5uI-0V; Mon, 29 May 2023 16:22:14 +0000 Received: from sender4-op-o15.zoho.com ([136.143.188.15]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q3fdK-00B5sq-1t; Mon, 29 May 2023 16:22:11 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1685377283; cv=none; d=zohomail.com; s=zohoarc; b=OsCqtYftfT3DdQvCNXWDRXWffnX4NxdxU6ZTnICojqLMCbD0RvFIwvSbohu40bqa8doWcLN5ejhYQk2Op/S8n9siL4VsQznGE7oLWmU8q6/1l/FFAOlPJyKBle9co0xJfz4uYHJbrtkCynbCpqrVTf92k1vt2nOUkfrq308UV6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685377283; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=feSVJ4ZJC7g6BnidW2efeFPZ8WR9Bevc0v3Vz7xYSoU=; b=XB2IkOwZYsctD0/n3S9F6IgIfgLG3xJxPtzCLBrdqgltFin7yLZRfCjyZbueIgRSAP+ymU+zCTlUAlDfYHFZe4N1OazNk7+dNH/uilc31ioZMKZvASQByWuWMPpDnaDuW8KR66KwUqXGkZXKcXSqCXGYve+m6OVLEuuB23iPZnM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=icenowy.me; spf=pass smtp.mailfrom=uwu@icenowy.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1685377283; s=zmail2; d=icenowy.me; i=uwu@icenowy.me; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=feSVJ4ZJC7g6BnidW2efeFPZ8WR9Bevc0v3Vz7xYSoU=; b=bLafyXxotwqr9pgTL6UYFeR4qpjB+4ATUbs7x2cx6ctdP5Q4YrMyTScYUkNdq5VM iUW+9ofO/k34ICTcVWLzGni9D0BywAYZLCSY5abGkxZmZN+lP5SZf+WdaJyZkN7TqJo aoIBLknQ71CEZ8EbvNItEX3HJOzUUGJ8IYWa5vhDw7hyc0o5faqDLEBE8cj19yZ/PR+ ggh2B8/cX+M8wornfeFkwvz1lIBGCSiTnjm4fqyYn7PQmUrl0b9M4l9dSx3cz5wttKI kXkTR6wS75ie9iJWJcXd8hd2cDtik/2OKvGi3e89IzXZt2QctzTh29a4NO2FT8YGH1N bvp5LvxXEA== Received: from edelgard.fodlan.icenowy.me (120.85.97.71 [120.85.97.71]) by mx.zohomail.com with SMTPS id 1685377282347443.2734596633554; Mon, 29 May 2023 09:21:22 -0700 (PDT) From: Icenowy Zheng To: "Rafael J . Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Matthias Brugger , AngeloGioacchino Del Regno , Kang Chen , Dongliang Mu Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Icenowy Zheng Subject: [PATCH 1/2] Revert "thermal/drivers/mediatek: Use devm_of_iomap to avoid resource leak in mtk_thermal_probe" Date: Tue, 30 May 2023 00:20:55 +0800 Message-Id: <20230529162056.3786301-2-uwu@icenowy.me> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230529162056.3786301-1-uwu@icenowy.me> References: <20230529162056.3786301-1-uwu@icenowy.me> MIME-Version: 1.0 X-ZohoMailClient: External X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230529_092210_668240_18FC781D X-CRM114-Status: GOOD ( 11.76 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org This reverts commit f05c7b7d9ea9477fcc388476c6f4ade8c66d2d26. As the documentation of devm_of_iomap says, it's not a drop-in replacement for of_iomap because it will detect existed mapping and prevent shared access to the memory region, Because these two calls are mapping memory specified in other device nodes, they are meant to be shared, and devm_of_iomap is not suitable. Reverts the code back to use of_iomap, to fix a regression of display failure on my mt8173-elm board. Signed-off-by: Icenowy Zheng --- drivers/thermal/mediatek/auxadc_thermal.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c index 0b5528804bbd..f59d36de20a0 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -1222,12 +1222,7 @@ static int mtk_thermal_probe(struct platform_device *pdev) return -ENODEV; } - auxadc_base = devm_of_iomap(&pdev->dev, auxadc, 0, NULL); - if (IS_ERR(auxadc_base)) { - of_node_put(auxadc); - return PTR_ERR(auxadc_base); - } - + auxadc_base = of_iomap(auxadc, 0); auxadc_phys_base = of_get_phys_base(auxadc); of_node_put(auxadc); @@ -1243,12 +1238,7 @@ static int mtk_thermal_probe(struct platform_device *pdev) return -ENODEV; } - apmixed_base = devm_of_iomap(&pdev->dev, apmixedsys, 0, NULL); - if (IS_ERR(apmixed_base)) { - of_node_put(apmixedsys); - return PTR_ERR(apmixed_base); - } - + apmixed_base = of_iomap(apmixedsys, 0); apmixed_phys_base = of_get_phys_base(apmixedsys); of_node_put(apmixedsys); From patchwork Mon May 29 16:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 13258776 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 0FE51C77B7E for ; Mon, 29 May 2023 16:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ilrAA1wC/2lR7cmTwLpraXPfwi0Ne6pIsDBp9ANZIxA=; b=5GvNdqMtwZYOC9h5ZQ2tR7EnXJ 5ceaNnMSLWFPIP+wAeS8j/cusghN/wWCj5SYsisvTJycF2SG3RYejDfdqiwlMjkGGjOveDy6F0ccb +Ain1HFlyBhgORZLDeVe7uLGXFCWW3Hu1+iqAdMWF/ik+IQItywmdz6/eAstgb0fnTCuTNzU8/xkQ gK99GGsBrhg/ZCaAroYppfjaBVroA38WfwSoNH/WC62JzkgB3+6KMd3P6+0as9U37ICRIjnD6t87v iGE/0XcmmZd3cvfl5F55Bu/PPy/YomZf43xsIoykfbtqX+1dSw9qUYoBWTc8iSgC/oEinhXtXCacS rv2TIn6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q3fdh-00B64e-1d; Mon, 29 May 2023 16:22:33 +0000 Received: from sender4-op-o15.zoho.com ([136.143.188.15]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q3fdX-00B60O-2d; Mon, 29 May 2023 16:22:25 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1685377291; cv=none; d=zohomail.com; s=zohoarc; b=kJo0+4Nh6uTfjtAcHruO7UKi+Y+CK/sWFzpJcJ/UcKhkgCmDDl8jKEkTyHn3WKvtuFFBCESfKbf5pIrpeiewabdKNwmjMG9fFWprA96xkJXrKGw/4iOoR9LCJ9lFompQ0qoRTsflMudT0oqUrv2GmKFktPolAagpNh4G7L5lh4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685377291; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ilrAA1wC/2lR7cmTwLpraXPfwi0Ne6pIsDBp9ANZIxA=; b=YWlfiW6dExhNftSoyAwit80Pt6GR85YsCYOxH1q4EBTlD03CERJvxe+9CnZqPDaosGP2lSfB7IB9rdc21+Jo7PTxsXbpDJIlSztH/OtDL48foysIRFkixjKguTm8BamTpEOHbBV0BoswDzc+ghVjLN3YVjDET1DEXMBA857t0sQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=icenowy.me; spf=pass smtp.mailfrom=uwu@icenowy.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1685377291; s=zmail2; d=icenowy.me; i=uwu@icenowy.me; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=ilrAA1wC/2lR7cmTwLpraXPfwi0Ne6pIsDBp9ANZIxA=; b=qgv0OzOh3t0eJ4mfgJXlbms56WzoJYNoAyrZ/2maDsOOhBD5fRE6r5PdmClMqiN1 xN6jbjcWhCDhTYd8+KZapgKtvhQqD2bhIRm9cQvWoEvXdRYPJA8IT3PHnVIzfzUmhuT l8b0MUQvh5U7BrX36wWLhtkJlwWAjyfxbNlaw3YzSLxfyqc+Aq2L/dS4RkAL2ivEMPU hwZTN71m1p0KOPOdRty8pl9J/kaov48y1a71zSqkD/1nysX5m/iJ3H1JeguajDGBRGp pPoe5MLoBd80nmxSalVmYfRv8jAVnaKGZRe4Ck8rYEqM2oKt7JWBP0eRGztHk0jz+3J RLMxeE9srA== Received: from edelgard.fodlan.icenowy.me (120.85.97.71 [120.85.97.71]) by mx.zohomail.com with SMTPS id 1685377291110330.7646889379969; Mon, 29 May 2023 09:21:31 -0700 (PDT) From: Icenowy Zheng To: "Rafael J . Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Matthias Brugger , AngeloGioacchino Del Regno , Kang Chen , Dongliang Mu Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Icenowy Zheng Subject: [PATCH 2/2] thermal/drivers/mediatek: unmap foreign MMIO after probing Date: Tue, 30 May 2023 00:20:56 +0800 Message-Id: <20230529162056.3786301-3-uwu@icenowy.me> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230529162056.3786301-1-uwu@icenowy.me> References: <20230529162056.3786301-1-uwu@icenowy.me> MIME-Version: 1.0 X-ZohoMailClient: External X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230529_092223_921858_FC915E96 X-CRM114-Status: GOOD ( 13.82 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org The MMIO space from auxadc and apmixedsys devices are only needed when initializing the thermal sensors, so these memory regions could be safely unmapped after the probing process to prevent resource leak. Unmap them at the end of the probe method, and route the unmap codepath to early exits of the probe method for preventing leak when error handling. Signed-off-by: Icenowy Zheng --- drivers/thermal/mediatek/auxadc_thermal.c | 32 ++++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c index f59d36de20a0..c010a96f9aca 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -1229,13 +1229,15 @@ static int mtk_thermal_probe(struct platform_device *pdev) if (auxadc_phys_base == OF_BAD_ADDR) { dev_err(&pdev->dev, "Can't get auxadc phys address\n"); - return -EINVAL; + ret = -EINVAL; + goto out_unmap_auxadc; } apmixedsys = of_parse_phandle(np, "mediatek,apmixedsys", 0); if (!apmixedsys) { dev_err(&pdev->dev, "missing apmixedsys node\n"); - return -ENODEV; + ret = -ENODEV; + goto out_unmap_auxadc; } apmixed_base = of_iomap(apmixedsys, 0); @@ -1245,25 +1247,26 @@ static int mtk_thermal_probe(struct platform_device *pdev) if (apmixed_phys_base == OF_BAD_ADDR) { dev_err(&pdev->dev, "Can't get auxadc phys address\n"); - return -EINVAL; + ret = -EINVAL; + goto out_unmap_apmixed; } ret = device_reset_optional(&pdev->dev); if (ret) - return ret; + goto out_unmap_apmixed; mt->clk_auxadc = devm_clk_get_enabled(&pdev->dev, "auxadc"); if (IS_ERR(mt->clk_auxadc)) { ret = PTR_ERR(mt->clk_auxadc); dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret); - return ret; + goto out_unmap_apmixed; } mt->clk_peri_therm = devm_clk_get_enabled(&pdev->dev, "therm"); if (IS_ERR(mt->clk_peri_therm)) { ret = PTR_ERR(mt->clk_peri_therm); dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret); - return ret; + goto out_unmap_apmixed; } mtk_thermal_turn_on_buffer(mt, apmixed_base); @@ -1287,14 +1290,23 @@ static int mtk_thermal_probe(struct platform_device *pdev) tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt, &mtk_thermal_ops); - if (IS_ERR(tzdev)) - return PTR_ERR(tzdev); + if (IS_ERR(tzdev)) { + ret = PTR_ERR(tzdev); + goto out_unmap_apmixed; + } ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, tzdev); - if (ret) + if (ret) { dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs"); + ret = 0; + } - return 0; +out_unmap_apmixed: + iounmap(apmixed_base); +out_unmap_auxadc: + iounmap(auxadc_base); + + return ret; } static struct platform_driver mtk_thermal_driver = {