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: 55784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1442544wrn; Sat, 11 Feb 2023 03:12:50 -0800 (PST) X-Google-Smtp-Source: AK7set9KGdAPUiep/Dp/wF/7KS2Ihx5cmlb99DbFHtFi5M3CK9gVWCDToz8FXeA1qajp/sLhOFYc X-Received: by 2002:a05:6a21:3398:b0:be:b137:9d15 with SMTP id yy24-20020a056a21339800b000beb1379d15mr22984033pzb.36.1676113970002; Sat, 11 Feb 2023 03:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676113969; cv=none; d=google.com; s=arc-20160816; b=J6HqZcwik+LFnMbZcQ6iMWDTTbmaP/9B4D6WVWMEvg+3DFiILcKK5Y/eRhnLBibdvJ WcFAvg0+7TWNAT7p5EluvBz9mUuBMViHHG0r8q43b4E81v/sgDRZ6G4LOfAyho9qwOXZ Qa6YSVraddXWYnQKcu5oaI0uuNsSh7Lxak7lTASsybshNCpJ6VU5j93QP+wF145QblHo xMrxbkWPFmzjYRGc1GzGyu16JoIDDq0wlnuN5gPeX8HkQqjreF+G0/0G7g7RburwNYyG 2ZPY11kM8c87QR+EmA36kWQr2dIpiLiqByqTOoEIgk8EBQaXZWC8FYaSCVxejbgrHkwF 8TMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=0cX/KtHqdJqb6Rrw059A36ailM7NF0OlYLzCM1/MQlg=; b=yuoDI4zfQKGoIW/uAr9zyfLRc/uAHvsk463hiPCn/nWqXeZqgWm3xrKZwi8ZI3YvJq Pi7B4gD4LQOPbyV4Msy9ctqSMtZA9n7ZIY8efTOJ//Tfu4F6xpUFGk5D6B5utRwHd+UW TJQs8MEZFDoxcqpXEZS8cIHxCKFSd5+FCQZjhErgs1qXzvlSIT771xMdTjrn+yKouIxg zriBNHjqkmH6UnDODyS5+IFtYxkthBRdtNiy0i+xLkWtYV5S0hmUIJcvquq6w8r3gwtm 9vfrMwMF0MbXNVR5+r5nZJMuBS0jttTC3IsZLIrB1M8mjfV+Dl0bi27VVlPe4TyHlDOO ULaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=ZGzOiTTq; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a638c02000000b00479018c4634si6805180pgd.671.2023.02.11.03.12.35; Sat, 11 Feb 2023 03:12:49 -0800 (PST) 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=fail header.i=@mailo.com header.s=mailo header.b=ZGzOiTTq; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbjBKLKH (ORCPT + 99 others); Sat, 11 Feb 2023 06:10:07 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757532882226250223?= X-GMAIL-MSGID: =?utf-8?q?1757532882226250223?= 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)