Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

coccinelle: api/stream_open: treat all wait_.*() calls as blocking

Previously steam_open.cocci was treating only wait_event_.* - e.g.
wait_event_interruptible - as a blocking operation. However e.g.
wait_for_completion_interruptible is also blocking, and so from this
point of view it would be more logical to treat all wait_.* as a
blocking point.

The logic of this change actually came up for real when
drivers/pci/switch/switchtec.c changed from using
wait_event_interruptible to wait_for_completion_interruptible:

https://lore.kernel.org/linux-pci/20190413170056.GA11293@deco.navytux.spb.ru/
https://lore.kernel.org/linux-pci/20190415145456.GA15280@deco.navytux.spb.ru/
https://lore.kernel.org/linux-pci/20190415154102.GB17661@deco.navytux.spb.ru/

For a driver that uses nonseekable_open with read/write having stream
semantic and read also calling e.g. wait_for_completion_interruptible,
running stream_open.cocci before this patch would produce:

WARNING: <driver>_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open.

while after this patch it will report:

ERROR: <driver>_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix.

Signed-off-by: Kirill Smelkov <kirr@nexedi.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

authored by

Kirill Smelkov and committed by
Masahiro Yamada
0c4ab18f f58c17c2

+4 -4
+4 -4
scripts/coccinelle/api/stream_open.cocci
··· 35 35 // a function that blocks 36 36 @ blocks @ 37 37 identifier block_f; 38 - identifier wait_event =~ "^wait_event_.*"; 38 + identifier wait =~ "^wait_.*"; 39 39 @@ 40 40 block_f(...) { 41 41 ... when exists 42 - wait_event(...) 42 + wait(...) 43 43 ... when exists 44 44 } 45 45 ··· 49 49 // XXX currently reader_blocks supports only direct and 1-level indirect cases. 50 50 @ reader_blocks_direct @ 51 51 identifier stream_reader.readstream; 52 - identifier wait_event =~ "^wait_event_.*"; 52 + identifier wait =~ "^wait_.*"; 53 53 @@ 54 54 readstream(...) 55 55 { 56 56 ... when exists 57 - wait_event(...) 57 + wait(...) 58 58 ... when exists 59 59 } 60 60