Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6408CBA3B for ; Fri, 13 Jan 2023 20:45:55 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id b17so17098330pld.7 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=emkwD81ChcnDPkIc2BXQhgae980v97KH6MXcLIQd1Z4dVLf/VlYKP0cLLr6ZmlXqWi RJtvKPxqVtDIFLaEh9KoKY2y+VDm10JWzgZaBHmcKzAhuCVhp2dKf7S/3MFlEtCUqkr7 g8nFM5lOKoqIEL5C7lNARyyjnEkEVt2bWr1pd7MtyZwffcrVzz8dSvO1cfrHc4OW14k2 aKrZeeFJH1ZkPWUHpzJX7UiIavZWC2bL0gpwQTcgUBHlb1x2nB9jMGISNU7n/R4EzXRe kyTRk3nSu1grE/U9Wo5QIUBQ6b1/rl/TdizdyRGMjKnQxTU9y+8aKwA6FlaR8mNsddTJ s/yA== X-Gm-Message-State: AFqh2kp/DFw4nx3zpYyEcpsR9RtMcN38X5QroOXwcEgv386QOm3xHFDj M6yKHaFJcm4IuQDhmbJsDtta4g== X-Google-Smtp-Source: AMrXdXuE9cOXm90YkFyK4/RVNwZqACeHvqf8UZLKFFGHDWZFnI801i6GdNVrYPO0HSgS8Bdu/QiDcg== 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> Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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