[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200710153018.12226-6-a.hajda@samsung.com>
Date: Fri, 10 Jul 2020 17:30:18 +0200
From: Andrzej Hajda <a.hajda@...sung.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Andrzej Hajda <a.hajda@...sung.com>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@...sung.com>,
Marek Szyprowski <m.szyprowski@...sung.com>,
"Rafael J. Wysocki" <rafael@...nel.org>,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
andy.shevchenko@...il.com, Mark Brown <broonie@...nel.org>,
Russell King - ARM Linux <linux@...linux.org.uk>,
Neil Armstrong <narmstrong@...libre.com>,
Laurent Pinchart <Laurent.pinchart@...asonboard.com>,
Jonas Karlman <jonas@...boo.se>,
Jernej Skrabec <jernej.skrabec@...l.net>,
Daniel Vetter <daniel@...ll.ch>,
dri-devel@...ts.freedesktop.org (open list:DRM DRIVERS)
Subject: [PATCH v8 5/5] coccinelle: add script looking for cases where
probe__err can be used
This is AD-HOC script, it should nt be merged.
Signed-off-by: Andrzej Hajda <a.hajda@...sung.com>
---
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
+
+@...tialize: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);
+ ...
+ }
+
+@...ch_no_nl@
+expression dev, err;
+constant char [] fmt !~ "\\n$";
+@@
+ dev_err_probe(dev, err, fmt, ...)
+
+@...ipt:python add_nl depends on catch_no_nl@
+fmt << catch_no_nl.fmt;
+nfmt;
+@@
+print "add_nl " + fmt
+coccinelle.nfmt = fmt[:-1] + '\\n"';
+
+@..._no_nl depends on catch_no_nl@
+constant char [] catch_no_nl.fmt;
+identifier add_nl.nfmt;
+@@
+- fmt
++ nfmt
+
+@...ch_fmt@
+expression err, dev;
+expression fmt;
+position p;
+@@
+
+ dev_err_probe@p(dev, err, fmt, ..., \( (int)err \| err \) )
+
+@...ipt: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
+
+@..._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)
+
+@..._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);
+
+@..._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;
+
+@..._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
Powered by blists - more mailing lists