This is AD-HOC script, it should nt be merged. Signed-off-by: Andrzej Hajda <a.hajda@xxxxxxxxxxx> --- probe_err.cocci | 247 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 probe_err.cocci diff --git a/probe_err.cocci b/probe_err.cocci new file mode 100644 index 000000000000..0ef9a9b4c9bc --- /dev/null +++ b/probe_err.cocci @@ -0,0 +1,247 @@ +virtual context +virtual patch + +@initialize:python@ +@@ + +import re + +@@ +expression err, dev; +constant char [] fmt; +expression list args; +@@ + +- if (err != -EPROBE_DEFER) { dev_err(dev, fmt, args); } ++ dev_err_probe(dev, err, fmt, args); + +@@ +expression ptr, dev; +constant char [] fmt; +expression list args; +@@ + +- if (ptr != ERR_PTR(-EPROBE_DEFER)) { dev_err(dev, fmt, args); } ++ dev_err_probe(dev, PTR_ERR(ptr), fmt, args); + +@@ +expression e, dev; +identifier err; +identifier fget =~ "^(devm_)?(clk_get|gpiod_get|gpiod_get_optional|gpiod_get_index|gpiod_get_index_optional|regulator_get|regulator_get_optional|reset_control_get|reset_control_get_exclusive|reset_control_get_shared|phy_get|pinctrl_get|iio_channel_get|pwm_get)$"; +identifier flog =~ "^(dev_err|dev_warn|dev_info)$"; +expression list args; +@@ + e = fget(...); + if (IS_ERR(e)) { +( + err = PTR_ERR(e); +- flog(dev, args); ++ dev_err_probe(dev, err, args); +| +- flog(dev, args); ++ dev_err_probe(dev, PTR_ERR(e), args); +) + ... + } + +@@ +expression dev; +identifier err; +identifier fget =~ "^(devm_)?(request_irq|request_threaded_irq|regulator_bulk_get)$"; +identifier flog =~ "^(dev_err|dev_warn|dev_info)$"; +expression list args; +@@ + err = fget(...); + if ( \( err \| err < 0 \) ) { + ... +- flog(dev, args); ++ dev_err_probe(dev, err, args); + ... + } + +@catch_no_nl@ +expression dev, err; +constant char [] fmt !~ "\\n$"; +@@ + dev_err_probe(dev, err, fmt, ...) + +@script:python add_nl depends on catch_no_nl@ +fmt << catch_no_nl.fmt; +nfmt; +@@ +print "add_nl " + fmt +coccinelle.nfmt = fmt[:-1] + '\\n"'; + +@fix_no_nl depends on catch_no_nl@ +constant char [] catch_no_nl.fmt; +identifier add_nl.nfmt; +@@ +- fmt ++ nfmt + +@catch_fmt@ +expression err, dev; +expression fmt; +position p; +@@ + + dev_err_probe@p(dev, err, fmt, ..., \( (int)err \| err \) ) + +@script:python trim_fmt@ +fmt << catch_fmt.fmt; +new_fmt; +@@ + +tmp = fmt +tmp = re.sub('failed: irq request (IRQ: %d, error :%d)', 'irq request %d', tmp) +tmp = re.sub('Error %l?[di] ', 'Error ', tmp) +tmp = re.sub(' as irq = %d\\\\n', ', bad irq\\\\n', tmp) +tmp = re.sub('[:,]? ?((ret|err|with|error)[ =]?)?%l?[di]\.?\\\\n', '\\\\n', tmp) +tmp = re.sub(' ?\(((err|ret|error)\s*=?\s*)?%l?[diu]\)[!.]?\\\\n', '\\\\n', tmp) + +assert tmp != fmt, "cannot trim_fmt in: " + fmt +print "trim_fmt " + fmt + " " + tmp +coccinelle.new_fmt = tmp + +@fix_fmt@ +expression err, err1, dev; +expression fmt; +expression list l; +identifier trim_fmt.new_fmt; +position catch_fmt.p; +@@ + +- dev_err_probe@p(dev, err, fmt, l, err1) ++ dev_err_probe(dev, err, new_fmt, l) + +@err_ass1@ +identifier err; +expression dev, ptr; +expression list args; +@@ + +- err = PTR_ERR(ptr); +- dev_err_probe(dev, err, args); +- return ERR_PTR(err); ++ dev_err_probe(dev, PTR_ERR(ptr), args); ++ return ERR_CAST(ptr); + +@err_ass2@ +identifier err, f1, f2; +expression dev, e; +expression list args; +@@ +- err = PTR_ERR(e); +- dev_err_probe(dev, err, args); +( +| + f1(...); +| + f1(...); + f2(...); +) +- return err; ++ return dev_err_probe(dev, PTR_ERR(e), args); + +@@ +identifier err; +expression dev, e; +expression list args; +@@ + +- int err = e; +- dev_err_probe(dev, err, args); +- return err; ++ return dev_err_probe(dev, e, args); + +@@ +expression err, dev; +expression list args; +@@ + +- dev_err_probe(dev, err, args); +- return err; ++ return dev_err_probe(dev, err, args); + +@@ +expression err, dev, ptr; +expression list args; +@@ + +- dev_err_probe(dev, PTR_ERR(ptr), args); + err = PTR_ERR(ptr); ++ dev_err_probe(dev, err, args); + +@@ +expression e; +expression list args; +statement s, s1; +@@ + +// without s1 spatch generates extra empty line after s +- if (e) { return dev_err_probe(args); } else s s1 ++ if (e) return dev_err_probe(args); s s1 + +@@ +expression e; +expression list args; +@@ + +- if (e) { return dev_err_probe(args); } ++ if (e) return dev_err_probe(args); + +@@ +expression e, s, v; +expression list args; +@@ + +- if (e == v) { s; } else { return dev_err_probe(args); } ++ if (e != v) return dev_err_probe(args); s; + +@err_ass3@ +identifier err; +expression dev, ptr; +expression list args; +@@ + +- err = PTR_ERR_OR_ZERO(ptr); +- if (err) return dev_err_probe(dev, err, args); ++ if (IS_ERR(ptr)) return dev_err_probe(dev, PTR_ERR(ptr), args); + +@@ +expression dev, ptr; +expression list args; +@@ + +- DROP_probe_err(dev, PTR_ERR(ptr), args) ++ probe_err(dev, ptr, args) + +@@ +identifier err_ass1.err; +expression e; +identifier f =~ "^(dev_err_probe|probe_err_ptr)$"; +@@ +- \( int err; \| int err = e; \) + <+... when != err + f + ...+> + +@@ +identifier err_ass2.err; +expression e; +identifier f =~ "^(dev_err_probe|probe_err_ptr)$"; +@@ +- \( int err; \| int err = e; \) + <+... when != err + f + ...+> + +@@ +identifier err_ass3.err; +expression e; +identifier f =~ "^(dev_err_probe|probe_err_ptr)$"; +@@ +- \( int err; \| int err = e; \) + <+... when != err + f + ...+> -- 2.17.1 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel