matching a modified identifier?
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.
Any thoughts?
johannes
Quoted 8 lines
@
attribute_group@
identifier group;
fresh identifier groups = group ## "_groups";
declarer nameATTRIBUTE_GROUPS;
@@
ATTRIBUTE_GROUPS(group);
If I add a dummy here:
+ATTRIBUTE_GROUPS_NAME(groups);
Quoted 15 lines
@
class_groupdepends onattribute_group@ identifiergroup_class;
identifier attribute_group.groups;
fresh identifiergroup_dev_attr= attribute_group.group ## "_dev_attrs";
@@struct class
group_class= {
+#ifLINUX_VERSION_CODE>=KERNEL_VERSION(3,11,0)
????????.dev_groups = groups,(quoted diff) +3
-0+#else +???????.dev_attrs = group_dev_attr, +#endif};
Quoted 1 line
[...]
Then the whole thing works - I guess I can live with that.
johannes
Quoted 57 lines · Johannes Berg
Hi,
In backports, we have the following spatch:
@
attribute_group@
identifier group;
declarer nameATTRIBUTE_GROUPS;
@@
ATTRIBUTE_GROUPS(group);@
class_groupdepends onattribute_group@
identifiergroup_class;
identifier groups;
fresh identifiergroup_dev_attr= attribute_group.group ## "_dev_attrs"; @@struct class
group_class= {
+#ifLINUX_VERSION_CODE>=KERNEL_VERSION(3,11,0)
????????.dev_groups = groups,(quoted diff) +3
-0+#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 nameATTRIBUTE_GROUPS;
@@
ATTRIBUTE_GROUPS(group);@
class_groupdepends onattribute_group@
identifiergroup_class;
identifier attribute_group.groups;
fresh identifiergroup_dev_attr= attribute_group.group ## "_dev_attrs"; @@struct class
group_class= {(quoted diff) +4
-0+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0) .dev_groups = groups, +#else + .dev_attrs = group_dev_attr, +#endif};
Quoted 4 lines
[...]
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
Quoted 3 lines
Use python between the two rules to construct the identifier you want.
Indeed, that works and is simpler than I thought (had briefly considered, but then found the workaround)
Thanks :)
johannes