On Tue, Mar 2, 2021 at 4:22 PM Joe Perches <[email protected]> wrote:
>
> Here is a possible opportunity to reduce data usage in the kernel.
>
> $ git grep -P -n '^static\s+(?!const|struct)(?:\w+\s+){1,3}\w+\s*\[\s*\]'
> drivers/ | \
> grep -v __initdata | \
> wc -l
> 3250
>
> Meaning there are ~3000 declarations of arrays with what appears to be
> file static const content that are not marked const.
>
> So there are many static arrays that could be marked const to move the
> compiled object code from data to text minimizing the total amount of
> exposed r/w data.
>
> However, I do not know of a mechanism using coccinelle to determine
> whether or not any of these static declarations are ever modified.
I thought it would be a fun exercise but it got tedious quick.
I don't know how to ignore an attribute like __initdata.
Feel free to refine it:
@@
type t;
identifier x;
@@
(
static const struct { ... } x[];
|
static
+ const
struct { ... } x[];
|
static const struct s *x[];
|
static
+ const
struct s *x[];
|
static const struct s x[];
|
static
+ const
struct s x[];
|
static const t *x[];
|
static
+ const
t *x[];
|
static const t x[];
|
static
+ const
t x[];
)
@@
type t;
identifier s, x, y, z;
assignment operator xx;
@@
(
static const struct { ... } x[] = { ... };
|
static
+ const
struct { ... } x[] = { ... };
|
static const struct s *x[] = { ... };
|
static
+ const
struct s *x[] = { ... };
|
static const struct s x[] = { ... };
|
static
+ const
struct s x[] = { ... };
|
static const t *x[] = { ... };
|
static
+ const
t *x[] = { ... };
|
static const t x[] = { ... };
|
static
+ const
t x[] = { ... };
)
... when != x.y xx ...
when != x[...] xx ...
when != z = x
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci