From patchwork Wed Oct 19 08:30:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp223780wrs; Wed, 19 Oct 2022 02:38:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6xs6EUqz+fURWjDq2CyF6QF/AIkKA2WFmQRCamBM9SUdXBmgM7MheOkpRAO8RhMXPGM6+6 X-Received: by 2002:a17:902:a707:b0:178:bd1e:e8be with SMTP id w7-20020a170902a70700b00178bd1ee8bemr7466388plq.167.1666172307876; Wed, 19 Oct 2022 02:38:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172307; cv=none; d=google.com; s=arc-20160816; b=LvrpQf7FGyLooX4u+TqBmaNVOApybED9ilf1nsiVoyEC2yGXA8PmjF6hIgzl8PCek0 u5fteqLB9qaMqKRyyQV5S08NssmzES/xDydQkx7qPy81D1JpaqUu3IWZi1X+w+DoIfYA oiBVKcTgh26ooou2Y2Jmp95eNVKdXM3Ap75r7PcMoTXBshaHQ3Z078PgjiL9MqAIicNG khmkbi8ty2LnL/FADSh9Xv9T2GQZmzFKaGC3zFSnlmBWfZtgm4CT5NqggKdUePYjJ8H4 4pBuZnuRBZCxttm8BBSVJ/225Q1U+2P1D2cbP0Gt7XFgl+rlpyStanuTxAk6eVIb0+hF QQGw== 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=TDcLYGcGAZCv5z2b3pIG9y886fk70+uka9vclmDwfkM=; b=JHtNAAEUjRh0Jsk818o/0FkMvSLmM2ZGHpBhkSTmSD1iuQYfEBbFOZIHWpWK+aKfu4 oGZmhaeaHM/DVVd5CQqP2lFRfTX2+UYVVvFgUl+tPRxVWuIrS3iDPWSmY9i1crhyOKzx 2XAu3GVIHoZb8CoqdEpjlmuK9/Aro7MRlGR9LQocolME3pRlj6fhEbmRCBPRpcQXvQvH jfuwxP+LZCtVtrr6zyT66376Ra5YkXyAE5m4+SrBM7kC26YkLS90q2LSRKWVvjkMjeym mWczIbZEsvBPOnO/OQfa9ap5hLIb9BP3EQXAeCvE+V+4N+3Ow7PYPpJ3AhvJPmFNLdGM rJsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0TIR2ShH; 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 d19-20020a170902e15300b00179e261e4f8si15375391pla.90.2022.10.19.02.38.14; Wed, 19 Oct 2022 02:38:27 -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=0TIR2ShH; 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 S233268AbiJSJUX (ORCPT + 99 others); Wed, 19 Oct 2022 05:20:23 -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 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?1747108293758295889?= X-GMAIL-MSGID: =?utf-8?q?1747108293758295889?= 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 = THIS_MODULE, }; +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, int 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 = 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; @@ -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 = of_iomap(np, 0); - if (!qphy->tx) - return -ENOMEM; - - qphy->rx = of_iomap(np, 1); - if (!qphy->rx) - return -ENOMEM; - - qphy->pcs = of_iomap(np, 2); - if (!qphy->pcs) - return -ENOMEM; + qphy->tx = devm_of_iomap(dev, np, 0, NULL); + if (IS_ERR(qphy->tx)) + return PTR_ERR(qphy->tx); + + qphy->rx = devm_of_iomap(dev, np, 1, NULL); + if (IS_ERR(qphy->rx)) + return PTR_ERR(qphy->rx); + + qphy->pcs = qmp_usb_iomap(dev, np, 2, exclusive); + if (IS_ERR(qphy->pcs)) + return PTR_ERR(qphy->pcs); if (cfg->pcs_usb_offset) qphy->pcs_usb = 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 = 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"); @@ -2545,15 +2570,17 @@ int qcom_qmp_phy_usb_create(struct devic 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)) { dev_vdbg(dev, "PHY pcs_misc-reg not used\n"); + qphy->pcs_misc = NULL; + } snprintf(prop_name, sizeof(prop_name), "pipe%d", id); qphy->pipe_clk = devm_get_clk_from_child(dev, np, prop_name);