2017-12-13 03:56:31

by Stephen Rothwell

[permalink] [raw]
Subject: linux-next: build warning after merge of the cgroup tree

Hi Tejun,

After merging the cgroup tree, today's linux-next build (arm
multi_v7_defconfig) produced this warning:

kernel/cgroup/cgroup.c: In function 'init_cgroup_root':
kernel/cgroup/cgroup.c:1867:3: warning: ignoring return value of 'strscpy', declared with attribute warn_unused_result [-Wunused-result]
strscpy(root->release_agent_path, opts->release_agent, PATH_MAX);
^
kernel/cgroup/cgroup.c:1869:3: warning: ignoring return value of 'strscpy', declared with attribute warn_unused_result [-Wunused-result]
strscpy(root->name, opts->name, MAX_CGROUP_ROOT_NAMELEN);
^
kernel/cgroup/cgroup.c: In function 'cgroup_file_name':
kernel/cgroup/cgroup.c:1400:3: warning: ignoring return value of 'strscpy', declared with attribute warn_unused_result [-Wunused-result]
strscpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
^

Introduced by commit

e7fd37ba1217 ("cgroup: avoid copying strings longer than the buffers")

--
Cheers,
Stephen Rothwell


2017-12-15 09:58:09

by Arnd Bergmann

[permalink] [raw]
Subject: Re: linux-next: build warning after merge of the cgroup tree

On Wed, Dec 13, 2017 at 4:56 AM, Stephen Rothwell <[email protected]> wrote:
> Hi Tejun,
>
> After merging the cgroup tree, today's linux-next build (arm
> multi_v7_defconfig) produced this warning:
>
> kernel/cgroup/cgroup.c: In function 'init_cgroup_root':
> kernel/cgroup/cgroup.c:1867:3: warning: ignoring return value of 'strscpy', declared with attribute warn_unused_result [-Wunused-result]
> strscpy(root->release_agent_path, opts->release_agent, PATH_MAX);
> ^
> kernel/cgroup/cgroup.c:1869:3: warning: ignoring return value of 'strscpy', declared with attribute warn_unused_result [-Wunused-result]
> strscpy(root->name, opts->name, MAX_CGROUP_ROOT_NAMELEN);
> ^
> kernel/cgroup/cgroup.c: In function 'cgroup_file_name':
> kernel/cgroup/cgroup.c:1400:3: warning: ignoring return value of 'strscpy', declared with attribute warn_unused_result [-Wunused-result]
> strscpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
> ^
>
> Introduced by commit
>
> e7fd37ba1217 ("cgroup: avoid copying strings longer than the buffers")

As long as cft->name is guaranteed to be NUL-terminated, using strlcpy() would
work just as well and avoid that warning, so the change below could be folded
into that commit.

Signed-off-by: Arnd Bergmann <[email protected]>

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index dc442a5d88b9..3cced1259cd3 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1397,7 +1397,7 @@ static char *cgroup_file_name(struct cgroup
*cgrp, const struct cftype *cft,
cgroup_on_dfl(cgrp) ? ss->name : ss->legacy_name,
cft->name);
else
- strscpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
+ strlcpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
return buf;
}

@@ -1874,9 +1874,9 @@ void init_cgroup_root(struct cgroup_root *root,
struct cgroup_sb_opts *opts)

root->flags = opts->flags;
if (opts->release_agent)
- strscpy(root->release_agent_path, opts->release_agent,
PATH_MAX);
+ strlcpy(root->release_agent_path, opts->release_agent,
PATH_MAX);
if (opts->name)
- strscpy(root->name, opts->name, MAX_CGROUP_ROOT_NAMELEN);
+ strlcpy(root->name, opts->name, MAX_CGROUP_ROOT_NAMELEN);
if (opts->cpuset_clone_children)
set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags);
}

2017-12-15 13:10:48

by Tejun Heo

[permalink] [raw]
Subject: Re: linux-next: build warning after merge of the cgroup tree

On Fri, Dec 15, 2017 at 10:58:04AM +0100, Arnd Bergmann wrote:
> As long as cft->name is guaranteed to be NUL-terminated, using strlcpy() would
> work just as well and avoid that warning, so the change below could be folded
> into that commit.
>
> Signed-off-by: Arnd Bergmann <[email protected]>

Applied to cgroup/for-4.15-fixes. Sorry about not responding sooner.

Thanks.

--
tejun

2023-07-11 01:40:34

by Tejun Heo

[permalink] [raw]
Subject: Re: linux-next: build warning after merge of the cgroup tree

On Tue, Jul 11, 2023 at 11:15:09AM +1000, Stephen Rothwell wrote:
> Hi all,
>
> After merging the cgroup tree, today's linux-next build (arm
> multi_v7_defconfig) produced this warning:
>
> kernel/cgroup/cgroup.c:503:36: warning: 'cgroup_tryget_css' defined but not used [-Wunused-function]
> 503 | static struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp,
> | ^~~~~~~~~~~~~~~~~
>
> Introduced by commit
>
> 1299eb2b0ad5 ("cgroup: minor cleanup for cgroup_extra_stat_show()")

Miaohe, can you send a patch to either add __maybe_unused to
cgroup_tryget_css() or also put it inside CONFIG_CGROUP_SCHED?

Thanks.

--
tejun

2023-07-11 02:33:49

by Miaohe Lin

[permalink] [raw]
Subject: Re: linux-next: build warning after merge of the cgroup tree

On 2023/7/11 9:22, Tejun Heo wrote:
> On Tue, Jul 11, 2023 at 11:15:09AM +1000, Stephen Rothwell wrote:
>> Hi all,
>>
>> After merging the cgroup tree, today's linux-next build (arm
>> multi_v7_defconfig) produced this warning:
>>
>> kernel/cgroup/cgroup.c:503:36: warning: 'cgroup_tryget_css' defined but not used [-Wunused-function]
>> 503 | static struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp,
>> | ^~~~~~~~~~~~~~~~~
>>
>> Introduced by commit
>>
>> 1299eb2b0ad5 ("cgroup: minor cleanup for cgroup_extra_stat_show()")
>
> Miaohe, can you send a patch to either add __maybe_unused to
> cgroup_tryget_css() or also put it inside CONFIG_CGROUP_SCHED?

Will do. Sorry for my mistake.

Thanks.