mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf/profile: Remove unused local variable err
@ 2026-08-24  2:42 yang_yongxin123
  2026-08-24 10:01 ` Bradley Morgan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: yang_yongxin123 @ 2026-08-24  2:42 UTC (permalink / raw)
  Cc: linux-kernel, Yongxin Yang

From: Yongxin Yang <yangyongxin@kylinos.cn>

Variable err is declared but never used in this function.
Remove it to avoid compiler warning.

No functional change.

Signed-off-by: Yongxin Yang <yangyongxin@kylinos.cn>
---
 kernel/profile.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/profile.c b/kernel/profile.c
index 1fcf1adcf4eb..6f63e3a8d3fb 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -216,7 +216,6 @@ static const struct proc_ops profile_proc_ops = {
 int __ref create_proc_profile(void)
 {
 	struct proc_dir_entry *entry;
-	int err = 0;
 
 	if (!prof_on)
 		return 0;
@@ -224,7 +223,7 @@ int __ref create_proc_profile(void)
 			    NULL, &profile_proc_ops);
 	if (entry)
 		proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
-	return err;
+	return 0;
 }
 subsys_initcall(create_proc_profile);
 #endif /* CONFIG_PROC_FS */
-- 
2.25.1


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

* Re: [PATCH] perf/profile: Remove unused local variable err
  2026-08-24  2:42 [PATCH] perf/profile: Remove unused local variable err yang_yongxin123
@ 2026-08-24 10:01 ` Bradley Morgan
  2026-11-04  7:14 ` [PATCH v2] " Yongxin Yang
  2026-11-04  9:32 ` [PATCH v3] perf/profile: Report failure to create /proc/profile Yongxin Yang
  2 siblings, 0 replies; 5+ messages in thread
From: Bradley Morgan @ 2026-08-24 10:01 UTC (permalink / raw)
  To: yang_yongxin123; +Cc: linux-kernel, yangyongxin

On 24 August 2026 03:42:51 BST, yang_yongxin123@163.com wrote:
>From: Yongxin Yang <yangyongxin@kylinos.cn>
>
>Variable err is declared but never used in this function.
>Remove it to avoid compiler warning.
>
>No functional change.
>

Obviously correct

Reviewed-by: Bradley Morgan <include@grrlz.net>



>Signed-off-by: Yongxin Yang <yangyongxin@kylinos.cn>
>---
> kernel/profile.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
>diff --git a/kernel/profile.c b/kernel/profile.c
>index 1fcf1adcf4eb..6f63e3a8d3fb 100644
>--- a/kernel/profile.c
>+++ b/kernel/profile.c
>@@ -216,7 +216,6 @@ static const struct proc_ops profile_proc_ops = {
> int __ref create_proc_profile(void)
> {
> 	struct proc_dir_entry *entry;
>-	int err = 0;
> 
> 	if (!prof_on)
> 		return 0;
>@@ -224,7 +223,7 @@ int __ref create_proc_profile(void)
> 			    NULL, &profile_proc_ops);
> 	if (entry)
> 		proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
>-	return err;
>+	return 0;
> }
> subsys_initcall(create_proc_profile);
> #endif /* CONFIG_PROC_FS */
>

Thanks!

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

* [PATCH v2] perf/profile: Remove unused local variable err
  2026-08-24  2:42 [PATCH] perf/profile: Remove unused local variable err yang_yongxin123
  2026-08-24 10:01 ` Bradley Morgan
@ 2026-11-04  7:14 ` Yongxin Yang
  2026-11-04  7:58   ` Andrew Morton
  2026-11-04  9:32 ` [PATCH v3] perf/profile: Report failure to create /proc/profile Yongxin Yang
  2 siblings, 1 reply; 5+ messages in thread
From: Yongxin Yang @ 2026-11-04  7:14 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Bradley Morgan, linux-kernel

In create_proc_profile() the local variable err is only ever assigned 0 and
then returned, so it can never hold anything but 0.  Drop it and return 0
directly.

No functional change.

Reviewed-by: Bradley Morgan <include@grrlz.net>
Signed-off-by: Yongxin Yang <yangyongxin@kylinos.cn>
---
Link: https://lore.kernel.org/all/20260824024251.279751-1-yang_yongxin123@163.com/

Changes in v2:
- Rebased onto current mainline; the file has moved 24 lines since v1.
- Reword the changelog: err is read by the return statement, so there is no
  compiler warning to fix; the variable is simply always zero.
- Add Reviewed-by from Bradley Morgan, given on v1.

 kernel/profile.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/profile.c b/kernel/profile.c
index 13be6fc9fd00..2d3bef69d3be 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -240,7 +240,6 @@ static const struct proc_ops profile_proc_ops = {
 int __ref create_proc_profile(void)
 {
 	struct proc_dir_entry *entry;
-	int err = 0;
 
 	if (!prof_on)
 		return 0;
@@ -248,7 +247,7 @@ int __ref create_proc_profile(void)
 			    NULL, &profile_proc_ops);
 	if (entry)
 		proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
-	return err;
+	return 0;
 }
 subsys_initcall(create_proc_profile);
 #endif /* CONFIG_PROC_FS */
-- 
2.25.1


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

* Re: [PATCH v2] perf/profile: Remove unused local variable err
  2026-11-04  7:14 ` [PATCH v2] " Yongxin Yang
@ 2026-11-04  7:58   ` Andrew Morton
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-11-04  7:58 UTC (permalink / raw)
  To: Yongxin Yang; +Cc: Bradley Morgan, linux-kernel

On Wed,  4 Nov 2026 15:14:02 +0800 Yongxin Yang <yangyongxin@kylinos.cn> wrote:

> In create_proc_profile() the local variable err is only ever assigned 0 and
> then returned, so it can never hold anything but 0.  Drop it and return 0
> directly.
> 
> No functional change.
> 
> ...
>
> --- a/kernel/profile.c
> +++ b/kernel/profile.c
> @@ -240,7 +240,6 @@ static const struct proc_ops profile_proc_ops = {
>  int __ref create_proc_profile(void)
>  {
>  	struct proc_dir_entry *entry;
> -	int err = 0;
>  
>  	if (!prof_on)
>  		return 0;
> @@ -248,7 +247,7 @@ int __ref create_proc_profile(void)
>  			    NULL, &profile_proc_ops);
>  	if (entry)
>  		proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
> -	return err;
> +	return 0;
>  }

Well.  If proc_create() returned error (entry==NULL) then should
create_proc_profile() just drop that information on the floor and
pretend that everything worked?

Would it be better to return an error from create_proc_profile() in
this situation?  Doing that that would require auditing the caller's
handling of this and hoping that the caller reports the failure in an
appropriate fashion.  If not then reporting the error from within
create_proc_profile() would be better than simple silence.


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

* [PATCH v3] perf/profile: Report failure to create /proc/profile
  2026-08-24  2:42 [PATCH] perf/profile: Remove unused local variable err yang_yongxin123
  2026-08-24 10:01 ` Bradley Morgan
  2026-11-04  7:14 ` [PATCH v2] " Yongxin Yang
@ 2026-11-04  9:32 ` Yongxin Yang
  2 siblings, 0 replies; 5+ messages in thread
From: Yongxin Yang @ 2026-11-04  9:32 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Bradley Morgan, linux-kernel

create_proc_profile() discards the result of proc_create(): when the
entry cannot be created, the function still returns 0 and profiling
setup silently pretends to have succeeded.  The local variable err is
never assigned anything but 0 and only hides that.

Report the failure and return -ENOMEM instead.

create_proc_profile() is a subsys_initcall and do_initcall_level()
discards the initcall return value, so the error message is what the
user will actually see.

Signed-off-by: Yongxin Yang <yangyongxin@kylinos.cn>
---
Link: https://lore.kernel.org/all/20260824024251.279751-1-yang_yongxin123@163.com/

Changes in v3:
- Do not silently ignore a proc_create() failure: report it with pr_err()
  and return -ENOMEM, as suggested by Andrew Morton.  This is no longer a
  pure cleanup, so 'No functional change.' is dropped.
- Drop the Reviewed-by from Bradley Morgan: v3 changes the behaviour, so
  the tag no longer covers the code he reviewed on v1.  Bradley is Cc'd
  again for a fresh review.

 kernel/profile.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/profile.c b/kernel/profile.c
index 13be6fc9fd00..818098cc094a 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -240,15 +240,17 @@ static const struct proc_ops profile_proc_ops = {
 int __ref create_proc_profile(void)
 {
 	struct proc_dir_entry *entry;
-	int err = 0;
 
 	if (!prof_on)
 		return 0;
 	entry = proc_create("profile", S_IWUSR | S_IRUGO,
 			    NULL, &profile_proc_ops);
-	if (entry)
-		proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
-	return err;
+	if (!entry) {
+		pr_err("profile: failed to create /proc/profile\n");
+		return -ENOMEM;
+	}
+	proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
+	return 0;
 }
 subsys_initcall(create_proc_profile);
 #endif /* CONFIG_PROC_FS */
-- 
2.25.1


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

end of thread, other threads:[~2026-11-04  9:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-24  2:42 [PATCH] perf/profile: Remove unused local variable err yang_yongxin123
2026-08-24 10:01 ` Bradley Morgan
2026-11-04  7:14 ` [PATCH v2] " Yongxin Yang
2026-11-04  7:58   ` Andrew Morton
2026-11-04  9:32 ` [PATCH v3] perf/profile: Report failure to create /proc/profile Yongxin Yang

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®