selftests/bpf: Fix a testmod compilation failure due to missing const modifier
Subsystems (4)
Yonghong Song
reviewerPATCH 1/1 selftests/bpf: Fix a testmod compilation failure due to missing const modifier
Commit 97d06802d10a ("sysfs: constify bin_attribute argument of bin_attribute::read/write()") added constant modifier to 'struct bin_attribute *' for read/write
func pointer members. This caused compilation failure with clang20:
bpf_testmod.c:494:10: error: incompatible function pointer types initializing
'ssize_t (*)(struct file *, struct kobject *, const struct bin_attribute *, char *, loff_t, size_t)' (aka 'long (*)(struct file *, struct kobject *, const struct bin_attribute *,
char *, long long, unsigned long)')
with an expression of type 'ssize_t (struct file *, struct kobject *, struct bin_attribute *,
char *, loff_t, size_t)'
(aka 'long (struct file *, struct kobject *, struct bin_attribute *, char *, long long, unsigned long)')
[-Wincompatible-function-pointer-types]
494 | .read = bpf_testmod_test_read,
| ^~~~~~~~~~~~~~~~~~~~~...
The same compilation error for functions bpf_testmod_test_write() and bpf_testmod_uprobe_write().
Fix the build failure by adding proper 'const' modifier.
--- tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +3 -3
@@ -385,7 +385,7 @@ int bpf_testmod_fentry_ok; noinline ssize_tbpf_testmod_test_read (struct file *file,struct kobject *kobj, -struct bin_attribute *bin_attr, +const struct bin_attribute *bin_attr,char *buf,loff_t off,size_t len) {struct bpf_testmod_test_read_ctx ctx = {
@@ -465,7 +465,7 @@ ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO); noinline ssize_tbpf_testmod_test_write (struct file *file,struct kobject *kobj, -struct bin_attribute *bin_attr, +const struct bin_attribute *bin_attr,char *buf,loff_t off,size_t len) {struct bpf_testmod_test_write_ctx ctx = {
@@ -567,7 +567,7 @@ static void testmod_unregister_uprobe(void)static ssize_t bpf_testmod_uprobe_write (struct file *file,struct kobject *kobj, -struct bin_attribute *bin_attr, +const struct bin_attribute *bin_attr,char *buf,loff_t off,size_t len) {unsigned long offset =0 ;
Signature · 1 line
2.47.1
Quoted 15 lines · Yonghong Song
Commit
97d06802d10a("sysfs: constifybin_attributeargument of bin_attribute::read/write()") added constant modifier to 'structbin_attribute*' for read/write
func pointer members. This caused compilation failure with clang20:bpf_testmod.c:494:10: error: incompatible function pointer types initializing
'ssize_t(*)(struct file *, struct kobject *, const structbin_attribute*, char *,loff_t,size_t)' (aka 'long (*)(struct file *, struct kobject *, const structbin_attribute*,
char *, long long, unsigned long)')
with an expression of type 'ssize_t(struct file *, struct kobject *, structbin_attribute*,char *, loff_t, size_t)' (aka 'long (struct file *, struct kobject *, struct bin_attribute *, char *, long long, unsigned long)') [-Wincompatible-function-pointer-types] 494 | .read = bpf_testmod_test_read, | ^~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines
...
The same compilation error for functions
bpf_testmod_test_write()andbpf_testmod_uprobe_write().Fix the build failure by adding proper 'const' modifier.
Signed-off-by Yonghong Song <[email protected]>
I already applied similar patch to bpf tree couple hours ago.
Yonghong Song
reviewerQuoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Yonghong Song
Commit
97d06802d10a("sysfs: constifybin_attributeargument of bin_attribute::read/write()") added constant modifier to 'structbin_attribute*' for read/write
func pointer members. This caused compilation failure with clang20:bpf_testmod.c:494:10: error: incompatible function pointer types initializing
'ssize_t(*)(struct file *, struct kobject *, const structbin_attribute*, char *,loff_t,size_t)' (aka 'long (*)(struct file *, struct kobject *, const structbin_attribute*,
char *, long long, unsigned long)')
with an expression of type 'ssize_t(struct file *, struct kobject *, structbin_attribute*,char *, loff_t, size_t)' (aka 'long (struct file *, struct kobject *, struct bin_attribute *, char *, long long, unsigned long)') [-Wincompatible-function-pointer-types] 494 | .read = bpf_testmod_test_read, | ^~~~~~~~~~~~~~~~~~~~~...
Quoted 6 lines
Quoted 5 lines
The same compilation error for functions
bpf_testmod_test_write()andbpf_testmod_uprobe_write().Fix the build failure by adding proper 'const' modifier.
Signed-off-by Yonghong Song <[email protected]>I already applied similar patch to bpf tree couple hours ago.
Ok, sounds good. I only checked bpf-next tree.