From nobody Sat Oct 18 02:26:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 908C6C4332F for ; Wed, 19 Oct 2022 09:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233271AbiJSJUZ (ORCPT ); Wed, 19 Oct 2022 05:20:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233396AbiJSJTJ (ORCPT ); Wed, 19 Oct 2022 05:19:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6103289CC6; Wed, 19 Oct 2022 02:08:06 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9F7C26174B; Wed, 19 Oct 2022 09:03:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B43EFC433D7; Wed, 19 Oct 2022 09:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170199; bh=jqy8C+Kc3rOan3G2Kng9jfcs+w4MNPapy2AHnhT+17U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0TIR2ShH4eB2MRY7LKAQ/SJiEYSCBVw3TVBiyEtVbsaUDCMGe2DEhU5z7c4wOpXF7 NB0FCm9Cw4/HJcsu3FokC48KEhpK+w7YzNUxWt6XHQXotyXT4Ihy+rGDsX68x3aE3b 0RTpY694rQAxuZb23yhN2oF+ybH0f+fanY+pVZNA= 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 528/862] phy: qcom-qmp-usb: fix memleak on probe deferral Date: Wed, 19 Oct 2022 10:30:15 +0200 Message-Id: <20221019083313.304749902@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-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Johan Hovold [ Upstream commit a5d6b1ac56cbd6b5850a3a54e35f1cb71e8e8cdd ] 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. Two bindings currently rely on overlapping mappings for the PCS region so fallback to non-exclusive mappings for those for now. 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-7-johan+linaro@kernel.= org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/phy/qualcomm/phy-qcom-qmp-usb.c | 61 +++++++++++++++++++++++----= ----- 1 file changed, 44 insertions(+), 17 deletions(-) --- a/drivers/phy/qualcomm/phy-qcom-qmp-usb.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-usb.c @@ -2489,6 +2489,21 @@ static const struct phy_ops qcom_qmp_phy .owner =3D THIS_MODULE, }; =20 +static void __iomem *qmp_usb_iomap(struct device *dev, struct device_node = *np, + int index, bool exclusive) +{ + struct resource res; + + if (!exclusive) { + if (of_address_to_resource(np, index, &res)) + return IOMEM_ERR_PTR(-EINVAL); + + return devm_ioremap(dev, res.start, resource_size(&res)); + } + + return devm_of_iomap(dev, np, index, NULL); +} + static int qcom_qmp_phy_usb_create(struct device *dev, struct device_node *np, in= t id, void __iomem *serdes, const struct qmp_phy_cfg *cfg) @@ -2497,8 +2512,18 @@ int qcom_qmp_phy_usb_create(struct devic struct phy *generic_phy; struct qmp_phy *qphy; char prop_name[MAX_PROP_NAME]; + bool exclusive =3D true; int ret; =20 + /* + * FIXME: These bindings should be fixed to not rely on overlapping + * mappings for PCS. + */ + if (of_device_is_compatible(dev->of_node, "qcom,sdx65-qmp-usb3-uni-phy")) + exclusive =3D false; + if (of_device_is_compatible(dev->of_node, "qcom,sm8350-qmp-usb3-uni-phy")) + exclusive =3D false; + qphy =3D devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL); if (!qphy) return -ENOMEM; @@ -2511,17 +2536,17 @@ int qcom_qmp_phy_usb_create(struct devic * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5 * For single lane PHYs: pcs_misc (optional) -> 3. */ - qphy->tx =3D of_iomap(np, 0); - if (!qphy->tx) - return -ENOMEM; - - qphy->rx =3D of_iomap(np, 1); - if (!qphy->rx) - return -ENOMEM; - - qphy->pcs =3D of_iomap(np, 2); - if (!qphy->pcs) - return -ENOMEM; + qphy->tx =3D devm_of_iomap(dev, np, 0, NULL); + if (IS_ERR(qphy->tx)) + return PTR_ERR(qphy->tx); + + qphy->rx =3D devm_of_iomap(dev, np, 1, NULL); + if (IS_ERR(qphy->rx)) + return PTR_ERR(qphy->rx); + + qphy->pcs =3D qmp_usb_iomap(dev, np, 2, exclusive); + if (IS_ERR(qphy->pcs)) + return PTR_ERR(qphy->pcs); =20 if (cfg->pcs_usb_offset) qphy->pcs_usb =3D qphy->pcs + cfg->pcs_usb_offset; @@ -2533,9 +2558,9 @@ int qcom_qmp_phy_usb_create(struct devic * offset from the first lane. */ if (cfg->is_dual_lane_phy) { - qphy->tx2 =3D of_iomap(np, 3); - qphy->rx2 =3D of_iomap(np, 4); - if (!qphy->tx2 || !qphy->rx2) { + qphy->tx2 =3D devm_of_iomap(dev, np, 3, NULL); + qphy->rx2 =3D 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"); =20 @@ -2545,15 +2570,17 @@ int qcom_qmp_phy_usb_create(struct devic qphy->rx2 =3D qphy->rx + QMP_PHY_LEGACY_LANE_STRIDE; =20 } else { - qphy->pcs_misc =3D of_iomap(np, 5); + qphy->pcs_misc =3D devm_of_iomap(dev, np, 5, NULL); } =20 } else { - qphy->pcs_misc =3D of_iomap(np, 3); + qphy->pcs_misc =3D devm_of_iomap(dev, np, 3, NULL); } =20 - if (!qphy->pcs_misc) + if (IS_ERR(qphy->pcs_misc)) { dev_vdbg(dev, "PHY pcs_misc-reg not used\n"); + qphy->pcs_misc =3D NULL; + } =20 snprintf(prop_name, sizeof(prop_name), "pipe%d", id); qphy->pipe_clk =3D devm_get_clk_from_child(dev, np, prop_name);