Messages in this thread | | | Subject | Re: [RFC PATCH] checkpatch: Support __initconst combined with struct definition | From | Joe Perches <> | Date | Tue, 11 Apr 2023 18:53:42 -0700 |
| |
On Tue, 2023-04-11 at 16:38 +0300, Andy Shevchenko wrote: > On Wed, Mar 01, 2023 at 10:43:20AM +0100, Björn Töpel wrote: > > From: Björn Töpel <bjorn@rivosinc.com> > > > > Checkpatch sometimes report a false positive for __initconst. E.g., for the > > following snippet: > > > > | static const struct strspn_test { > > | const char str[16]; > > | const char accept[16]; > > | const char reject[16]; > > | unsigned a; > > | unsigned r; > > | } tests[] __initconst = { > > | { "foobar", "", "", 0, 6 }, > > | { "abba", "abc", "ABBA", 4, 4 }, > > | { "abba", "a", "b", 1, 1 }, > > | { "", "abc", "abc", 0, 0}, > > | }; > > > > checkpatch would report: > > > > | ERROR: Use of __initconst requires a separate use of const > > | #190: FILE: ./test_string.c:190: > > | + } tests[] __initconst = { > > > > Improve the reporting by trying harder to find the 'const'. > > Joe, what do you think about this?
I think the ctx_block_outer_rev function doesn't handle patch context blocks and the loop at best needs to be changed to include
last if $rawlines[$line] =~ /^@/);.
And the loop parsing couldn't handle structs with embedded unions or structs.
I also think that checkpatch will always have false negatives and false positives and this might not be that useful as likely most compilers should now be able to identify this as well.
| |