From patchwork Wed Oct 19 08:30:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp283022wrs; Wed, 19 Oct 2022 05:04:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM748Txz/a44zx5FqldRD8JwSyZWKVlx2N0HHfmyqHs+A+Gl6CHEIizyoMZFnVRBMrPox9ab X-Received: by 2002:a05:6a00:1ca4:b0:562:daf9:6162 with SMTP id y36-20020a056a001ca400b00562daf96162mr8068443pfw.40.1666181038254; Wed, 19 Oct 2022 05:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666181038; cv=none; d=google.com; s=arc-20160816; b=G8DJTkb0Qaebo2GTfa3sGS2qqIP6gKQUv5vU3fXgH9LlvIwCzWQeJdhOp8SrQlmItL tqbH9d9w8jvUUvQvIHJAJ5ItctiFvRYHYuLRZPG+4jC6CEEq71nrsSqluMTPyKaWf+Un TgUSacqg0QeXYxB2Ji4mwmCHoVkRqWKAZWlVebdgK5qh9SQXhqnIPaF1U1MJIJFpC243 5wxGVgPaVvrkdw8YrpYjj2SqSCx2v40gj/EsY3fUiyXRTHob5qoLF7HBNFkAJuZunCzG cJT2BIu0brWrGdj1ioUndRz6+pTvHqa516RkDw+r7Eq9bH3w/+Mm9rgC5jTtZC8fSAt2 OblA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8/JIv6DE5lYz6XAI0b/D+D+cV6LTgDdb9jONJlX6t3I=; b=n/9EgCScCTkI0DyZBhFDLPpZorSFU60am0TRtnSk9jtNpz/zk6d6sPS29mvRq8rJ28 0vhYNNYO6j3qzxwOPNwAaqHcNg7jJ2XpWVUB2qIiU2iTF5VizBuEElUA+s4HT2DvfOmo w/UC8d2kfsu7ZGUeixqyWDx0n6goG/UzqNYMalsTiuyeLGCEmpiit6ucV1wmWsrFre4j rNenRVT4nQSWDkmqvE+9jK8PJ8A9yzYIO6bpHWZFXbKkq/Ccj0d0o53MiFaXmjxdSv5w oD1AQERT3n0XLxJPnC2IELtDkEDnDobQ6y9GzTOICvBfgQ0MoiffTf9VJkLWKQpgtVp8 PmRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uT6etYBr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a056a00174700b005660f2c4b27si19126815pfc.274.2022.10.19.05.03.44; Wed, 19 Oct 2022 05:03:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uT6etYBr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232001AbiJSLzb (ORCPT + 99 others); Wed, 19 Oct 2022 07:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbiJSLyy (ORCPT ); Wed, 19 Oct 2022 07:54:54 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C0CDF0E; Wed, 19 Oct 2022 04:33:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 031D7CE2158; Wed, 19 Oct 2022 09:03:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E88C0C433D6; Wed, 19 Oct 2022 09:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170188; bh=yKJziEW283XpJTXlC22Huxwlr5z6BXBtoJ1k6n5TaWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uT6etYBrfhUkdmLd3ReGPcAFzwVHg1E38D3udNuf6kngqkN3E6QdK7hc32yIN6j0r leQaVIpfSS9175ErM0h2tEfoBSDaD0SktC0wX2FxvTUJPZWSrVJfNgrgRupS9C434o 9TCi2DJNJ3efaOgOSfbX2bvaO4dHbSrXpAW0lCzI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold , Vinod Koul , Sasha Levin Subject: [PATCH 6.0 524/862] phy: qcom-qmp-pcie: fix memleak on probe deferral Date: Wed, 19 Oct 2022 10:30:11 +0200 Message-Id: <20221019083313.126741569@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747117448244771473?= X-GMAIL-MSGID: =?utf-8?q?1747117448244771473?= From: Johan Hovold [ Upstream commit 4be26f695ffa458b065b7942dbff9393bf0836ea ] Switch to using the device-managed of_iomap helper to avoid leaking memory on probe deferral and driver unbind. Note that this helper checks for already reserved regions and may fail if there are multiple devices claiming the same memory. Fixes: e78f3d15e115 ("phy: qcom-qmp: new qmp phy driver for qcom-chipsets") Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20220916102340.11520-3-johan+linaro@kernel.org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/phy/qualcomm/phy-qcom-qmp-pcie.c | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c b/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c index 0e0f2482827a..819bcd975ba4 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c @@ -2329,17 +2329,17 @@ int qcom_qmp_phy_pcie_create(struct device *dev, struct device_node *np, int id, * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5 * For single lane PHYs: pcs_misc (optional) -> 3. */ - qphy->tx = of_iomap(np, 0); - if (!qphy->tx) - return -ENOMEM; + qphy->tx = devm_of_iomap(dev, np, 0, NULL); + if (IS_ERR(qphy->tx)) + return PTR_ERR(qphy->tx); - qphy->rx = of_iomap(np, 1); - if (!qphy->rx) - return -ENOMEM; + qphy->rx = devm_of_iomap(dev, np, 1, NULL); + if (IS_ERR(qphy->rx)) + return PTR_ERR(qphy->rx); - qphy->pcs = of_iomap(np, 2); - if (!qphy->pcs) - return -ENOMEM; + qphy->pcs = devm_of_iomap(dev, np, 2, NULL); + if (IS_ERR(qphy->pcs)) + return PTR_ERR(qphy->pcs); /* * If this is a dual-lane PHY, then there should be registers for the @@ -2348,9 +2348,9 @@ int qcom_qmp_phy_pcie_create(struct device *dev, struct device_node *np, int id, * offset from the first lane. */ if (cfg->is_dual_lane_phy) { - qphy->tx2 = of_iomap(np, 3); - qphy->rx2 = of_iomap(np, 4); - if (!qphy->tx2 || !qphy->rx2) { + qphy->tx2 = devm_of_iomap(dev, np, 3, NULL); + qphy->rx2 = devm_of_iomap(dev, np, 4, NULL); + if (IS_ERR(qphy->tx2) || IS_ERR(qphy->rx2)) { dev_warn(dev, "Underspecified device tree, falling back to legacy register regions\n"); @@ -2360,20 +2360,20 @@ int qcom_qmp_phy_pcie_create(struct device *dev, struct device_node *np, int id, qphy->rx2 = qphy->rx + QMP_PHY_LEGACY_LANE_STRIDE; } else { - qphy->pcs_misc = of_iomap(np, 5); + qphy->pcs_misc = devm_of_iomap(dev, np, 5, NULL); } } else { - qphy->pcs_misc = of_iomap(np, 3); + qphy->pcs_misc = devm_of_iomap(dev, np, 3, NULL); } - if (!qphy->pcs_misc && + if (IS_ERR(qphy->pcs_misc) && of_device_is_compatible(dev->of_node, "qcom,ipq6018-qmp-pcie-phy")) qphy->pcs_misc = qphy->pcs + 0x400; - if (!qphy->pcs_misc) { + if (IS_ERR(qphy->pcs_misc)) { if (cfg->pcs_misc_tbl || cfg->pcs_misc_tbl_sec) - return -EINVAL; + return PTR_ERR(qphy->pcs_misc); } snprintf(prop_name, sizeof(prop_name), "pipe%d", id);