From patchwork Fri Nov 11 06:09:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Can X-Patchwork-Id: 13039695 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D211C4332F for ; Fri, 11 Nov 2022 06:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232499AbiKKGLI (ORCPT ); Fri, 11 Nov 2022 01:11:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbiKKGLG (ORCPT ); Fri, 11 Nov 2022 01:11:06 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B77442BB0E for ; Thu, 10 Nov 2022 22:11:05 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N7pGz6lCbzRp6x; Fri, 11 Nov 2022 14:10:51 +0800 (CST) Received: from huawei.com (10.175.112.208) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 14:11:03 +0800 From: Yuan Can To: , , , , , CC: Subject: [PATCH] media: amphion: Fix error handling in vpu_driver_init() Date: Fri, 11 Nov 2022 06:09:26 +0000 Message-ID: <20221111060926.18508-1-yuancan@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org A problem about modprobe amphion-vpu failed is triggered with the following log given: [ 2208.634841] Error: Driver 'amphion-vpu' is already registered, aborting... modprobe: ERROR: could not insert 'amphion_vpu': Device or resource busy The reason is that vpu_driver_init() returns vpu_core_driver_init() directly without checking its return value, if vpu_core_driver_init() failed, it returns without unregister amphion_vpu_driver, resulting the amphion-vpu can never be installed later. A simple call graph is shown as below: vpu_driver_init() platform_driver_register() # register amphion_vpu_driver vpu_core_driver_init() platform_driver_register() driver_register() bus_add_driver() dev = kzalloc(...) # OOM happened # return without unregister amphion_vpu_driver Fix by unregister amphion_vpu_driver when vpu_core_driver_init() returns error. Fixes: b50a64fc54af ("media: amphion: add amphion vpu device driver") Signed-off-by: Yuan Can Reviewed-by: ming_qian --- drivers/media/platform/amphion/vpu_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/amphion/vpu_drv.c b/drivers/media/platform/amphion/vpu_drv.c index 9d5a5075343d..f01ce49d27e8 100644 --- a/drivers/media/platform/amphion/vpu_drv.c +++ b/drivers/media/platform/amphion/vpu_drv.c @@ -245,7 +245,11 @@ static int __init vpu_driver_init(void) if (ret) return ret; - return vpu_core_driver_init(); + ret = vpu_core_driver_init(); + if (ret) + platform_driver_unregister(&hion_vpu_driver); + + return ret; } static void __exit vpu_driver_exit(void)