From patchwork Wed May 24 13:29:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 13253994 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 30669C77B7A for ; Wed, 24 May 2023 13:30:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230093AbjEXNaI (ORCPT ); Wed, 24 May 2023 09:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbjEXN3o (ORCPT ); Wed, 24 May 2023 09:29:44 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42677BF for ; Wed, 24 May 2023 06:29:38 -0700 (PDT) Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1q1oYU-0007Bo-HD; Wed, 24 May 2023 15:29:30 +0200 From: Philipp Zabel Date: Wed, 24 May 2023 15:29:24 +0200 Subject: [PATCH 1/2] media: video-mux: fix error paths MIME-Version: 1.0 Message-Id: <20230524-video-mux-active-state-v1-1-325c69937ac3@pengutronix.de> References: <20230524-video-mux-active-state-v1-0-325c69937ac3@pengutronix.de> In-Reply-To: <20230524-video-mux-active-state-v1-0-325c69937ac3@pengutronix.de> To: Mauro Carvalho Chehab Cc: Sakari Ailus , Laurent Pinchart , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Philipp Zabel X-Mailer: b4 0.12-dev-aab37 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::54 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Move notifier cleanup into video_mux_async_register() to avoid calling v4l2_async_nf_unregister() when v4l2_async_subdev_nf_register() failed. In case video_mux_async_register() fails, call media_entity_cleanup(). Signed-off-by: Philipp Zabel Reviewed-by: Laurent Pinchart --- drivers/media/platform/video-mux.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c index 1d9f32e5a917..4fe31386afc7 100644 --- a/drivers/media/platform/video-mux.c +++ b/drivers/media/platform/video-mux.c @@ -389,7 +389,7 @@ static int video_mux_async_register(struct video_mux *vmux, ret = PTR_ERR(asd); /* OK if asd already exists */ if (ret != -EEXIST) - return ret; + goto err_nf_cleanup; } } @@ -397,9 +397,19 @@ static int video_mux_async_register(struct video_mux *vmux, ret = v4l2_async_subdev_nf_register(&vmux->subdev, &vmux->notifier); if (ret) - return ret; + goto err_nf_cleanup; - return v4l2_async_register_subdev(&vmux->subdev); + ret = v4l2_async_register_subdev(&vmux->subdev); + if (ret) + goto err_nf_unregister; + + return 0; + +err_nf_unregister: + v4l2_async_nf_unregister(&vmux->notifier); +err_nf_cleanup: + v4l2_async_nf_cleanup(&vmux->notifier); + return ret; } static int video_mux_probe(struct platform_device *pdev) @@ -473,11 +483,13 @@ static int video_mux_probe(struct platform_device *pdev) vmux->subdev.entity.ops = &video_mux_ops; ret = video_mux_async_register(vmux, num_pads - 1); - if (ret) { - v4l2_async_nf_unregister(&vmux->notifier); - v4l2_async_nf_cleanup(&vmux->notifier); - } + if (ret) + goto err_entity_cleanup; + return 0; + +err_entity_cleanup: + media_entity_cleanup(&vmux->subdev.entity); return ret; }