From patchwork Wed Oct 19 08:30:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp216303wrs; Wed, 19 Oct 2022 02:18:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UyHKtY4mxrELncUy6naBbIAvD1XbLeYsRr8SdQBz4OSqL8voyKclfX0fBXuDZrwdoSToD X-Received: by 2002:a05:6402:5211:b0:45d:131b:8dd7 with SMTP id s17-20020a056402521100b0045d131b8dd7mr6542631edd.93.1666171084823; Wed, 19 Oct 2022 02:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666171084; cv=none; d=google.com; s=arc-20160816; b=CSIR6cUT43mcvRPmXwIQh+5oshAGkpn4Ya8OA4H6MimqSaZ7k5XUVi59BL0PvbrUfA jPyszZuxZS6WK4kpgdAR+HfoWXS7Q4G1R3Lo1Mo6RjVBEpnaLsxle8H+nJMpkq0K4ckp S00hmDyoTP/hTU9p+6qGP8Srg9Uc6I8v2s0BAt8odNjtu1bTxDwzSgswdIY7DT3Xcpux X52gKOKuNXXAQgTTSEerMjrpEra+h+BriUAncicV2KbPoqigz5V98HJ+s748hgw8fLUT zRQ3upceoTbBk9KeNFP2zEwE7cXbyyMYQUCBEFjQ4MkSiysHavQ/9W82xh3IJUDWvWEB LtBg== 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=O5Z5JqyGf1w2ISBZrEbDT+6vU84vLgZGOCsdFhhYYSg=; b=LYfQ6CqWc57gG9G4G5vbD1DhpVGYHyfaPxwtdTXuVJRvT1jTnqEV0fam8uie55kGBD FcKpBh6d4QpG9IgXKDhH+oA7L1nTzRuw/E6T6FIxAdPVwIL32iy8zdILgKh6Gw6HJYj4 O5XjT+la59cefmbWe3xCfwg069HpIdKZYsWLHEGcIqbtl4cT+s19NuOv+GUP38ipnqsY QTx3uP9YIuUfqs09+Z9EkuyIbqGCV6yKo2vUC63wnnDfOSCODPt4QQCfVyeAAdWezY7x vEjlDM1aiD0DbAHFwF/L2dRZDBTibpqLCbOX7Vibj45cml2j4cBZ4CsSic2v+LvDz2EX e3CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="v/KIgXYx"; 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 js10-20020a17090797ca00b0078e20d9c473si9767965ejc.764.2022.10.19.02.17.40; Wed, 19 Oct 2022 02:18:04 -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="v/KIgXYx"; 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 S232757AbiJSJQf (ORCPT + 99 others); Wed, 19 Oct 2022 05:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233103AbiJSJN7 (ORCPT ); Wed, 19 Oct 2022 05:13:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09367CF185; Wed, 19 Oct 2022 02:03:51 -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 705F46181B; Wed, 19 Oct 2022 09:03:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82E2EC433D6; Wed, 19 Oct 2022 09:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170193; bh=cciPacl9eT/Q43v963/166drUbkyCCfGboVieuGeFvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v/KIgXYxzYWLQfL4y91kDI/OroeY9ugZd02ZZLSLKlo+dWZdT+PuU4+meHX41Qk/W qSTVHTE8ZzSBd3AuHhGhv4f0P3DbEilwnYFhqC66C+DWhE/qmYHm1pT6fvB1sKOPDb bJOb0+0JA/gkI/xk89xIl2KFAtK2Y3sr4FZQnoNk= 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 526/862] phy: qcom-qmp-combo: fix memleak on probe deferral Date: Wed, 19 Oct 2022 10:30:13 +0200 Message-Id: <20221019083313.221255789@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?1747107011571977820?= X-GMAIL-MSGID: =?utf-8?q?1747107011571977820?= From: Johan Hovold [ Upstream commit 2de8a325b1084330ae500380cc27edc39f488c30 ] 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-5-johan+linaro@kernel.org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c index bbdca263058c..f089977c85bb 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c @@ -2350,17 +2350,17 @@ int qcom_qmp_phy_combo_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 (cfg->pcs_usb_offset) qphy->pcs_usb = qphy->pcs + cfg->pcs_usb_offset; @@ -2372,9 +2372,9 @@ int qcom_qmp_phy_combo_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"); @@ -2384,15 +2384,17 @@ int qcom_qmp_phy_combo_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)) { dev_vdbg(dev, "PHY pcs_misc-reg not used\n"); + qphy->pcs_misc = NULL; + } /* * Get PHY's Pipe clock, if any. USB3 and PCIe are PIPE3