Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1477526rwb; Fri, 13 Jan 2023 12:54:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXviRK0Wxc4Gl3hYo1xf2PTuuS9IlhTnkRDmHcQtxjVWxjDv0KIBcRjZ/a6li9XqMrMf9otj X-Received: by 2002:a17:906:86cc:b0:869:3b49:35c2 with SMTP id j12-20020a17090686cc00b008693b4935c2mr4236926ejy.61.1673643279179; Fri, 13 Jan 2023 12:54:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673643279; cv=none; d=google.com; s=arc-20160816; b=zmls+kqEsbt6q3Ecv4aW03DCF6WOXi5GjLlLv+mjh8i3jQ13wLr6ZhwUMd93m0zqCf tfr1+73vG6rCzepXoIjjPJAVlWDxXqbpS4YRslQVirR7CE2mOZLcUGK0MSwM6UDlsEK6 m2vI+vTBMw+OhnAkhrRYTf+h0SB7xuqJLqiupLZe+7tfJwOEJmee/vfIseZErzFF/lAk Xa0s8zPmR9+PYT3YCGG7DXtNhSyJ+knoy+jTLbwCVMC8iy5EbCL2DRShxm6Wce5eDGDU Gv7cApaw9Razl/atJxrN+1kMqLu2UXnzFio8j9PGoVy6gmxx+4Rsa8OPXFm8CHWzPtUf h4Rw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/wf/jRQXTrwopLou3zIfVtkgVUx/udC4D9rZCEjw0W4=; b=y5aMicqUCwvhEAkAnMX0Wq75ExDOweu3kXTLvefRlfxpf2SnHAmy/EIpbx+2UkSkQj B02OfCzdVw/qOBwge691Th63blUNCeLcbVER3feUPPvkmhGhnz8/619QwU+d3Pyd2n2c 8tblWh/0gbaHuh+F0yvVHgCFfHg+AkYDaLCFBH423pGQQnPK9FlIr47ENYPDtdZAC5kd xXH36oaHvYm+V/qb/J45ErmyhCoXtj4SDz/iBxHKyA0j0pjfMOM83zeXnwGQ4L7sIjlc FZaW3p/NEb4iHfsgIVQdctSRT1r0L/pXTXK/esVGVIbqs5rjYyvv1nVpZVhL5P1M+NS+ 84FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kPo2syja; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca2-20020a170906a3c200b007c1891ecc5asi14938661ejb.189.2023.01.13.12.54.24; Fri, 13 Jan 2023 12:54:39 -0800 (PST) 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=@chromium.org header.s=google header.b=kPo2syja; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231296AbjAMUqM (ORCPT + 52 others); Fri, 13 Jan 2023 15:46:12 -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-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: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 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); } +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 device_node *np, int id, struct qmp_phy *qphy; const struct phy_ops *ops; char prop_name[MAX_PROP_NAME]; + bool exclusive = true; int ret; + /* + * 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 = false; + if (of_device_is_compatible(dev->of_node, "qcom,sm8350-qmp-usb3-uni-phy")) + exclusive = false; + qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL); if (!qphy) return -ENOMEM; @@ -5418,7 +5443,7 @@ int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id, if (IS_ERR(qphy->rx)) return PTR_ERR(qphy->rx); - qphy->pcs = devm_of_iomap(dev, np, 2, NULL); + qphy->pcs = qmp_usb_iomap(dev, np, 2, exclusive); if (IS_ERR(qphy->pcs)) return PTR_ERR(qphy->pcs); -- https://chromeos.dev