From patchwork Mon Oct 18 09:22:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jammy Huang X-Patchwork-Id: 12565465 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B206AC433EF for ; Mon, 18 Oct 2021 09:23:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 937D06127C for ; Mon, 18 Oct 2021 09:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231567AbhJRJ0A (ORCPT ); Mon, 18 Oct 2021 05:26:00 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:9322 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231665AbhJRJZX (ORCPT ); Mon, 18 Oct 2021 05:25:23 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 19I90GxC071198; Mon, 18 Oct 2021 17:00:16 +0800 (GMT-8) (envelope-from jammy_huang@aspeedtech.com) Received: from JammyHuang-PC.aspeed.com (192.168.2.115) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 18 Oct 2021 17:22:10 +0800 From: Jammy Huang To: , , , , , , , , Subject: [PATCH v2 1/7] media: aspeed: move err-handling together to the bottom Date: Mon, 18 Oct 2021 17:22:01 +0800 Message-ID: <20211018092207.13336-2-jammy_huang@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211018092207.13336-1-jammy_huang@aspeedtech.com> References: <20211018092207.13336-1-jammy_huang@aspeedtech.com> MIME-Version: 1.0 X-Originating-IP: [192.168.2.115] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 19I90GxC071198 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org refine aspeed_video_setup_video() flow. Signed-off-by: Jammy Huang --- drivers/media/platform/aspeed-video.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/aspeed-video.c b/drivers/media/platform/aspeed-video.c index 491447bf5186..6259cf17a7cc 100644 --- a/drivers/media/platform/aspeed-video.c +++ b/drivers/media/platform/aspeed-video.c @@ -1644,11 +1644,8 @@ static int aspeed_video_setup_video(struct aspeed_video *video) rc = video->ctrl_handler.error; if (rc) { - v4l2_ctrl_handler_free(&video->ctrl_handler); - v4l2_device_unregister(v4l2_dev); - dev_err(video->dev, "Failed to init controls: %d\n", rc); - return rc; + goto err_ctrl_init; } v4l2_dev->ctrl_handler = &video->ctrl_handler; @@ -1666,11 +1663,8 @@ static int aspeed_video_setup_video(struct aspeed_video *video) rc = vb2_queue_init(vbq); if (rc) { - v4l2_ctrl_handler_free(&video->ctrl_handler); - v4l2_device_unregister(v4l2_dev); - dev_err(video->dev, "Failed to init vb2 queue\n"); - return rc; + goto err_vb2_init; } vdev->queue = vbq; @@ -1688,15 +1682,19 @@ static int aspeed_video_setup_video(struct aspeed_video *video) video_set_drvdata(vdev, video); rc = video_register_device(vdev, VFL_TYPE_GRABBER, 0); if (rc) { - vb2_queue_release(vbq); - v4l2_ctrl_handler_free(&video->ctrl_handler); - v4l2_device_unregister(v4l2_dev); - dev_err(video->dev, "Failed to register video device\n"); - return rc; + goto err_video_reg; } return 0; + +err_video_reg: + vb2_queue_release(vbq); +err_vb2_init: +err_ctrl_init: + v4l2_ctrl_handler_free(&video->ctrl_handler); + v4l2_device_unregister(v4l2_dev); + return rc; } static int aspeed_video_init(struct aspeed_video *video)