I suggest the following semantic patch.  It is in two parts.  The first
part matches all of the functions/declarations to ensure that they are all
present.  The second part then makes the transformation.

I get a change in only one file.

julia

// Find opportunities to use module_pci_driver(a)

@r1@
identifier f1, ret;
struct pci_driver a;
@@

int f1(void) {
  int ret;
  ret = pci_register_driver(&a);
  return ret;
}


@r2 depends on r1@
identifier f2;
struct pci_driver r1.a;
@@

void f2(void) {
pci_unregister_driver(&a);
}

@r3 depends on r2@
identifier r1.f1;
declarer name module_init;
@@

module_init(f1);

@r4 depends on r3@
identifier r2.f2;
declarer name module_exit;
@@

module_exit(f2);

// Clean up

@depends on r4@
identifier f1, ret;
struct pci_driver a;
@@

- int f1(void) {
-   int ret;
-   ret = pci_register_driver(&a);
-   return ret;
- }


@depends on r4@
identifier f2;
struct pci_driver r1.a;
@@

- void f2(void) {
-   pci_unregister_driver(&a);
- }

@depends on r4@
identifier r1.f1;
declarer name module_pci_driver;
@@

- module_init(f1);
+ module_pci_driver(&a);

@depends on r4@
identifier r2.f2;
@@

- module_exit(f2);
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to