Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp683265rdb; Fri, 17 Nov 2023 09:38:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcnMAgaoU1eYDKRpsXTcAo2jdwVhbTRiMDoqxygzu5jZEAMfb0B+CqZD02NSI3g0v1NUa+ X-Received: by 2002:a9d:7d97:0:b0:6d3:e5c:768f with SMTP id j23-20020a9d7d97000000b006d30e5c768fmr11918186otn.11.1700242702860; Fri, 17 Nov 2023 09:38:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700242702; cv=none; d=google.com; s=arc-20160816; b=d+1+j6wF2gpqOdvPYM+BA8+R0FZHL7utQ7QkdpG2Urddhce5TMJg05/rv0fwTOhgWU 9wf+OlQny9FsLEa/dJKj/5WguNHIMLuSNvjnk8eJvat9lZiuQltCkP6CAsjnF1HMZapD vxuIbhoalU+1sNTXwAJ/ZG4tNLNJh+mzGhOBfxpkZoUFiq8MlIiRqZiazZbLqWZn/WB3 1qQracuQafRG+yh0+RHg6CBNOJjSTpfkdu9Im3xk+wbpHudKjkc/qlWaybUzRleodA0v faX2dudvuBSoLIUfCMO8uinunmKmz2iK1DXfT/TzF08JBo+ZP+DxiCP7RsEKjBbCkzIc YGOg== 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=OdLauOLpbKLJXRKeFlyTsCWtpPIh44ZNYL488mdQVGw=; fh=6pCCKOhGyzdK+XdsN2fRe1xh5MCQPAJLu6LKxoNW22U=; b=bBMAzyJLe9esRN5GrUYaRCvw2VcurGFbS9O6g2w/lPg96PQkRk1KMPchcZcdmGd2v/ eaVL9ihlRuUL19CloILrCGYxwBfaHVESDS08JOMMaZ3ua0f+hHoT1+IKzmqp6tur88Px NCgMpSePHnikEafwDo4kgVLin9NnxglYll/CQ+29KaGnF2L5NO3eoJvBlrv5w5DKYQqe tBHB4nlQEgsB4r7JgL1rJooeaq+knw7e3hAMZqVdgbJzEYPIfty1jqZexEUCSVU06Bo3 CSjCwa+Kz2KZxkbCGrOdTdTjFY2BdCJjzZoQKaiBHHRGmR9z+2qnZ5of3mHSmvZIOi2I /agw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nZY+9QHQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e23-20020a63e017000000b005be3c3748c7si2129709pgh.38.2023.11.17.09.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 09:38:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nZY+9QHQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8AFB2829E5FA; Fri, 17 Nov 2023 09:38:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346167AbjKQRiS (ORCPT + 99 others); Fri, 17 Nov 2023 12:38:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346146AbjKQRiN (ORCPT ); Fri, 17 Nov 2023 12:38:13 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C77B210F4 for ; Fri, 17 Nov 2023 09:38:09 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AEA2C433CB; Fri, 17 Nov 2023 17:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700242689; bh=IDrqe0MvHTg6enNUp8mTcE/BgNy+EDele8qbx8DCFmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZY+9QHQrZY7aae9tNrEW16uBgb+gK8D9LEpKbV3uKNZZSycjpDoiD5Z+jnml14Vl PilvGJTsfZlrkdW7hu9pqR/xD0q5jFo0L6HJUtHjrf9TCp/4IaDh+cW0D9YpHP/BMU bLHLOFc2AczbfruoCz/8eRUfwePgOxfd/onUWUqd7zXHe1Ww3Virrdk6kSEcQI5Sxe kK/OJ0ER84KOgxHHStzkXz0q09ZuLDeV0lRKB+H9gb7QaAcZD4BfEm1AmjJvzxWMMM y1GD+Lrl7fKZpnxiEq43OMuNTiS79DMnhNm3eeMvRtbJZPILnScgV0SO+HxlxhmyHg +qq8ATEygyXJQ== Received: from johan by xi.lan with local (Exim 4.96.2) (envelope-from ) id 1r42nF-0005Vu-1A; Fri, 17 Nov 2023 18:38:13 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Thinh Nguyen , Krishna Kurapati PSSNV , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Shawn Guo Subject: [PATCH 3/3] USB: dwc3: qcom: fix ACPI platform device leak Date: Fri, 17 Nov 2023 18:36:50 +0100 Message-ID: <20231117173650.21161-4-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231117173650.21161-1-johan+linaro@kernel.org> References: <20231117173650.21161-1-johan+linaro@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 09:38:21 -0800 (PST) Make sure to free the "urs" platform device, which is created for some ACPI platforms, on probe errors and on driver unbind. Compile-tested only. Fixes: c25c210f590e ("usb: dwc3: qcom: add URS Host support for sdm845 ACPI boot") Cc: Shawn Guo Signed-off-by: Johan Hovold --- drivers/usb/dwc3/dwc3-qcom.c | 37 +++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 0703f9b85cda..10fb481d943b 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -767,9 +767,9 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev) return ret; } -static struct platform_device * -dwc3_qcom_create_urs_usb_platdev(struct device *dev) +static struct platform_device *dwc3_qcom_create_urs_usb_platdev(struct device *dev) { + struct platform_device *urs_usb = NULL; struct fwnode_handle *fwh; struct acpi_device *adev; char name[8]; @@ -789,9 +789,26 @@ dwc3_qcom_create_urs_usb_platdev(struct device *dev) adev = to_acpi_device_node(fwh); if (!adev) - return NULL; + goto err_put_handle; + + urs_usb = acpi_create_platform_device(adev, NULL); + if (IS_ERR_OR_NULL(urs_usb)) + goto err_put_handle; + + return urs_usb; - return acpi_create_platform_device(adev, NULL); +err_put_handle: + fwnode_handle_put(fwh); + + return urs_usb; +} + +static void dwc3_qcom_destroy_urs_usb_platdev(struct platform_device *urs_usb) +{ + struct fwnode_handle *fwh = urs_usb->dev.fwnode; + + platform_device_unregister(urs_usb); + fwnode_handle_put(fwh); } static int dwc3_qcom_probe(struct platform_device *pdev) @@ -875,13 +892,13 @@ static int dwc3_qcom_probe(struct platform_device *pdev) qcom->qscratch_base = devm_ioremap_resource(dev, parent_res); if (IS_ERR(qcom->qscratch_base)) { ret = PTR_ERR(qcom->qscratch_base); - goto clk_disable; + goto free_urs; } ret = dwc3_qcom_setup_irq(pdev); if (ret) { dev_err(dev, "failed to setup IRQs, err=%d\n", ret); - goto clk_disable; + goto free_urs; } /* @@ -900,7 +917,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); - goto clk_disable; + goto free_urs; } ret = dwc3_qcom_interconnect_init(qcom); @@ -939,6 +956,9 @@ static int dwc3_qcom_probe(struct platform_device *pdev) platform_device_del(qcom->dwc3); } platform_device_put(qcom->dwc3); +free_urs: + if (qcom->urs_usb) + dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); clk_disable: for (i = qcom->num_clocks - 1; i >= 0; i--) { clk_disable_unprepare(qcom->clks[i]); @@ -965,6 +985,9 @@ static void dwc3_qcom_remove(struct platform_device *pdev) } platform_device_put(qcom->dwc3); + if (qcom->urs_usb) + dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); + for (i = qcom->num_clocks - 1; i >= 0; i--) { clk_disable_unprepare(qcom->clks[i]); clk_put(qcom->clks[i]); -- 2.41.0