Re: [Cocci] matching a modified identifier?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Mon, 6 Feb 2017, Johannes Berg wrote:

> Hi,
>
> In backports, we have the following spatch:
>
> @ attribute_group @
> identifier group;
> declarer name ATTRIBUTE_GROUPS;
> @@
>
> ATTRIBUTE_GROUPS(group);
>
> @ class_group depends on attribute_group @
> identifier group_class;
> identifier groups;
> fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
> @@
>
> struct class group_class = {
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
>         .dev_groups = groups,
> +#else
> +       .dev_attrs = group_dev_attr,
> +#endif
> };
>
> [...]
>
>
>
> But this isn't sufficient and falls over if there are multiple
> instances of ATTRIBUTE_GROUPS, it's essentially undefined which one
> gets picked.
>
> I tried to match a modified identifier like this:
>
> @ attribute_group @
> identifier group;
> fresh identifier groups = group ## "_groups";
> declarer name ATTRIBUTE_GROUPS;
> @@
>
> ATTRIBUTE_GROUPS(group);
>
> @ class_group depends on attribute_group @
> identifier group_class;
> identifier attribute_group.groups;
> fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
> @@
>
> struct class group_class = {
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
>         .dev_groups = groups,
> +#else
> +       .dev_attrs = group_dev_attr,
> +#endif
> };
>
> [...]
>
>
> but that doesn't work at all.

Use python between the two rules to construct the identifier you want.
You can see examples in coccinelle/demos/pythontococci.cocci

julia

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux