lib/string_helpers: add linux/string.h for strlen()
Subsystems (4)
PATCH 1/1 lib/string_helpers: add linux/string.h for strlen()
linux/string_helpers.h uses strlen(), so include the correpondent header. Otherwise we get a compilation error if it's not also included by whoever included the helper.
--- include/linux/string_helpers.h | 1 + 1 file changed, 1 insertion(+)
include/linux/string_helpers.h +1 -0
@@ -4,6 +4,7 @@#include <linux/bits.h> #include <linux/ctype.h> +#include <linux/string.h> #include <linux/types.h> struct file ;
Signature · 1 line
2.33.0
Quoted 3 lines · On Tue, 5 Oct 2021 14:26:34 -0700 Lucas De Marchi <[email protected]>…
linux/string_helpers.husesstrlen(), so include the correpondent header. Otherwise we get a compilation error if it's not also included by whoever included the helper.
Is such a compilation error demonstrable in the current mainline kernel?
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Tue, 5 Oct 2021 14:26:34 -0700 Lucas De Marchi <[email protected]>…
linux/string_helpers.husesstrlen(), so include the correpondent header. Otherwise we get a compilation error if it's not also included by whoever included the helper.Is such a compilation error demonstrable in the current mainline kernel?
No, not with the current mainline. I was just starting to implement some more helpers there and noticed the issue when including this header from i915. Then I noticed Andy and Jani already had similar patches to what I was doing:
https://lore.kernel.org/all/[email protected]/
and https://lore.kernel.org/all/[email protected]/
So I'm following up on the first thread abovee to figure out what would be the proper header to implement this. Meanwhile, we can have this quick harmless fix.
thanks,
Lucas De Marchi
A message that is not in the archive (sent off-list or not yet received): CAHp75VfT+dSNYSntj9O5a9NVGnbf_raxWLiS7ciDMe-kRL-+=A@mail.gmail.com
Quoted 19 lines · Andy Shevchenko
Quoted 16 lines · Lucas De Marchi
linux/string_helpers.husesstrlen(), so include the correpondent header. Otherwise we get a compilation error if it's not also included by whoever included the helper.Signed-off-by Lucas De Marchi <[email protected]>--- include/linux/string_helpers.h | 1 + 1 file changed, 1 insertion(+)include/linux/string_ renamed from include/linux/string_helpers.h +0
-0
helpers.h
index68189c4a2eb1..4ba39e1403b2100644include/linux/string_helpers.h +0
-0@@ -4,6 +4,7 @@
Quoted 8 lines
include/linux/string_helpers.h line 8
Quoted 4 lines
include/linux/string_helpers.h +1
-0#include <linux/bits.h> #include <linux/ctype.h> +#include <linux/string.h> #include <linux/types.h> I’m afraid this potentially can add into header dependencies hell. What about moving the user to the C file?
I can do that, but I don't see the problem here... afaics it has been like this for 7 years, since commit c8250381c827 ("lib / string_helpers: introduce string_escape_mem()"), and the only way it was never borken is becauselinux/string.h is already being indirectly included from other headers.
So just adding it here is harmless.
I reproduced this while following the normal header order in i915 and adding linux/string_helpers.h like this:
drivers/gpu/drm/i915/display/intel_display_debugfs.c +2 -0
@@ -3,6 +3,8 @@* Copyright © 2020 Intel Corporation */ +#include <linux/string_helpers.h> +#include <drm/drm_debugfs.h> #include <drm/drm_fourcc.h>
Note that this became the first header included, producing the following error:
make -j$(nproc) drivers/gpu/drm/i915/display/intel_display_debugfs.o
DESCEND objtool
CALL scripts/atomic/check-atomics.sh CALL scripts/checksyscalls.sh CC [M] drivers/gpu/drm/i915/display/intel_display_debugfs.o
In file included from drivers/gpu/drm/i915/display/intel_display_debugfs.c:6:./include/linux/string_helpers.h: In function ‘string_escape_str’:./include/linux/string_helpers.h:75:32: error: implicit declaration of function ‘strlen’ [-Werror=implicit-function-declaration]
75 | return string_escape_mem(src, strlen(src), dst, sz, flags, only);
| ^~~~~~./include/linux/string_helpers.h:75:32: error: incompatible implicit declaration of built-in function ‘strlen’ [-Werror] ./include/linux/string_helpers.h:7:1: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
6 | #include <linux/ctype.h>
+++ |+#include <string.h>
7 | #include <linux/types.h>cc1: all warnings being treated as errors
Anyway, if it's preferable to move these functions out of line, I can do so.
thanks
Lucas De Marchi
Quoted 12 lines
Quoted 8 lines
include/linux/string_helpers.h +0
-1struct file ; --2.33.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Lucas De Marchi
Quoted 4 lines · Andy Shevchenko
Quoted 1 line · Lucas De Marchi
linux/string_helpers.husesstrlen(), so include the correspondent
correspondent
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
header. Otherwise we get a compilation error if it's not also included by whoever included the helper.
...
Quoted 9 lines
Quoted 2 lines
I’m afraid this potentially can add into header dependencies hell. What about moving the user to the C file?
I can do that, but I don't see the problem here... afaics it has been like this for 7 years, since commit
c8250381c827("lib /string_helpers: introducestring_escape_mem()"), and the only way it was never borken is becauselinux/string.his already being indirectly included from other headers.So just adding it here is harmless.
Quite possible.
...
Quoted 2 lines
Anyway, if it's preferable to move these functions out of line, I can do so.
I have no strong opinion, whatever maintainers will decide then!
Signature · 2 lines
With Best Regards, Andy Shevchenko