Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp184843rwb; Thu, 12 Jan 2023 18:06:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXtqYdgGbrGXmDlVg4DkaAdjdx9vMDxPP5FS/g4pGTTC72naJdymj7j/1EK56dcSbkC/ikVl X-Received: by 2002:a05:6a20:4f12:b0:af:89c2:ad02 with SMTP id gi18-20020a056a204f1200b000af89c2ad02mr9207460pzb.22.1673575598176; Thu, 12 Jan 2023 18:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673575598; cv=none; d=google.com; s=arc-20160816; b=uJASG9+KGfCGCL83bx6ceehNRhnERsYtRNh3PiTZ78JfLbIFbxBPl4j+1WBDcxPet7 6YAfM9AM25O9BBeYtAj7+dI6Y1vnnIai7SKWlDG753fjtKDK5py+AfT1+8sEWelgySP+ KZHE7gh/rN3v75v7oN/kcnG0ovTbKnBFeN82Rrgf4ZcAP5TTYt49HUUKIG02GfTvaNyx xJzSv7yCDOOvAI4Rd9luDbqTBUdkOrBap/p5ZQBZJw+kkUueybsGIX44692QUggBeNOc NsQTvbl6x2tuXXn5YwwDlPMuqK5DGMFEhAxHSGuUtAgM6h2F88/iCux3xqRiaTRmgoct +AMQ== 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=N2wcLjsTcjdbm+VH5n74TxdGjIeMuYPhTeae7C7VjKmP8iMh8Mo74EWxs619Pd77al KLU/DGJ3fR3yA8Q64VrOB2KAiyHgovEEbhusEqf0+FeLyu/E5URntNg9rlxhVp09CuOz fFOF6eIdCwEx4HzjjES0z8zidJUhhZwrJnTUxG8imNXnZd7riSxnZWfoJ38FvtNrOylp vtXaqggaf5r+mv1m9tI+wxpdPxedXBZruZbJ0/obu04SB4VnDPgZy0wmuo2UgqZXScum k30akpZYKM9WELxY0yZCptZcgnxDRrwz6c2X90hRhlrslLdsy+hbdzsVGEHO8negwR/B jmug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=E1FYs3gi; 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 m69-20020a633f48000000b00477931a9ba7si19913125pga.279.2023.01.12.18.06.31; Thu, 12 Jan 2023 18:06:38 -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=E1FYs3gi; 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 S239969AbjAMAyi (ORCPT + 50 others); Thu, 12 Jan 2023 19:54:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239204AbjAMAyM (ORCPT ); Thu, 12 Jan 2023 19:54:12 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DBE613D25 for ; Thu, 12 Jan 2023 16:54:11 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id jl4so21898725plb.8 for ; Thu, 12 Jan 2023 16:54:11 -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=E1FYs3giqJVQqe4m9EiI/42Aeraq7nSFJAh76CzhEmZ8N3OiAbqSjVPL+sEjUMnKj7 kfRLIW03elctYlzBsoKaFi5rtWxbg/aGGqPhU0L0BX3xAi4wkRbe+NWyKw8aBSfOIOwm +zboYH6FFwuvhu5msLAZcc8u82gIq4GamG8/0= 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=pG8cGIzOQ74IrLgNT6M0r1swHy8WFInyfHfaw7DbS5qR00ehtVs57C9QrgNx/KkEhQ UttzIfmdSTF5S1EmpyFbkObewxSgqVgJdYFI66mQ5vD42v5ZEz0VLmLA2HFT3Qgdfjo3 LdXHWcGrTbxTUbAVmPDKluFZAdcMQ3xygp734QdgneIGJfloGBjRO5moaQhiE+DTU6Ik DLGia7BdRYAcIv4UW0McitQ7h7cXSNd9l53Yt4qTNXOxGg7SHo1GanXAgT3AvVa1pdt3 zjsi8ZR+mAiyx8CLwnCJcvZsd72IH6j570ZN/wNPXPsfaLVU66kE90aXE6T7GXAM2umN Fhvg== X-Gm-Message-State: AFqh2koF4wyztu+pWNO0Mz7h5qETSXcKiWnmGvLzDNufnuhPnm/fbfcq Tm2//D1IbpcsTC/fWSVlnOSeWkERlhFUr+Kd X-Received: by 2002:a05:6a20:6724:b0:b6:55e:caa0 with SMTP id q36-20020a056a20672400b000b6055ecaa0mr9167697pzh.17.1673571250950; Thu, 12 Jan 2023 16:54:10 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:11a:201:4652:3752:b9b7:29f9]) by smtp.gmail.com with ESMTPSA id u11-20020a6540cb000000b0046ff3634a78sm10676614pgp.71.2023.01.12.16.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 16:54:10 -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 2/4] phy: qcom-qmp-combo: fix memleak on probe deferral Date: Thu, 12 Jan 2023 16:54:03 -0800 Message-Id: <20230113005405.3992011-3-swboyd@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230113005405.3992011-1-swboyd@chromium.org> References: <20230113005405.3992011-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