]> git.baikalelectronics.ru Git - kernel.git/commit
string: drop __must_check from strscpy() and restore strscpy() usages in cgroup
authorTejun Heo <tj@kernel.org>
Tue, 9 Jan 2018 15:21:15 +0000 (07:21 -0800)
committerTejun Heo <tj@kernel.org>
Fri, 19 Jan 2018 16:51:36 +0000 (08:51 -0800)
commit0f5b8888d60ffef388d0ff1b9892eb0a27b4ac11
tree511ee5c7b8e1a7ed5a1a8f118c3042ee3d44e87c
parent9568fc8e85738450708c5cc638952ece6b355826
string: drop __must_check from strscpy() and restore strscpy() usages in cgroup

2220e75b8792 ("cgroup: avoid copying strings longer than the buffers")
converted possibly unsafe strncpy() usages in cgroup to strscpy().
However, although the callsites are completely fine with truncated
copied, because strscpy() is marked __must_check, it led to the
following warnings.

  kernel/cgroup/cgroup.c: In function ‘cgroup_file_name’:
  kernel/cgroup/cgroup.c:1400:10: warning: ignoring return value of ‘strscpy’, declared with attribute warn_unused_result [-Wunused-result]
     strscpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
       ^

To avoid the warnings, c91fd8cfa78a ("cgroup: use strlcpy() instead of
strscpy() to avoid spurious warning") switched them to strlcpy().

strlcpy() is worse than strlcpy() because it unconditionally runs
strlen() on the source string, and the only reason we switched to
strlcpy() here was because it was lacking __must_check, which doesn't
reflect any material differences between the two function.  It's just
that someone added __must_check to strscpy() and not to strlcpy().

These basic string copy operations are used in variety of ways, and
one of not-so-uncommon use cases is safely handling truncated copies,
where the caller naturally doesn't care about the return value.  The
__must_check doesn't match the actual use cases and forces users to
opt for inferior variants which lack __must_check by happenstance or
spread ugly (void) casts.

Remove __must_check from strscpy() and restore strscpy() usages in
cgroup.

Signed-off-by: Tejun Heo <tj@kernel.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
include/linux/string.h
kernel/cgroup/cgroup.c