Release coccinelle-0.1
[bpt/coccinelle.git] / demos / sgrep / dangerous_GFP_KERNEL.sgrep
1
2 // note that need -sgrep options otherwise don't detect
3 // every situation as for instance:
4
5 // static int start_command_port(struct usb_serial *serial)
6 // {
7 // spin_lock_irqsave(&command_info->lock, flags);
8 // if (!command_info->port_running) {
9 // retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
10 // if (retval) {
11 // err("%s - failed submitting read urb, error %d", __FUNCTION__, retval);
12 // goto exit;
13 // }
14 // }
15 // command_info->port_running++;
16 //
17 // exit:
18 // spin_unlock_irqrestore(&command_info->lock, flags);
19 // return retval;
20 // }
21
22 // note that better to send a .sgrep than a .cocci, that is
23 // to not do the fix because sometimes the correct fix is not to replace
24 // the use of GFP_KERNEL but instead to move the function call outside
25 // the spin_locked region.
26
27 @@
28 //expression E;
29 identifier fn;
30 @@
31
32 (
33 spin_lock_irqsave(...)
34 |
35 spin_lock(...)
36 )
37 ... when != \(spin_unlock_irqrestore(...)\|spin_unlock(...)\)
38 //- usb_submit_urb(E, GFP_KERNEL)
39 fn(...,
40 - GFP_KERNEL
41 //+ GFP_ATOMIC
42 ,...
43 )
44