From patchwork Thu Mar 3 18:09:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12767868 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 DA1DDC433EF for ; Thu, 3 Mar 2022 18:10:52 +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=QFmrv8udqvMHG8K5hG8e2Qy8hGU+/qKkBipJg8PUEQ8=; b=p5b23QnYoOMcM0 GvbrowNVCPzTWkhmC6CH6wMIJ1bcNs7fhslkVpnMXZseyhSCRc+BZzbojXoUYqk44qiqM7NOf6fNt kY+Inj5gkiBHI3906B1faHllUChvd/A/keBQvqeloWYkjvlwsupiNOSqfC0IFs+L/kghQvmsVG9Kb vTD2wISo69sMRNhoWW+X38sOW4rNQM4ryDYU3nkssywuKUm9enBPQR9jUUceCiG2gtnw29xkoxPfN UeVDPK1z3fxR6PQ2WTkMXy+bUicYtlSqIyR6Sua4wStsCb48smF32S/6l2XaLryxubFV7V0eHuv8a 5JK8jDytS0OkGEkrx1Yg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nPpta-007RiN-RR; Thu, 03 Mar 2022 18:09:46 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nPptY-007Ri2-2c for linux-arm-kernel@lists.infradead.org; Thu, 03 Mar 2022 18:09:45 +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 ams.source.kernel.org (Postfix) with ESMTPS id 49B4BB8087F; Thu, 3 Mar 2022 18:09:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 079AAC004E1; Thu, 3 Mar 2022 18:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646330981; bh=PmxWgWYYEa9JLK8qebEjp4pPoTL5mDmqZB4piqpOtvM=; h=From:To:Cc:Subject:Date:From; b=AnmT/FxGaPyzVmDOxrDUnKWgM8sCsnyTdw6HY8X3RrDUHBqeFixlj+U5VsoU00dWF p4O5/qlCZeOvBxzdnb4f7kPKkBACygIc6F4bJt9R2WfQWkUeYLfYBTt1yrbSRJY4Q6 SjaQa2PPzP6h4vU3mTx2p5IlZhAn8P86d/YAn08MduJejbhLVdEtVwTUmXWn9w8iiZ f6NPXmvW/CUTdYIbAjY4FIuRC5oIKhd7MR9os9dHq8jMbM9NHYvcsoZZiYl4uvrBrw y3WSkm/at/tNvgcJLTAMG1S1D6eyXdlsOxSHWyiYVHSQI6ZeEUb072haepmXQZXFTW OsAoGxWvdEokQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1nPptT-0000t3-Q6; Thu, 03 Mar 2022 19:09:39 +0100 From: Johan Hovold To: Lubomir Rintel Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH] ARM: mmp: fix platform-device leak on registration errors Date: Thu, 3 Mar 2022 19:09:00 +0100 Message-Id: <20220303180900.3371-1-johan@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220303_100944_301899_1C24E6E9 X-CRM114-Status: GOOD ( 13.83 ) 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 --- 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 18bee66a671f..0b99aa1d5350 100644 --- a/arch/arm/mach-mmp/devices.c +++ b/arch/arm/mach-mmp/devices.c @@ -53,20 +53,25 @@ int __init pxa_register_device(struct pxa_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)