All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] media: siano: Fix two bugs in smsdvb_debugfs_create()
@ 2023-09-14  3:50 Jinjie Ruan
  2023-09-14  3:50 ` [PATCH 1/2] media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file() Jinjie Ruan
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jinjie Ruan @ 2023-09-14  3:50 UTC (permalink / raw)
  To: mchehab, hverkuil-cisco, ye.xingchen, linux-media; +Cc: ruanjinjie

As debugfs_create_file() returns ERR_PTR and never NULL, check NULL is not
correct to catch the error.

And if kzalloc() fails in smsdvb_debugfs_create(), the dir and file which
is created by debugfs_create_dir() and debugfs_create_file() is
not freed.

This patch set fix the above 2 bugs.

Jinjie Ruan (2):
  media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file()
  media: siano: Fix the missing err path in smsdvb_debugfs_create()

 drivers/media/common/siano/smsdvb-debugfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file()
  2023-09-14  3:50 [PATCH 0/2] media: siano: Fix two bugs in smsdvb_debugfs_create() Jinjie Ruan
@ 2023-09-14  3:50 ` Jinjie Ruan
  2023-10-05  8:21   ` [DKIM] " Hans Verkuil
  2023-09-14  3:50 ` [PATCH 2/2] media: siano: Fix the missing err path in smsdvb_debugfs_create() Jinjie Ruan
  2023-09-28  1:24 ` [PATCH 0/2] media: siano: Fix two bugs " Ruan Jinjie
  2 siblings, 1 reply; 7+ messages in thread
From: Jinjie Ruan @ 2023-09-14  3:50 UTC (permalink / raw)
  To: mchehab, hverkuil-cisco, ye.xingchen, linux-media; +Cc: ruanjinjie

Since debugfs_create_file() returns ERR_PTR and never NULL, use IS_ERR() to
check the return value.

Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/media/common/siano/smsdvb-debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c
index e0beefd80d7b..16d3b9ab31c5 100644
--- a/drivers/media/common/siano/smsdvb-debugfs.c
+++ b/drivers/media/common/siano/smsdvb-debugfs.c
@@ -369,7 +369,7 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client)
 
 	d = debugfs_create_file("stats", S_IRUGO | S_IWUSR, client->debugfs,
 				client, &debugfs_stats_ops);
-	if (!d) {
+	if (IS_ERR(d)) {
 		debugfs_remove(client->debugfs);
 		return -ENOMEM;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] media: siano: Fix the missing err path in smsdvb_debugfs_create()
  2023-09-14  3:50 [PATCH 0/2] media: siano: Fix two bugs in smsdvb_debugfs_create() Jinjie Ruan
  2023-09-14  3:50 ` [PATCH 1/2] media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file() Jinjie Ruan
@ 2023-09-14  3:50 ` Jinjie Ruan
  2023-10-05  8:30   ` [DKIM] " Hans Verkuil
  2023-09-28  1:24 ` [PATCH 0/2] media: siano: Fix two bugs " Ruan Jinjie
  2 siblings, 1 reply; 7+ messages in thread
From: Jinjie Ruan @ 2023-09-14  3:50 UTC (permalink / raw)
  To: mchehab, hverkuil-cisco, ye.xingchen, linux-media; +Cc: ruanjinjie

If kzalloc() fails in smsdvb_debugfs_create(), the dir and file which
is created by debugfs_create_dir() and debugfs_create_file() is
not freed. So use debugfs_remove_recursive() to free them.

Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/media/common/siano/smsdvb-debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c
index 16d3b9ab31c5..38b25e88ce57 100644
--- a/drivers/media/common/siano/smsdvb-debugfs.c
+++ b/drivers/media/common/siano/smsdvb-debugfs.c
@@ -375,8 +375,10 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client)
 	}
 
 	debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL);
-	if (!debug_data)
+	if (!debug_data) {
+		debugfs_remove_recursive(client->debugfs);
 		return -ENOMEM;
+	}
 
 	client->debug_data        = debug_data;
 	client->prt_dvb_stats     = smsdvb_print_dvb_stats;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] media: siano: Fix two bugs in smsdvb_debugfs_create()
  2023-09-14  3:50 [PATCH 0/2] media: siano: Fix two bugs in smsdvb_debugfs_create() Jinjie Ruan
  2023-09-14  3:50 ` [PATCH 1/2] media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file() Jinjie Ruan
  2023-09-14  3:50 ` [PATCH 2/2] media: siano: Fix the missing err path in smsdvb_debugfs_create() Jinjie Ruan
@ 2023-09-28  1:24 ` Ruan Jinjie
  2 siblings, 0 replies; 7+ messages in thread
From: Ruan Jinjie @ 2023-09-28  1:24 UTC (permalink / raw)
  To: mchehab, hverkuil-cisco, ye.xingchen, linux-media

Ping.

On 2023/9/14 11:50, Jinjie Ruan wrote:
> As debugfs_create_file() returns ERR_PTR and never NULL, check NULL is not
> correct to catch the error.
> 
> And if kzalloc() fails in smsdvb_debugfs_create(), the dir and file which
> is created by debugfs_create_dir() and debugfs_create_file() is
> not freed.
> 
> This patch set fix the above 2 bugs.
> 
> Jinjie Ruan (2):
>   media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file()
>   media: siano: Fix the missing err path in smsdvb_debugfs_create()
> 
>  drivers/media/common/siano/smsdvb-debugfs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [DKIM] [PATCH 1/2] media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file()
  2023-09-14  3:50 ` [PATCH 1/2] media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file() Jinjie Ruan
@ 2023-10-05  8:21   ` Hans Verkuil
  0 siblings, 0 replies; 7+ messages in thread
From: Hans Verkuil @ 2023-10-05  8:21 UTC (permalink / raw)
  To: Jinjie Ruan, mchehab, ye.xingchen, linux-media

On 14/09/2023 05:50, Jinjie Ruan wrote:
> Since debugfs_create_file() returns ERR_PTR and never NULL, use IS_ERR() to
> check the return value.
> 
> Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/media/common/siano/smsdvb-debugfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c
> index e0beefd80d7b..16d3b9ab31c5 100644
> --- a/drivers/media/common/siano/smsdvb-debugfs.c
> +++ b/drivers/media/common/siano/smsdvb-debugfs.c
> @@ -369,7 +369,7 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client)
>  
>  	d = debugfs_create_file("stats", S_IRUGO | S_IWUSR, client->debugfs,
>  				client, &debugfs_stats_ops);
> -	if (!d) {
> +	if (IS_ERR(d)) {
>  		debugfs_remove(client->debugfs);
>  		return -ENOMEM;
>  	}

Actually, standard behavior is not to check the error at all. It is not
considered a bug if creating a debugfs directory fails, you can just continue.

So rather than 'fixing' this, just drop the error check completely.

See e.g. commit 8c23f411296e ("media: sti: no need to check return value of
debugfs_create functions").

Regards,

	Hans


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [DKIM] [PATCH 2/2] media: siano: Fix the missing err path in smsdvb_debugfs_create()
  2023-09-14  3:50 ` [PATCH 2/2] media: siano: Fix the missing err path in smsdvb_debugfs_create() Jinjie Ruan
@ 2023-10-05  8:30   ` Hans Verkuil
  2023-10-07 11:10     ` Ruan Jinjie
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Verkuil @ 2023-10-05  8:30 UTC (permalink / raw)
  To: Jinjie Ruan, mchehab, ye.xingchen, linux-media

On 14/09/2023 05:50, Jinjie Ruan wrote:
> If kzalloc() fails in smsdvb_debugfs_create(), the dir and file which
> is created by debugfs_create_dir() and debugfs_create_file() is
> not freed. So use debugfs_remove_recursive() to free them.
> 
> Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/media/common/siano/smsdvb-debugfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c
> index 16d3b9ab31c5..38b25e88ce57 100644
> --- a/drivers/media/common/siano/smsdvb-debugfs.c
> +++ b/drivers/media/common/siano/smsdvb-debugfs.c
> @@ -375,8 +375,10 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client)
>  	}
>  
>  	debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL);
> -	if (!debug_data)
> +	if (!debug_data) {
> +		debugfs_remove_recursive(client->debugfs);
>  		return -ENOMEM;
> +	}
>  
>  	client->debug_data        = debug_data;
>  	client->prt_dvb_stats     = smsdvb_print_dvb_stats;

It's much better to first allocate debug_data before calling debugfs_create_dir.

No need to clean anything up in that case.

You can also ignore any errors from debugfs_create_file.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [DKIM] [PATCH 2/2] media: siano: Fix the missing err path in smsdvb_debugfs_create()
  2023-10-05  8:30   ` [DKIM] " Hans Verkuil
@ 2023-10-07 11:10     ` Ruan Jinjie
  0 siblings, 0 replies; 7+ messages in thread
From: Ruan Jinjie @ 2023-10-07 11:10 UTC (permalink / raw)
  To: Hans Verkuil, mchehab, ye.xingchen, linux-media



On 2023/10/5 16:30, Hans Verkuil wrote:
> On 14/09/2023 05:50, Jinjie Ruan wrote:
>> If kzalloc() fails in smsdvb_debugfs_create(), the dir and file which
>> is created by debugfs_create_dir() and debugfs_create_file() is
>> not freed. So use debugfs_remove_recursive() to free them.
>>
>> Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file")
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>>  drivers/media/common/siano/smsdvb-debugfs.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c
>> index 16d3b9ab31c5..38b25e88ce57 100644
>> --- a/drivers/media/common/siano/smsdvb-debugfs.c
>> +++ b/drivers/media/common/siano/smsdvb-debugfs.c
>> @@ -375,8 +375,10 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client)
>>  	}
>>  
>>  	debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL);
>> -	if (!debug_data)
>> +	if (!debug_data) {
>> +		debugfs_remove_recursive(client->debugfs);
>>  		return -ENOMEM;
>> +	}
>>  
>>  	client->debug_data        = debug_data;
>>  	client->prt_dvb_stats     = smsdvb_print_dvb_stats;
> 
> It's much better to first allocate debug_data before calling debugfs_create_dir.

Right! After that the code will be more cleaner.

> 
> No need to clean anything up in that case.
> 
> You can also ignore any errors from debugfs_create_file.
> 
> Regards,
> 
> 	Hans
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-10-07 11:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14  3:50 [PATCH 0/2] media: siano: Fix two bugs in smsdvb_debugfs_create() Jinjie Ruan
2023-09-14  3:50 ` [PATCH 1/2] media: siano: Fix the NULL vs IS_ERR() bug for debugfs_create_file() Jinjie Ruan
2023-10-05  8:21   ` [DKIM] " Hans Verkuil
2023-09-14  3:50 ` [PATCH 2/2] media: siano: Fix the missing err path in smsdvb_debugfs_create() Jinjie Ruan
2023-10-05  8:30   ` [DKIM] " Hans Verkuil
2023-10-07 11:10     ` Ruan Jinjie
2023-09-28  1:24 ` [PATCH 0/2] media: siano: Fix two bugs " Ruan Jinjie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.