From patchwork Mon Jun 20 14:14:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12887610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FC65C433EF for ; Mon, 20 Jun 2022 14:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=n0el+z4ITV0ibNurYdC2WoFU8XmUsCpZ8XVy/yY6jkw=; b=AUHpBZ5yjnMz6F 8yzflVyzzIW+Ln7mJhqVAxpK1ACkjRwU2cY2UKNbw6L08k4PXTl+OjXDA7PapCI1SGsrQ4eb9m6+S feIhowjXLtTuJz/zBG82MhUP/UDCgsqSXszsDGj5KvsiWDur0K1Zp81a1vCLO9gGIM417QbLiLwWc kMlZ1y/L/R7V6xDPCbuogpdQs/61+pWfUke1hwLn5oIn7bzDVUZkP6H2jUmCOYbpDwBzmD3uVtnWy 7j1zyG+fLoBuaWtcEvtgAvxbkieEVPimkGOJQMQCFvvlMG4+jIyHyAbkOG4qk7Kq2EsppxmFQwAFS 14gKH4+nwuJVrFNrOwxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3IAu-0012bG-9Y; Mon, 20 Jun 2022 14:14:44 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3IAk-0012Zh-RB for linux-arm-kernel@lists.infradead.org; Mon, 20 Jun 2022 14:14:36 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5C9F460BFB; Mon, 20 Jun 2022 14:14:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B78F7C3411B; Mon, 20 Jun 2022 14:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655734473; bh=PPCdeS+2XDRfjEPcn2kexd2bRxaYKO9xJ1qMW6/4C/M=; h=From:To:Cc:Subject:Date:From; b=X5A1Bq8j+3aOZuH0OfuzedSC4UeZkxK3Mib52D8qIZ92kTE3wcKAC+aUZGQDab6Y9 Xsl7fB0P4zlv02dWja5s7lbsT6cYFWwKjCguNk/Bjxnbwy0qHp7rcgKFE8sJX1LL0n AabCVtoPgqVPJnbCIQIqqk/D3o51qxDLcZZ4JYjZTWYVZaYEZhghKC0BFmc+O2GpUt RJ2v0cjIgxiZbRQXLhphcbrZmRUE+fAaPfBQ6LeyFPLpfM7M3GdCEnOY9shuv3xpB5 ESUyhAWFP8623BvXLcntzhIjtykSSb56uOUL18yQhYjpCij2NLqTlLowTXLqZLwCEG nX8SS3/bFfJwA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1o3IAe-0002ds-Gw; Mon, 20 Jun 2022 16:14:29 +0200 From: Johan Hovold To: Lubomir Rintel , Arnd Bergmann Cc: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH RESEND] ARM: mmp: fix platform-device leak on registration errors Date: Mon, 20 Jun 2022 16:14:06 +0200 Message-Id: <20220620141406.10122-1-johan@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220620_071434_954065_E02D21BA X-CRM114-Status: GOOD ( 13.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Make sure to free the platform device also in the event that registration fails. Fixes: 49cbe78637eb ("[ARM] pxa: add base support for Marvell's PXA168 processor line") Cc: stable@vger.kernel.org # 2.6.30 Signed-off-by: Johan Hovold --- It's been almost four months so resending. Arnd, can you pick this one up if Lubomir isn't around anymore? Johan arch/arm/mach-mmp/devices.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/arm/mach-mmp/devices.c b/arch/arm/mach-mmp/devices.c index 79f4a2aa5475..dfb072d788ff 100644 --- a/arch/arm/mach-mmp/devices.c +++ b/arch/arm/mach-mmp/devices.c @@ -53,20 +53,25 @@ int __init mmp_register_device(struct mmp_device_desc *desc, } ret = platform_device_add_resources(pdev, res, nres); - if (ret) { - platform_device_put(pdev); - return ret; - } + if (ret) + goto err_put_device; if (data && size) { ret = platform_device_add_data(pdev, data, size); - if (ret) { - platform_device_put(pdev); - return ret; - } + if (ret) + goto err_put_device; } - return platform_device_add(pdev); + ret = platform_device_add(pdev); + if (ret) + goto err_put_device; + + return 0; + +err_put_device: + platform_device_put(pdev); + + return ret; } #if IS_ENABLED(CONFIG_USB) || IS_ENABLED(CONFIG_USB_GADGET)