From patchwork Fri Feb 3 22:26:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 52693 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1089098wrn; Fri, 3 Feb 2023 14:32:23 -0800 (PST) X-Google-Smtp-Source: AK7set8YoJ4pO+L/AGkU5HHMPqj0WqoOdwl5tVSMDwUB6te9EocPdl2AGrIZguSMGJCv3z0ebwFK X-Received: by 2002:a17:906:b2c5:b0:88d:2a41:2a4b with SMTP id cf5-20020a170906b2c500b0088d2a412a4bmr10713524ejb.60.1675463543006; Fri, 03 Feb 2023 14:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675463542; cv=none; d=google.com; s=arc-20160816; b=HojQ7ACEv1Er4G+j2SmHPwpKLI9tNq9rNXYGMbSF/TpPooPBGJCAtJ0jeGIgXIB9Rb K9b/STE6zhy3cYnxEjH9Ox8sak10hIv5OM2zNmFDcSxAfSivjyGwr1chkrhhQqX8Zokm Blu/vRnKw+X70yZZiomzwJyCGzsvQVc/ML7Qhg7+7vc1qTIC5c1oCQS0+ufghv06QoUc 5vLq8TVDmqLgRvyzo9BWcA/piaR1vcwTue47cM6Awhmnf0kerQ2ChQmaH6q6fx2EeVjb mFc3cmdc3dV9WUp+ubGyaYAEgDbQ01/lGsB0dK2RSpBSLR0IRuP1zC9lRYGPd8TTIy1o pMIw== 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=/wf/jRQXTrwopLou3zIfVtkgVUx/udC4D9rZCEjw0W4=; b=09+Svc2SboIgDkPZ2X7v9nPpsR44WkOw+LHUcjTXHsQQVds4B2fT0UHHj+RgrJGLd0 eg8cD/QoBYQzItHZoREcavV3RAzzbF/iVrnyzHgNVUJbQjilSJtlMQfzzumKz9gRD4Gn wqYFyLgBMxnpTaXJ9bYO8Gz9udxVVxjADDMtEqYijKEhecgCvxWjtQpUl6IMJ1tDklIW AAgk+CXEbCMYrp+G5Tak1EORcON+MMO93Y5fF8RVF+veqjOac2qCogqwZR7LOm/AZEP6 oQ7SWh+S3Ni/n0cGx/CYEeqnwaM9HsygJz1GHNbmEgtpOs7PwPqv51D2ETo/KOLOuvkL hJ5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=j+2EDjk6; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wc15-20020a170907124f00b00889a7745918si3727080ejb.167.2023.02.03.14.31.58; Fri, 03 Feb 2023 14:32:22 -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=j+2EDjk6; 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 S233373AbjBCW0c (ORCPT + 99 others); Fri, 3 Feb 2023 17:26:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233294AbjBCW0Z (ORCPT ); Fri, 3 Feb 2023 17:26:25 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 364881BACF for ; Fri, 3 Feb 2023 14:26:24 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id mi9so6403550pjb.4 for ; Fri, 03 Feb 2023 14:26:24 -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=/wf/jRQXTrwopLou3zIfVtkgVUx/udC4D9rZCEjw0W4=; b=j+2EDjk6kXsfu96EGsq9W+a4ZlMfTkNoxCSWsme1zPjSw/07v/aPaxFBfKkUeWIlJJ frEK4jPLIUPilY0mgh1v0EfxN4jn3oHDXdXnblPtxTYy5n6BrGtYflOWzjvWvzPmp7MQ 7+NG8U0AC2axMf8ia4UXvb3GdGJuppA6uN4Gc= 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=/wf/jRQXTrwopLou3zIfVtkgVUx/udC4D9rZCEjw0W4=; b=6Ruo9Zx6niDMJZea/4NWJc7F2rh69BubeFnI9NOD5NGm0IrtKspyFb7Hd5X0/dmvQl aiN9ZguovU5eJ1zkRwXvGQz7KHhUMNngbATva16dlLKoHzbErWPhWudCHN6huc6K/l42 bbLHaNpRHyOGB/pIbnfKIPPPP2yh+VEEXQ7sETN+2R6m7ZL3TuT0pl574imgJi7N5dG2 DMziAAsnaHP8E6IUeGx8a0/sEnM2p/RHUAuWryLgGAMcM2Y/XCr4F7adpdFAuHt7I0u5 GHXneY8Edlex7mB1mVbW37xTfVVdhOuK/7HEdi64Rj663PqA7BoyxbA5zjv5hyywL1vo WtRw== X-Gm-Message-State: AO0yUKXg3QThn14SEZD8GAA0cmV8ogdKydiYiDjcwJIR9KAhj8XlEZJd sHTlLDmH9Tj//RQbBPjAGaeGtQ== X-Received: by 2002:a17:903:230d:b0:196:4fe3:21b1 with SMTP id d13-20020a170903230d00b001964fe321b1mr13352508plh.27.1675463183645; Fri, 03 Feb 2023 14:26:23 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:11a:201:44f:ac27:361d:7805]) by smtp.gmail.com with ESMTPSA id x13-20020a170902a38d00b0019602263feesm2095071pla.90.2023.02.03.14.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 14:26:23 -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 v3 3/5] phy: qcom-qmp-usb: fix memleak on probe deferral Date: Fri, 3 Feb 2023 14:26:14 -0800 Message-Id: <20230203222616.2935268-4-swboyd@chromium.org> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog In-Reply-To: <20230203222616.2935268-1-swboyd@chromium.org> References: <20230203222616.2935268-1-swboyd@chromium.org> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756850860047127053?= X-GMAIL-MSGID: =?utf-8?q?1756850860047127053?= From: Johan Hovold commit a5d6b1ac56cbd6b5850a3a54e35f1cb71e8e8cdd 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. 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 [swboyd@chromium.org: Backport to pre-split driver] Signed-off-by: Stephen Boyd --- drivers/phy/qualcomm/phy-qcom-qmp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c index c6f860ce3d99..ee4fd7afcea2 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -5387,6 +5387,21 @@ static void qcom_qmp_reset_control_put(void *data) reset_control_put(data); } +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_create(struct device *dev, struct device_node *np, int id, void __iomem *serdes, const struct qmp_phy_cfg *cfg) @@ -5396,8 +5411,18 @@ int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id, struct qmp_phy *qphy; const struct phy_ops *ops; 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; @@ -5418,7 +5443,7 @@ int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id, if (IS_ERR(qphy->rx)) return PTR_ERR(qphy->rx); - qphy->pcs = devm_of_iomap(dev, np, 2, NULL); + qphy->pcs = qmp_usb_iomap(dev, np, 2, exclusive); if (IS_ERR(qphy->pcs)) return PTR_ERR(qphy->pcs);