linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] locking/lock_events: no need to check return value of debugfs_create functions
@ 2020-11-07  9:19 Tiezhu Yang
  2020-11-09  8:32 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Tiezhu Yang @ 2020-11-07  9:19 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon; +Cc: linux-kernel, Xuefeng Li

When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 kernel/locking/lock_events.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/kernel/locking/lock_events.c b/kernel/locking/lock_events.c
index fa2c2f9..bac77a1 100644
--- a/kernel/locking/lock_events.c
+++ b/kernel/locking/lock_events.c
@@ -146,9 +146,6 @@ static int __init init_lockevent_counts(void)
 	struct dentry *d_counts = debugfs_create_dir(LOCK_EVENTS_DIR, NULL);
 	int i;
 
-	if (!d_counts)
-		goto out;
-
 	/*
 	 * Create the debugfs files
 	 *
@@ -159,21 +156,13 @@ static int __init init_lockevent_counts(void)
 	for (i = 0; i < lockevent_num; i++) {
 		if (skip_lockevent(lockevent_names[i]))
 			continue;
-		if (!debugfs_create_file(lockevent_names[i], 0400, d_counts,
-					 (void *)(long)i, &fops_lockevent))
-			goto fail_undo;
+		debugfs_create_file(lockevent_names[i], 0400, d_counts,
+				    (void *)(long)i, &fops_lockevent);
 	}
 
-	if (!debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200,
-				 d_counts, (void *)(long)LOCKEVENT_reset_cnts,
-				 &fops_lockevent))
-		goto fail_undo;
+	debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200, d_counts,
+			    (void *)(long)LOCKEVENT_reset_cnts, &fops_lockevent);
 
 	return 0;
-fail_undo:
-	debugfs_remove_recursive(d_counts);
-out:
-	pr_warn("Could not create '%s' debugfs entries\n", LOCK_EVENTS_DIR);
-	return -ENOMEM;
 }
 fs_initcall(init_lockevent_counts);
-- 
2.1.0


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

* Re: [PATCH] locking/lock_events: no need to check return value of debugfs_create functions
  2020-11-07  9:19 [PATCH] locking/lock_events: no need to check return value of debugfs_create functions Tiezhu Yang
@ 2020-11-09  8:32 ` Peter Zijlstra
  2020-11-09  9:51   ` Tiezhu Yang
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2020-11-09  8:32 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Ingo Molnar, Will Deacon, linux-kernel, Xuefeng Li, Greg Kroah-Hartman

On Sat, Nov 07, 2020 at 05:19:13PM +0800, Tiezhu Yang wrote:
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.

I strongly disagree and have told this to Greg before. Having half a
debug interface is weird at best, so upon failure we remove the whole
thing, which is consistent.

> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  kernel/locking/lock_events.c | 19 ++++---------------
>  1 file changed, 4 insertions(+), 15 deletions(-)
> 
> diff --git a/kernel/locking/lock_events.c b/kernel/locking/lock_events.c
> index fa2c2f9..bac77a1 100644
> --- a/kernel/locking/lock_events.c
> +++ b/kernel/locking/lock_events.c
> @@ -146,9 +146,6 @@ static int __init init_lockevent_counts(void)
>  	struct dentry *d_counts = debugfs_create_dir(LOCK_EVENTS_DIR, NULL);
>  	int i;
>  
> -	if (!d_counts)
> -		goto out;
> -
>  	/*
>  	 * Create the debugfs files
>  	 *
> @@ -159,21 +156,13 @@ static int __init init_lockevent_counts(void)
>  	for (i = 0; i < lockevent_num; i++) {
>  		if (skip_lockevent(lockevent_names[i]))
>  			continue;
> -		if (!debugfs_create_file(lockevent_names[i], 0400, d_counts,
> -					 (void *)(long)i, &fops_lockevent))
> -			goto fail_undo;
> +		debugfs_create_file(lockevent_names[i], 0400, d_counts,
> +				    (void *)(long)i, &fops_lockevent);
>  	}
>  
> -	if (!debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200,
> -				 d_counts, (void *)(long)LOCKEVENT_reset_cnts,
> -				 &fops_lockevent))
> -		goto fail_undo;
> +	debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200, d_counts,
> +			    (void *)(long)LOCKEVENT_reset_cnts, &fops_lockevent);
>  
>  	return 0;
> -fail_undo:
> -	debugfs_remove_recursive(d_counts);
> -out:
> -	pr_warn("Could not create '%s' debugfs entries\n", LOCK_EVENTS_DIR);
> -	return -ENOMEM;
>  }
>  fs_initcall(init_lockevent_counts);
> -- 
> 2.1.0
> 

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

* Re: [PATCH] locking/lock_events: no need to check return value of debugfs_create functions
  2020-11-09  8:32 ` Peter Zijlstra
@ 2020-11-09  9:51   ` Tiezhu Yang
  2020-11-09 10:04     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Tiezhu Yang @ 2020-11-09  9:51 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Will Deacon, linux-kernel, Xuefeng Li, Greg Kroah-Hartman

On 11/09/2020 04:32 PM, Peter Zijlstra wrote:
> On Sat, Nov 07, 2020 at 05:19:13PM +0800, Tiezhu Yang wrote:
>> When calling debugfs functions, there is no need to ever check the
>> return value.  The function can work or not, but the code logic should
>> never do something different based on this.
> I strongly disagree and have told this to Greg before. Having half a
> debug interface is weird at best, so upon failure we remove the whole
> thing, which is consistent.

Hi Peter,

Thanks for your reply.

I find the early discussion and see the following opinion by Greg:

https://lore.kernel.org/patchwork/patch/1290162/

[ For debugfs, this isn't an issue, what can a user do with something like
"debugfs isn't working?  What does that mean???"

And if we _really_ want warnings like this, it should go into the
debugfs core, not require this to be done for every debugfs user, right?

debugfs is just there for kernel developers to help debug things, it's
not a dependancy on any userspace functionality, so if it works or not
should not be an issue for any user.

Unless that user is a kernel developer of course :)

thanks,

greg k-h ]

Anyway, if this patch is meaningless after discussion, please ignore it.

Thanks,
Tiezhu

>
>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>> ---
>>   kernel/locking/lock_events.c | 19 ++++---------------
>>   1 file changed, 4 insertions(+), 15 deletions(-)
>>
>> diff --git a/kernel/locking/lock_events.c b/kernel/locking/lock_events.c
>> index fa2c2f9..bac77a1 100644
>> --- a/kernel/locking/lock_events.c
>> +++ b/kernel/locking/lock_events.c
>> @@ -146,9 +146,6 @@ static int __init init_lockevent_counts(void)
>>   	struct dentry *d_counts = debugfs_create_dir(LOCK_EVENTS_DIR, NULL);
>>   	int i;
>>   
>> -	if (!d_counts)
>> -		goto out;
>> -
>>   	/*
>>   	 * Create the debugfs files
>>   	 *
>> @@ -159,21 +156,13 @@ static int __init init_lockevent_counts(void)
>>   	for (i = 0; i < lockevent_num; i++) {
>>   		if (skip_lockevent(lockevent_names[i]))
>>   			continue;
>> -		if (!debugfs_create_file(lockevent_names[i], 0400, d_counts,
>> -					 (void *)(long)i, &fops_lockevent))
>> -			goto fail_undo;
>> +		debugfs_create_file(lockevent_names[i], 0400, d_counts,
>> +				    (void *)(long)i, &fops_lockevent);
>>   	}
>>   
>> -	if (!debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200,
>> -				 d_counts, (void *)(long)LOCKEVENT_reset_cnts,
>> -				 &fops_lockevent))
>> -		goto fail_undo;
>> +	debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200, d_counts,
>> +			    (void *)(long)LOCKEVENT_reset_cnts, &fops_lockevent);
>>   
>>   	return 0;
>> -fail_undo:
>> -	debugfs_remove_recursive(d_counts);
>> -out:
>> -	pr_warn("Could not create '%s' debugfs entries\n", LOCK_EVENTS_DIR);
>> -	return -ENOMEM;
>>   }
>>   fs_initcall(init_lockevent_counts);
>> -- 
>> 2.1.0
>>


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

* Re: [PATCH] locking/lock_events: no need to check return value of debugfs_create functions
  2020-11-09  9:51   ` Tiezhu Yang
@ 2020-11-09 10:04     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2020-11-09 10:04 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Peter Zijlstra, Ingo Molnar, Will Deacon, linux-kernel, Xuefeng Li

On Mon, Nov 09, 2020 at 05:51:56PM +0800, Tiezhu Yang wrote:
> On 11/09/2020 04:32 PM, Peter Zijlstra wrote:
> > On Sat, Nov 07, 2020 at 05:19:13PM +0800, Tiezhu Yang wrote:
> > > When calling debugfs functions, there is no need to ever check the
> > > return value.  The function can work or not, but the code logic should
> > > never do something different based on this.
> > I strongly disagree and have told this to Greg before. Having half a
> > debug interface is weird at best, so upon failure we remove the whole
> > thing, which is consistent.
> 
> Hi Peter,
> 
> Thanks for your reply.
> 
> I find the early discussion and see the following opinion by Greg:
> 
> https://lore.kernel.org/patchwork/patch/1290162/
> 
> [ For debugfs, this isn't an issue, what can a user do with something like
> "debugfs isn't working?  What does that mean???"
> 
> And if we _really_ want warnings like this, it should go into the
> debugfs core, not require this to be done for every debugfs user, right?

The debugfs core does spit out a warning when this happens, so no need
to duplicate it in your code as well.

And for subsystems that _really_ want to check this, that's fine, it's
the minority for the whole tree, but please, document it well with a
comment on the check so that it doesn't get "cleanup" patches sent for
it in the future.

thanks,

greg k-h

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

end of thread, other threads:[~2020-11-09 10:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-07  9:19 [PATCH] locking/lock_events: no need to check return value of debugfs_create functions Tiezhu Yang
2020-11-09  8:32 ` Peter Zijlstra
2020-11-09  9:51   ` Tiezhu Yang
2020-11-09 10:04     ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).