From patchwork Sat Feb 11 11:09:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 13137006 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 AEA5AC61DA4 for ; Sat, 11 Feb 2023 11:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229566AbjBKLKG (ORCPT ); Sat, 11 Feb 2023 06:10:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjBKLKG (ORCPT ); Sat, 11 Feb 2023 06:10:06 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED35B20057; Sat, 11 Feb 2023 03:10:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1676113794; bh=5yApPz7ebuShtxrTuVWINA4sOPX+XYKVeOohcbcuehk=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=ZGzOiTTqV4La4J5DQSAtgRFeWjt0e52Q3jNl0ztbPToIl0sHOpl3Wsnl3j+aaON95 KYLzJDwwygq9Fpfx4R95gdsCSVG4o9U8E2fH6SBZHqTX/pH9j3Y5JZPhjCM/gmN4et 3vMXwCuhXC+56uPZnftbWtaPwQCCIX9Ix91w8ecA= Received: by b-2.in.mailobj.net [192.168.90.12] with ESMTP via ip-206.mailobj.net [213.182.55.206] Sat, 11 Feb 2023 12:09:54 +0100 (CET) X-EA-Auth: +b2O3JVJUDbTIbrBSTNVB6zRG+uUfXCvDhDTmkEoMe3IMbabFQNeu7b99bIpT+wXnTRI+9dz+M00r4LxxZQH+pA4Vr7R4788 Date: Sat, 11 Feb 2023 16:39:50 +0530 From: Deepak R Varma To: Mauro Carvalho Chehab , Matthias Brugger , AngeloGioacchino Del Regno , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH] media: platform: mtk-mdp3: release node reference before returning Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The iterator for_each_child_of_node() increments the refcount of the child node it is processing. Release such a reference when the loop needs to break due to an error during its execution. Issue identified using for_each_child.cocci Coccinelle semantic patch. Signed-off-by: Deepak R Varma --- Please note: The proposed change is compile tested only. I do not have the necessary hardware to perform additional testing. Please suggest if there is an alternate means available to further test this change. .../media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c index 7bc05f42a23c..2c50a73bbf23 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c @@ -898,6 +898,7 @@ static int mdp_comp_sub_create(struct mdp_dev *mdp) { struct device *dev = &mdp->pdev->dev; struct device_node *node, *parent; + int ret = 0; parent = dev->of_node->parent; @@ -923,16 +924,22 @@ static int mdp_comp_sub_create(struct mdp_dev *mdp) dev_err(dev, "Fail to get sub comp. id: type %d alias %d\n", type, alias_id); - return -EINVAL; + ret = -EINVAL; + goto err_free_node; } mdp_comp_alias_id[type]++; comp = mdp_comp_create(mdp, node, id); - if (IS_ERR(comp)) - return PTR_ERR(comp); + if (IS_ERR(comp)) { + ret = PTR_ERR(comp); + goto err_free_node; + } } + return ret; - return 0; +err_free_node: + of_node_put(node); + return ret; } void mdp_comp_destroy(struct mdp_dev *mdp)