Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1019004rwi; Wed, 19 Oct 2022 05:55:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ppg2HKSwpYUbWFGCk45fn9DWGXFM2oJfNkk3rXnApRyZfDdSiDxtKnJWOQ9AntrmiqH37 X-Received: by 2002:a17:906:fe45:b0:791:9624:9e9f with SMTP id wz5-20020a170906fe4500b0079196249e9fmr6642421ejb.86.1666184102783; Wed, 19 Oct 2022 05:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666184102; cv=none; d=google.com; s=arc-20160816; b=yzTQGwUW0bDLuM5fjyh21ygLkeFdShr4OooGZv8vQz9wv0p1DEPOBtt5OpPJQt4DAK evPOG99CK1afW19F8iJJJy1RDxRzucP7fA2nxUgCwUPiTmJyOdC7tdIMCjHVmXUfAVB+ PPHqg40vB56Xrvr7EaqtG9EQQxFebFTuZnzImG4p/fJeql5SVTskijFKz9cXOwWHA8+D yvqLJBvV2Pas5wCN51DqkFxnYdrqK0damPyj2TB57CsFrMg0HoHvMteX5RWzF1E6Tp+V 634dVeZ7njvKuJNJzDskir7fNXMoGQhQY6w6k2615hKyCnbqRgEoxl8BDR4g9Yjaq+IS hjPA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a05640250c900b00458bc949b45si16762546edb.488.2022.10.19.05.54.36; Wed, 19 Oct 2022 05:55:02 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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); -- 2.35.1