^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Author: Kirill Smelkov (kirr@nexedi.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // Search for stream-like files that are using nonseekable_open and convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // them to stream_open. A stream-like file is a file that does not use ppos in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // its read and write. Rationale for the conversion is to avoid deadlock in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // between read and write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) virtual report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) virtual patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) virtual explain // explain decisions in the patch (SPFLAGS="-D explain")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) // stream-like reader & writer - ones that do not depend on f_pos.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) @ stream_reader @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) identifier readstream, ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) identifier f, buf, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) type loff_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ssize_t readstream(struct file *f, char *buf, size_t len, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) ... when != ppos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) @ stream_writer @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) identifier writestream, ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) identifier f, buf, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) type loff_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ssize_t writestream(struct file *f, const char *buf, size_t len, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) ... when != ppos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) // a function that blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) @ blocks @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) identifier block_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) identifier wait =~ "^wait_.*";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) block_f(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ... when exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) wait(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ... when exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) // stream_reader that can block inside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) // XXX wait_* can be called not directly from current function (e.g. func -> f -> g -> wait())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) // XXX currently reader_blocks supports only direct and 1-level indirect cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) @ reader_blocks_direct @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) identifier stream_reader.readstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) identifier wait =~ "^wait_.*";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) readstream(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ... when exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) wait(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ... when exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) @ reader_blocks_1 @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) identifier stream_reader.readstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) identifier blocks.block_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) readstream(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ... when exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) block_f(...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ... when exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) @ reader_blocks depends on reader_blocks_direct || reader_blocks_1 @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) identifier stream_reader.readstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) readstream(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) // file_operations + whether they have _any_ .read, .write, .llseek ... at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) // XXX add support for file_operations xxx[N] = ... (sound/core/pcm_native.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) @ fops0 @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) identifier fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) @ has_read @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) identifier read_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .read = read_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) @ has_read_iter @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) identifier read_iter_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .read_iter = read_iter_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) @ has_write @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) identifier write_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .write = write_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) @ has_write_iter @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) identifier write_iter_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .write_iter = write_iter_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) @ has_llseek @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) identifier llseek_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .llseek = llseek_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) @ has_no_llseek @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) @ has_noop_llseek @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .llseek = noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) @ has_mmap @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) identifier mmap_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .mmap = mmap_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) @ has_copy_file_range @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) identifier copy_file_range_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .copy_file_range = copy_file_range_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) @ has_remap_file_range @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) identifier remap_file_range_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .remap_file_range = remap_file_range_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) @ has_splice_read @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) identifier splice_read_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .splice_read = splice_read_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) @ has_splice_write @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) identifier splice_write_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .splice_write = splice_write_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) // file_operations that is candidate for stream_open conversion - it does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) // use mmap and other methods that assume @offset access to file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) // XXX for simplicity require no .{read/write}_iter and no .splice_{read/write} for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) // XXX maybe_steam.fops cannot be used in other rules - it gives "bad rule maybe_stream or bad variable fops".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) @ maybe_stream depends on (!has_llseek || has_no_llseek || has_noop_llseek) && !has_mmap && !has_copy_file_range && !has_remap_file_range && !has_read_iter && !has_write_iter && !has_splice_read && !has_splice_write @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) identifier fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) // ---- conversions ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) // XXX .open = nonseekable_open -> .open = stream_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) // XXX .open = func -> openfunc -> nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) // read & write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) // if both are used in the same file_operations together with an opener -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) // under that conditions we can use stream_open instead of nonseekable_open.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) @ fops_rw depends on maybe_stream @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) identifier fops0.fops, openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) identifier stream_reader.readstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) identifier stream_writer.writestream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .open = openfunc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .read = readstream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .write = writestream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) @ report_rw depends on report @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) identifier fops_rw.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) position p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) nonseekable_open@p1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) @ script:python depends on report && reader_blocks @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) fops << fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) p << report_rw.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) coccilib.report.print_report(p[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) "ERROR: %s: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix." % (fops,))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) @ script:python depends on report && !reader_blocks @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) fops << fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) p << report_rw.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) coccilib.report.print_report(p[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) "WARNING: %s: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open." % (fops,))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) @ explain_rw_deadlocked depends on explain && reader_blocks @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) identifier fops_rw.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) - nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) + nonseekable_open /* read & write (was deadlock) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) @ explain_rw_nodeadlock depends on explain && !reader_blocks @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) identifier fops_rw.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) - nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) + nonseekable_open /* read & write (no direct deadlock) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) @ patch_rw depends on patch @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) identifier fops_rw.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) - nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) + stream_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) // read, but not write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) @ fops_r depends on maybe_stream && !has_write @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) identifier fops0.fops, openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) identifier stream_reader.readstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .open = openfunc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .read = readstream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) @ report_r depends on report @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) identifier fops_r.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) position p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) nonseekable_open@p1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) @ script:python depends on report @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) fops << fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) p << report_r.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) coccilib.report.print_report(p[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) "WARNING: %s: .read() has stream semantic; safe to change nonseekable_open -> stream_open." % (fops,))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) @ explain_r depends on explain @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) identifier fops_r.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) - nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) + nonseekable_open /* read only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) @ patch_r depends on patch @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) identifier fops_r.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) - nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) + stream_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) // write, but not read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) @ fops_w depends on maybe_stream && !has_read @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) identifier fops0.fops, openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) identifier stream_writer.writestream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .open = openfunc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .write = writestream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) @ report_w depends on report @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) identifier fops_w.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) position p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) nonseekable_open@p1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) @ script:python depends on report @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) fops << fops0.fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) p << report_w.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) coccilib.report.print_report(p[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) "WARNING: %s: .write() has stream semantic; safe to change nonseekable_open -> stream_open." % (fops,))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) @ explain_w depends on explain @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) identifier fops_w.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) - nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) + nonseekable_open /* write only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) @ patch_w depends on patch @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) identifier fops_w.openfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) openfunc(...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) <...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) - nonseekable_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) + stream_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) ...>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) // no read, no write - don't change anything