Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3117687rwb; Mon, 15 Aug 2022 18:32:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR7+vMXFAMQ/3K64X96l+a7OZ2ek9/fb8U5sqcTKXNJ3ZwOYgq3vs4+fCdO5KdK+kx42fifK X-Received: by 2002:a17:907:1608:b0:730:5ad0:ae1a with SMTP id hb8-20020a170907160800b007305ad0ae1amr12099536ejc.222.1660613569830; Mon, 15 Aug 2022 18:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613569; cv=none; d=google.com; s=arc-20160816; b=qKkaySPR0dHrRecz1uZDZZ7Uc+A+q2RVTXddhKUzmb0R6i6t9P224oQjrA3H288tnj 0m+wxXUw1abZH9VGnA4Dz0h1lZydG9gJh4V3qMTXFPwbYnOd4mKubHUgmtjBZfmCpqn4 z2iTCRP7uM1kBcrXGyhE4wjZJyqgtgN49U6GnvMr675d5bFKywEUKmqxvCBGdHOJzF/P B5IKn/1vd5OUhEJE4RcBd+TCfqXkQ/rlQv7epUyj873psggf/SpUz1tHJcvH33i7knOI KYhUXQIyWhk5QCfwlOjWZbA71QMoBMCsJ6/eHdDdUOxKTKMY+wRq9GHt9fSUS4BobttU i/wg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1C+0yYzwgKHADqKkps9XZdoq83OGn+seDFZHZDZYCDY=; b=dJ3cz9mcboAdqcVmj5STfhtwkOVRIGLBc1GdWrh3oq641kUQPNYW0m/ZUT0eSkdpH+ NU9/53EYP0LAYbsKc2V38LYDnLDhTHqRb6JXJLn8MIHWmedYSHS8yyvcf/aGBwy3GEy1 v68DetY4oXGDOfNTAs3nPbV0l1COxKamzSuci6MuckH0+07yI8H4Hrnw4LjHGk+WLr/C vDRgVu2kuAr7j3QXa2CCLTmRz95dnNRzNB1csEoHZz1hJeJERtFrpZ3H6J0ERwr1tmjL cUUf+2a7W7lr1UYo/PqD7Sk0HHVUBPJppmm54Fd0qS86KiGdCOcSDvp9fCCTXZ+pZ9n5 Boow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qmse1TJt; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a056402518a00b0043bd77de21esi10107246edd.51.2022.08.15.18.32.24; Mon, 15 Aug 2022 18:32:49 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=Qmse1TJt; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352526AbiHOW6t (ORCPT + 99 others); Mon, 15 Aug 2022 18:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352718AbiHOW4j (ORCPT ); Mon, 15 Aug 2022 18:56:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194A346DB8; Mon, 15 Aug 2022 12:55:54 -0700 (PDT) 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 83E926113B; Mon, 15 Aug 2022 19:55:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F40DC433D6; Mon, 15 Aug 2022 19:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593353; bh=XaWrafOU5DIdzkvtKxrTyXkKxC1Ft11aAwTJwMtn/v8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qmse1TJtl15Sl48/B7Ruc8nDDX8sM7gx6oEw1Xv1YJmgn0SAjV9QuA6R273CZphdZ wcAIoC87C0zpg1UzgXgKAdsxYl2Iqd17JSCumnGLZpZBPVqM/oBtHTN/Wm/OT1NBMV 2CESmkGPMRPLLr1hfNAP0vcoqgKMuVtKJcx7Jqu8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Yang Yingliang , Laurent Vivier , Geert Uytterhoeven , Sasha Levin Subject: [PATCH 5.19 0255/1157] m68k: virt: Fix missing platform_device_unregister() on error in virt_platform_init() Date: Mon, 15 Aug 2022 19:53:31 +0200 Message-Id: <20220815180449.795267297@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Yang Yingliang [ Upstream commit 566a2d6d8e429727832c7e347cbe736b12ad7297 ] Add the missing platform_device_unregister() before return from virt_platform_init() in the error handling case. Fixes: 05d51e42df06 ("m68k: Introduce a virtual m68k machine") Reported-by: Hulk Robot Signed-off-by: Yang Yingliang Reviewed-by: Laurent Vivier Link: https://lore.kernel.org/r/20220628084903.3147123-1-yangyingliang@huawei.com Signed-off-by: Geert Uytterhoeven Signed-off-by: Sasha Levin --- arch/m68k/virt/platform.c | 58 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/arch/m68k/virt/platform.c b/arch/m68k/virt/platform.c index cb820f19a221..1560c4140ab9 100644 --- a/arch/m68k/virt/platform.c +++ b/arch/m68k/virt/platform.c @@ -8,20 +8,15 @@ #define VIRTIO_BUS_NB 128 -static int __init virt_virtio_init(unsigned int id) +static struct platform_device * __init virt_virtio_init(unsigned int id) { const struct resource res[] = { DEFINE_RES_MEM(virt_bi_data.virtio.mmio + id * 0x200, 0x200), DEFINE_RES_IRQ(virt_bi_data.virtio.irq + id), }; - struct platform_device *pdev; - pdev = platform_device_register_simple("virtio-mmio", id, + return platform_device_register_simple("virtio-mmio", id, res, ARRAY_SIZE(res)); - if (IS_ERR(pdev)) - return PTR_ERR(pdev); - - return 0; } static int __init virt_platform_init(void) @@ -35,8 +30,10 @@ static int __init virt_platform_init(void) DEFINE_RES_MEM(virt_bi_data.rtc.mmio + 0x1000, 0x1000), DEFINE_RES_IRQ(virt_bi_data.rtc.irq + 1), }; - struct platform_device *pdev; + struct platform_device *pdev1, *pdev2; + struct platform_device *pdevs[VIRTIO_BUS_NB]; unsigned int i; + int ret = 0; if (!MACH_IS_VIRT) return -ENODEV; @@ -44,29 +41,40 @@ static int __init virt_platform_init(void) /* We need this to have DMA'able memory provided to goldfish-tty */ min_low_pfn = 0; - pdev = platform_device_register_simple("goldfish_tty", - PLATFORM_DEVID_NONE, - goldfish_tty_res, - ARRAY_SIZE(goldfish_tty_res)); - if (IS_ERR(pdev)) - return PTR_ERR(pdev); + pdev1 = platform_device_register_simple("goldfish_tty", + PLATFORM_DEVID_NONE, + goldfish_tty_res, + ARRAY_SIZE(goldfish_tty_res)); + if (IS_ERR(pdev1)) + return PTR_ERR(pdev1); - pdev = platform_device_register_simple("goldfish_rtc", - PLATFORM_DEVID_NONE, - goldfish_rtc_res, - ARRAY_SIZE(goldfish_rtc_res)); - if (IS_ERR(pdev)) - return PTR_ERR(pdev); + pdev2 = platform_device_register_simple("goldfish_rtc", + PLATFORM_DEVID_NONE, + goldfish_rtc_res, + ARRAY_SIZE(goldfish_rtc_res)); + if (IS_ERR(pdev2)) { + ret = PTR_ERR(pdev2); + goto err_unregister_tty; + } for (i = 0; i < VIRTIO_BUS_NB; i++) { - int err; - - err = virt_virtio_init(i); - if (err) - return err; + pdevs[i] = virt_virtio_init(i); + if (IS_ERR(pdevs[i])) { + ret = PTR_ERR(pdevs[i]); + goto err_unregister_rtc_virtio; + } } return 0; + +err_unregister_rtc_virtio: + while (i > 0) + platform_device_unregister(pdevs[--i]); + platform_device_unregister(pdev2); +err_unregister_tty: + platform_device_unregister(pdev1); + + return ret; } arch_initcall(virt_platform_init); -- 2.35.1