backports: restrict group_attr spatch properly
authorJohannes Berg <johannes.berg@intel.com>
Mon, 6 Feb 2017 11:26:05 +0000 (12:26 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 7 Feb 2017 06:29:51 +0000 (07:29 +0100)
In cases where there are multiple instances of the ATTRIBUTE_GROUPS()
macro, or an instance thereof with a .dev_groups that doesn't actually
use it (like in devcoredump.c), the spatch wasn't correctly restricted
to make sure the two belong together, and thus made some completely
wrong modifications, linking an ATTRIBUTE_GROUPS() to a .dev_attrs it
didn't belong to at all.

Fix this by making sure that the ATTRIBUTE_GROUPS() instance and use
for .dev_groups match. This needs python indirection to create the
symbol name that ATTRIBUTE_GROUPS() creates in the C code.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
patches/collateral-evolutions/generic/0001-group-attr/0001-group_attr_class.cocci
patches/collateral-evolutions/generic/0001-group-attr/0002-group_attr_bus.cocci

index ea2e7039f50c29ab1f208620bbcfe6294365a404..a9c84651eedcbf4fcd6611c252b696820ecc723c 100644 (file)
@@ -33,9 +33,15 @@ declarer name ATTRIBUTE_GROUPS;
 
 ATTRIBUTE_GROUPS(group);
 
-@ class_group depends on attribute_group @
+@script:python attribute_groups_name@
+group << attribute_group.group;
+groups;
+@@
+coccinelle.groups = group + "_groups"
+
+@ class_group @
 identifier group_class;
-expression groups;
+identifier attribute_groups_name.groups;
 fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
 @@
 
@@ -47,9 +53,9 @@ struct class group_class = {
 +#endif
 };
 
-@ attribute_group_mod depends on attribute_group && class_group @
+@ attribute_group_mod depends on class_group @
 declarer name ATTRIBUTE_GROUPS_BACKPORT;
-identifier group;
+identifier attribute_group.group;
 @@
 
 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
@@ -59,10 +65,10 @@ ATTRIBUTE_GROUPS(group);
 +ATTRIBUTE_GROUPS_BACKPORT(group);
 +#endif
 
-@ class_registering depends on class_group && attribute_group_mod @
+@ class_registering @
 identifier class_register, ret;
 identifier class_group.group_class;
-fresh identifier group_class_init = "init_" ## attribute_group_mod.group ## "_attrs";
+fresh identifier group_class_init = "init_" ## attribute_group.group ## "_attrs";
 @@
 
 (
index b01da875083b09d3f59685f86e6c27bc240af1db..c19e9d7f3eda51ae888e5f8cfc28bd9f8345c840 100644 (file)
@@ -31,9 +31,15 @@ declarer name ATTRIBUTE_GROUPS;
 
 ATTRIBUTE_GROUPS(group);
 
-@ bus_group depends on attribute_group @
+@script:python attribute_groups_name@
+group << attribute_group.group;
+groups;
+@@
+coccinelle.groups = group + "_groups"
+
+@ bus_group @
 identifier group_bus;
-expression groups;
+identifier attribute_groups_name.groups;
 fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
 @@
 
@@ -45,9 +51,9 @@ struct bus_type group_bus = {
 +#endif
 };
 
-@ attribute_group_mod depends on attribute_group && bus_group @
+@ attribute_group_mod depends on bus_group @
 declarer name ATTRIBUTE_GROUPS_BACKPORT;
-identifier group;
+identifier attribute_group.group;
 @@
 
 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,12,0)
@@ -57,10 +63,10 @@ ATTRIBUTE_GROUPS(group);
 +ATTRIBUTE_GROUPS_BACKPORT(group);
 +#endif
 
-@ bus_registering depends on bus_group && attribute_group_mod @
+@ bus_registering @
 identifier bus_register, ret;
 identifier bus_group.group_bus;
-fresh identifier group_bus_init = "init_" ## attribute_group_mod.group ## "_attrs";
+fresh identifier group_bus_init = "init_" ## attribute_group.group ## "_attrs";
 @@
 
 (
@@ -70,4 +76,3 @@ fresh identifier group_bus_init = "init_" ## attribute_group_mod.group ## "_attr
 +       group_bus_init();
         ret = bus_register(&group_bus);
 )
-