mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH] media: v4l2-core: Fix a potential resource leak in v4l2_fwnode_parse_link()
Date: Tue, 13 Jun 2023 19:15:40 +0200	[thread overview]
Message-ID: <34b714b6-cb49-1a34-58f5-8b5ef0da2714@wanadoo.fr> (raw)
In-Reply-To: <ZIhLDh567eWqY5vk@kekkonen.localdomain>

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 <christophe.jaillet@wanadoo.fr>
>> ---
>> /!\  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

  reply	other threads:[~2023-06-13 17:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-29  6:17 Christophe JAILLET
2023-06-13 10:55 ` Sakari Ailus
2023-06-13 17:15   ` Christophe JAILLET [this message]
2023-06-14  8:00     ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34b714b6-cb49-1a34-58f5-8b5ef0da2714@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®