public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] smsdvb-debugfs.c: Fix error checking for debugfs_create_file
@ 2023-05-24 16:42 Osama Muhammad
  2023-05-26 10:53 ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 3+ messages in thread
From: Osama Muhammad @ 2023-05-24 16:42 UTC (permalink / raw)
  To: mchehab; +Cc: linux-media, linux-kernel, Osama Muhammad

This patch fixes the error checking in smsdvb-debugfs.c in
debugfs_create_file. The correct way to check if an error occurred
is using 'IS_ERR_OR_NULL' inline function.

Signed-off-by: Osama Muhammad <osmtendev@gmail.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 8916bb644756..0f8750d7993c 100644
--- a/drivers/media/common/siano/smsdvb-debugfs.c
+++ b/drivers/media/common/siano/smsdvb-debugfs.c
@@ -469,7 +469,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_OR_NULL(d)) {
 		debugfs_remove(client->debugfs);
 		return -ENOMEM;
 	}
-- 
2.34.1


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

* Re: [PATCH] smsdvb-debugfs.c: Fix error checking for debugfs_create_file
  2023-05-24 16:42 [PATCH] smsdvb-debugfs.c: Fix error checking for debugfs_create_file Osama Muhammad
@ 2023-05-26 10:53 ` Mauro Carvalho Chehab
  2023-05-28 15:12   ` Osama Muhammad
  0 siblings, 1 reply; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2023-05-26 10:53 UTC (permalink / raw)
  To: Osama Muhammad; +Cc: linux-media, linux-kernel

Em Wed, 24 May 2023 21:42:10 +0500
Osama Muhammad <osmtendev@gmail.com> escreveu:

> This patch fixes the error checking in smsdvb-debugfs.c in
> debugfs_create_file. The correct way to check if an error occurred
> is using 'IS_ERR_OR_NULL' inline function.
> 
> Signed-off-by: Osama Muhammad <osmtendev@gmail.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 8916bb644756..0f8750d7993c 100644
> --- a/drivers/media/common/siano/smsdvb-debugfs.c
> +++ b/drivers/media/common/siano/smsdvb-debugfs.c
> @@ -469,7 +469,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_OR_NULL(d)) {
>  		debugfs_remove(client->debugfs);
>  		return -ENOMEM;

if IS_ERR, it is probably better to return PTR_ERR(d).

So, please change it accordingly, returning -ENOMEM only on NULL, e. g.
something like (untested):

	if (IS_ERR_OR_NULL(d)) {
 		debugfs_remove(client->debugfs);
		if (!d)
	  		return -ENOMEM;
		return PTR_ERR(d);
	}

Regards,
Mauro

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

* Re: [PATCH] smsdvb-debugfs.c: Fix error checking for debugfs_create_file
  2023-05-26 10:53 ` Mauro Carvalho Chehab
@ 2023-05-28 15:12   ` Osama Muhammad
  0 siblings, 0 replies; 3+ messages in thread
From: Osama Muhammad @ 2023-05-28 15:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media, linux-kernel

Hi,

After researching more into it I have come to know that the debugfs
API will not return null on error but an ERR_PTR. The modern wisdom
about it is to ignore the errors returned by the function as stated in
the comment  above the function debugfs_create_file.

> * NOTE: it's expected that most callers should _ignore_ the errors returned
 >* by this function. Other debugfs functions handle the fact that the "dentry"
 >* passed to them could be an error and they don't crash in that case.
> * Drivers should generally work fine even if debugfs fails to init anyway.
Here is the link to comment :-
https://elixir.bootlin.com/linux/latest/source/fs/debugfs/inode.c#L451

Considering this, I will send the revision of the patch by removing
error checks. Please correct me if  there are any concerns with this.

Thanks,
Osmten



On Fri, 26 May 2023 at 15:53, Mauro Carvalho Chehab <mchehab@kernel.org> wrote:
>
> Em Wed, 24 May 2023 21:42:10 +0500
> Osama Muhammad <osmtendev@gmail.com> escreveu:
>
> > This patch fixes the error checking in smsdvb-debugfs.c in
> > debugfs_create_file. The correct way to check if an error occurred
> > is using 'IS_ERR_OR_NULL' inline function.
> >
> > Signed-off-by: Osama Muhammad <osmtendev@gmail.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 8916bb644756..0f8750d7993c 100644
> > --- a/drivers/media/common/siano/smsdvb-debugfs.c
> > +++ b/drivers/media/common/siano/smsdvb-debugfs.c
> > @@ -469,7 +469,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_OR_NULL(d)) {
> >               debugfs_remove(client->debugfs);
> >               return -ENOMEM;
>
> if IS_ERR, it is probably better to return PTR_ERR(d).
>
> So, please change it accordingly, returning -ENOMEM only on NULL, e. g.
> something like (untested):
>
>         if (IS_ERR_OR_NULL(d)) {
>                 debugfs_remove(client->debugfs);
>                 if (!d)
>                         return -ENOMEM;
>                 return PTR_ERR(d);
>         }
>
> Regards,
> Mauro

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

end of thread, other threads:[~2023-05-28 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-24 16:42 [PATCH] smsdvb-debugfs.c: Fix error checking for debugfs_create_file Osama Muhammad
2023-05-26 10:53 ` Mauro Carvalho Chehab
2023-05-28 15:12   ` Osama Muhammad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox