Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1493794rwb; Fri, 13 Jan 2023 13:08:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXsT/CUAGnf6FiEPJgMBue7gLCiSGiAqXUTXHPGpWB+qWtQIBb9Q8esllJIF4ACcN4jEp4V3 X-Received: by 2002:a17:90a:8d0d:b0:226:e0da:fcc2 with SMTP id c13-20020a17090a8d0d00b00226e0dafcc2mr26814969pjo.47.1673644097918; Fri, 13 Jan 2023 13:08:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673644097; cv=none; d=google.com; s=arc-20160816; b=eVxSMEL/ItBws5anFRWkSdAZEAnVH8ew0AmN6rJ0BwQWzzEJklG/8sKsRRujPKpChf +kY5hOdVHAWN2u5n+nuvr35hzmABVIlLJFRn+TCFywgluZuVTYV+ulGRxBhYs96ATI3d mp99P3IXg28ztDx59KvCZF2DeXcDWNMCVfxj4cTqM3JsP8R0DYkd72fO7sqJY4sr0sAM 1GZ4x7Wu3A/t2BCtZ40d5aEFMxUduY0X/j5sXPvtaho8kMQR7UxjYHqF8uxlZFjY4eO4 ZC/ur61mMhg2TpBhDasQdlI8D00SwaUJKjoBr6Uw+GQRXIdqUYSjheSyKxSrU0LkweaD KzEw== 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=3EKfzPUpjx2o77cFgSD1szOPFx9p7F1YloFu6dux5jE=; b=xGqtVU0I1/dz1G6pnXKB80D/aNBEEP51dnTfLTk0K58tMbXbK598pRXKVfMO/Uy0rr t7JwEnSg/T4BgPmG/ngRE1/gvzkIhxRPazRX0QkXWKsjoiY+VCRCEczKwe7YYVw8QtGk 4XP/7+IA/4YDVgPWr1eWt2NjTi2v8KdB6OFmrva1RmJwJrt3OrUx80fPiTgpveyynvJw rWIgeAQIpo8zibR1XkdbM5mF9KQ6a0+lo79LnBSTIx/2Lrq3aDzBM4plk3uZyn0pF2/a +uY6lXjYVim9TcjRUdxr2X8ObRrEitA9IheTCIOGZI8UnPT4b9OMPxindgxHLbH1HkKe iBGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=c5MePPcQ; 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 a11-20020a17090a480b00b00200435da17asi4040414pjh.128.2023.01.13.13.08.11; Fri, 13 Jan 2023 13:08:17 -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=c5MePPcQ; 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 S231272AbjAMUqG (ORCPT + 54 others); Fri, 13 Jan 2023 15:46:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231201AbjAMUp4 (ORCPT ); Fri, 13 Jan 2023 15:45:56 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36803B7E2 for ; Fri, 13 Jan 2023 12:45:55 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id o7-20020a17090a0a0700b00226c9b82c3aso25545540pjo.3 for ; Fri, 13 Jan 2023 12:45:55 -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=3EKfzPUpjx2o77cFgSD1szOPFx9p7F1YloFu6dux5jE=; b=c5MePPcQOxolySSTkYSFqcPzoRQgD2LAbFsfAgCFEXRR5kITKtrkGnUohoWrokrKUT CdCF4317T73BZ7ZBB2dZrNcFuCEAxsQCZiuyKT3961Ixuk2FDLmSVE22o4HrSsoB+h37 srCCiUIppMFQOc6qmDfbRqbAeNTu5AdXBK/JI= 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=3EKfzPUpjx2o77cFgSD1szOPFx9p7F1YloFu6dux5jE=; b=Rr85pON6fTWpLOcvnuQipqaEnZcw3ajoPfZC9vo52un3Mp+qkLubOTGf5B7tmGp8On NT9cBZZTxpGfVqxIOqN4OAVUeMuKToCpyEJctqmIwtGq1e5s0rcuxw76BBd5x4v3+2lN sowGEAFMn6S81phKwZ+8Xn8hSuv8TppZhUuL3ijdNcTWxnVbj+/N3ivZcL930rVQAJFa HuQ19kofPeTu8Nc7NjLJ44Ezxs6Lfg0Z509gHPFV/j0iV6C/ueCU4A7lpFD19aINr4ny eQiRSKMDBTY7Z//HRUEbYNHEIaY66Omxc/8HMrqh7SPuxPDiyQ5+PJWCYLCOUsmQXMeo ernw== X-Gm-Message-State: AFqh2kqn927jUQN8wrItTLdks9YgwJhSgYkmMGf0MSrY+OFY1JNm0PvW IBo4t9ccwCBAXVVLGstzFISRww== X-Received: by 2002:a17:902:bf01:b0:189:c47b:af27 with SMTP id bi1-20020a170902bf0100b00189c47baf27mr77998697plb.10.1673642754855; Fri, 13 Jan 2023 12:45:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 12:45:54 -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 2/5] phy: qcom-qmp-combo: fix memleak on probe deferral Date: Fri, 13 Jan 2023 12:45:45 -0800 Message-Id: <20230113204548.578798-3-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 2de8a325b1084330ae500380cc27edc39f488c30 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. 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: Stephen Boyd --- drivers/phy/qualcomm/phy-qcom-qmp.c | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c index 7b7557c35af6..c6f860ce3d99 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -5410,17 +5410,17 @@ int qcom_qmp_phy_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 this is a dual-lane PHY, then there should be registers for the @@ -5429,9 +5429,9 @@ int qcom_qmp_phy_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"); @@ -5441,15 +5441,17 @@ int qcom_qmp_phy_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 -- https://chromeos.dev