Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1538136rwd; Tue, 13 Jun 2023 10:23:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ423iviZQcbtoItCDu3x4OKSJ+Tckk3wLxnfgOftbCXugF1bjWvUcifCO4etq/wYB6UVr/1 X-Received: by 2002:a50:fb8e:0:b0:518:7adb:22fd with SMTP id e14-20020a50fb8e000000b005187adb22fdmr1072570edq.14.1686676989410; Tue, 13 Jun 2023 10:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686676989; cv=none; d=google.com; s=arc-20160816; b=hnajnEd3hYVsKFOKXHMQDtJDMjG6mP2ga1kRwWhjEs9ry0Jinb3wFgoraZw9YoEtov v/v88jXnZBHymTXK9z9Y1VfJVn8LmHER2ZzsKtEHhT/eB7I1qyazwTSdypHPj47h5LKM avmCZQJ4aTLNcyEni0PuCBHSizOyfxrGPolN4Ozuzl5M9p/GSlXoaczRIAsEOHADTF3W Gl8qf40dqDcpMN8r81/csgsOS/5FJaWaR1LsfP3wm5wsy87Un/n5Bw+jX4gCD5t948l2 VvLPTz55Ah8TC880M2JOT6EJOZQwY6E9euv5g4hyD9WCGcNPdhigaPtur4N5HhWpP7AV gIzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=nJwk0bnAQ0Xv6sG4ivedyKkZihPzSwcBd5Y0QPp0N8Q=; b=viEpUQtlDzbJTPQ/om2p+30aEmSsMPOk1Sp5yZlpRlsQbeSG7wWcLWYaHRBoU7yoWi vTw9LkVTgYwi9/pJRi6itKRHLhOVaZnbCvXEqRCbF3Dte8jaHUupwsF/Zk8X2kh1Ktav yRwKOtTEOeGf/ifLZAzppqLKxW913WrwVfjMq/PW5GY1+zDslcRjwfPbF9aE83WTv4rU yAmJ33USOb5FP+FLf/kGS3EaTDsOav0sInmNLmWu1pfQm4nbSfsr8RB6Fnxk+nhsjfQP QcSpkuwLWoCrXJK/3VxBmPhp6mj/X+PXxR/qgjohYJ1ebg5ct+ZNwbUh/eudWJjR3hCu s4sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=MVyQ422g; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f9-20020a056402150900b005149b9127b9si7603005edw.675.2023.06.13.10.22.44; Tue, 13 Jun 2023 10:23:09 -0700 (PDT) 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=pass header.i=@wanadoo.fr header.s=t20230301 header.b=MVyQ422g; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237637AbjFMRP6 (ORCPT + 99 others); Tue, 13 Jun 2023 13:15:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237764AbjFMRPz (ORCPT ); Tue, 13 Jun 2023 13:15:55 -0400 Received: from smtp.smtpout.orange.fr (smtp-25.smtpout.orange.fr [80.12.242.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86801BD3 for ; Tue, 13 Jun 2023 10:15:50 -0700 (PDT) Received: from [192.168.1.18] ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 97cKqpd5hx5Vb97cKqvfRE; Tue, 13 Jun 2023 19:15:42 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1686676542; bh=nJwk0bnAQ0Xv6sG4ivedyKkZihPzSwcBd5Y0QPp0N8Q=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=MVyQ422go+DjjzMaDCYxv4dYV00tNMyAXp4VRoC/u+vRBDxhF+r1NEVXlvPeaj/G1 XPSj8iTmg8nxd5idXgfiqg6JZVHpk5RTaUP4LxVOK/IZwbhwMnQfAZS0jhdD4pWjC9 cVL/de62rrH4bsDt84FJLrm8k95o8VmS/v4Pyf5unBP2Gj00S1+n5TqYCCRKY95uNM tWaQYID9AN+jWNhvsMRiPF2lb3RKXwTyFlDcXOPYgDmyoEVrFlieyzA+cBWyDHPGLK vreUmFehIue4Nx7PF08o4Fk2E4nLcvvXSN+ZT6q+qjLsM1/KfHEtR3ib8LYjRPbOil 6q+UQea0BNfGA== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 13 Jun 2023 19:15:42 +0200 X-ME-IP: 86.243.2.178 Message-ID: <34b714b6-cb49-1a34-58f5-8b5ef0da2714@wanadoo.fr> Date: Tue, 13 Jun 2023 19:15:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] media: v4l2-core: Fix a potential resource leak in v4l2_fwnode_parse_link() To: Sakari Ailus Cc: Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-media@vger.kernel.org References: <2ddd10ec9e009bbb85518355f1e09e1ecd349925.1685340968.git.christophe.jaillet@wanadoo.fr> Content-Language: fr From: Christophe JAILLET In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Le 13/06/2023 à 12:55, Sakari Ailus a écrit : > Hi Christophe, > > On Mon, May 29, 2023 at 08:17:18AM +0200, Christophe JAILLET wrote: >> 'fwnode is known to be NULL, at this point, so fwnode_handle_put() is a >> no-op. >> >> Release the reference taken from a previous fwnode_graph_get_port_parent() >> call instead. >> >> Fixes: ca50c197bd96 ("[media] v4l: fwnode: Support generic fwnode for parsing standardised properties") >> Signed-off-by: Christophe JAILLET >> --- >> /!\ THIS PATCH IS SPECULATIVE /!\ >> review with care >> --- >> drivers/media/v4l2-core/v4l2-fwnode.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c >> index 049c2f2001ea..b7dd467c53fd 100644 >> --- a/drivers/media/v4l2-core/v4l2-fwnode.c >> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c >> @@ -571,7 +571,7 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, >> >> fwnode = fwnode_graph_get_remote_endpoint(fwnode); >> if (!fwnode) { >> - fwnode_handle_put(fwnode); >> + fwnode_handle_put(link->local_node); > > link->local_node also needs to be non-NULL for the successful case. The > condition should take that into account. Could you send v2 with that? > >> return -ENOLINK; >> } >> > Hi, something like below? @@ -568,19 +568,25 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, link->local_id = fwep.id; link->local_port = fwep.port; link->local_node = fwnode_graph_get_port_parent(fwnode); + if (!link->local_node) + return -ENOLINK; fwnode = fwnode_graph_get_remote_endpoint(fwnode); - if (!fwnode) { - fwnode_handle_put(fwnode); - return -ENOLINK; - } + if (!fwnode) + goto err_put_local_node; fwnode_graph_parse_endpoint(fwnode, &fwep); link->remote_id = fwep.id; link->remote_port = fwep.port; link->remote_node = fwnode_graph_get_port_parent(fwnode); + if (!link->remote_node) + goto err_put_local_node; return 0; + +err_put_local_node: + fwnode_handle_put(link->local_node); + return -ENOLINK; } EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link); CJ