Re: [PATCH v2] perf/profile: Remove unused local variable err

From: Andrew Morton

Date: Wed Nov 04 2026 - 03:02:15 EST


On Wed, 4 Nov 2026 15:14:02 +0800 Yongxin Yang <yangyongxin@xxxxxxxxxx> 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.