From nobody Mon Sep 15 07:33:20 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 23A34C6379F for ; Fri, 13 Jan 2023 20:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbjAMUqN (ORCPT ); Fri, 13 Jan 2023 15:46:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230439AbjAMUp5 (ORCPT ); Fri, 13 Jan 2023 15:45:57 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ECE0B7E2 for ; Fri, 13 Jan 2023 12:45:57 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id v23so23548450pju.3 for ; Fri, 13 Jan 2023 12:45:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/wf/jRQXTrwopLou3zIfVtkgVUx/udC4D9rZCEjw0W4=; b=kPo2syja8pG1+b5fwu1HFrYc0YBxgk1lwktiuerWs0WfGaXdeLnjXrILaXommkZmiN TNBvxVRka/G4k3yCvinez3F8Bzk4brPFy8QhoNbLVetuVfBrlSlnYa0C3aXzmsvfwa5V Ysjwnxm0/E6NRaQCLqdmbPkkFx3cDNhZQSeZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/wf/jRQXTrwopLou3zIfVtkgVUx/udC4D9rZCEjw0W4=; b=k3sZf3Phj+uc/ZN6t/6sRVr2FN9EX1soQf3NUlxccJfxURB4zn/Dz+jiPykkyVgwbR eVAjVVuJpwE6ZP0h6AC3ET8q3tX6y0t3xLUAvDHtXkCzN9aLCJ8KuD51EdmYVo5eF+Az TS0I9y0vy8B1wwMIJaJh/QISpFpgUqUztEkzuR8FT2cSBrTmBAEHjjujX0zHGgO+i6S2 ulywUddDLZmMzgw28iZ/wiR66RCTNYJm3CvZiyvJK/+8yajfJZ7hlMrc2msgMnIKFuzn U/qP7D9EtZEvM3DPKN334TDsPqRr5u0gX6Z/b57dsKtZXUqK0iKsYha5dKoHa7cy1fZa MHHg== X-Gm-Message-State: AFqh2kpl5VWmBQ8n5dK3urEAOM8+7hQNTssUT0BbCY86dhcyXor08qhy LpMbtwgpnWGt3mqPGBGd0og0fQPS1h3VaaQx X-Google-Smtp-Source: AMrXdXsXdacwL++OIjYQp4TVRlwKJ9pcnP7TMzzFIV+6SC3sDKY6D9lpghENazU7xbdyht7Mn8htWg== X-Received: by 2002:a17:902:854b:b0:192:903c:3726 with SMTP id d11-20020a170902854b00b00192903c3726mr58947252plo.28.1673642756623; Fri, 13 Jan 2023 12:45:56 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:11a:201:4652:3752:b9b7:29f9]) by smtp.gmail.com with ESMTPSA id f21-20020a170902e99500b001945b984341sm4010081plb.100.2023.01.13.12.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 12:45:55 -0800 (PST) From: Stephen Boyd To: stable@vger.kernel.org Cc: Johan Hovold , linux-kernel@vger.kernel.org, patches@lists.linux.dev, Vinod Koul Subject: [PATCH 5.15.y v2 3/5] phy: qcom-qmp-usb: fix memleak on probe deferral Date: Fri, 13 Jan 2023 12:45:46 -0800 Message-Id: <20230113204548.578798-4-swboyd@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230113204548.578798-1-swboyd@chromium.org> References: <20230113204548.578798-1-swboyd@chromium.org> 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 commit a5d6b1ac56cbd6b5850a3a54e35f1cb71e8e8cdd upstream. 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 [swboyd@chromium.org: Backport to pre-split driver] Signed-off-by: Stephen Boyd --- drivers/phy/qualcomm/phy-qcom-qmp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy= -qcom-qmp.c index c6f860ce3d99..ee4fd7afcea2 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -5387,6 +5387,21 @@ static void qcom_qmp_reset_control_put(void *data) reset_control_put(data); } =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_create(struct device *dev, struct device_node *np, int id, void __iomem *serdes, const struct qmp_phy_cfg *cfg) @@ -5396,8 +5411,18 @@ int qcom_qmp_phy_create(struct device *dev, struct d= evice_node *np, int id, struct qmp_phy *qphy; const struct phy_ops *ops; 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; @@ -5418,7 +5443,7 @@ int qcom_qmp_phy_create(struct device *dev, struct de= vice_node *np, int id, if (IS_ERR(qphy->rx)) return PTR_ERR(qphy->rx); =20 - qphy->pcs =3D devm_of_iomap(dev, np, 2, NULL); + qphy->pcs =3D qmp_usb_iomap(dev, np, 2, exclusive); if (IS_ERR(qphy->pcs)) return PTR_ERR(qphy->pcs); =20 --=20 https://chromeos.dev