* [PATCH] msi: use for_each_msi_entry_safe iterator macro
@ 2020-12-17 0:55 Jacob Keller
2020-12-18 14:19 ` Lokesh Vutla
0 siblings, 1 reply; 2+ messages in thread
From: Jacob Keller @ 2020-12-17 0:55 UTC (permalink / raw)
To: linux-kernel, linux-pci
Cc: Jacob Keller, Rafael J . Wysocki, Stuart Yoder, Laurentiu Tudor,
Nishanth Menon, Tero Kristo, Santosh Shilimkar, Miquel Raynal
Commit 81b1e6e6a859 ("platform-msi: Free descriptors in
platform_msi_domain_free()") introduced for_each_msi_entry_safe as an
iterator operating on the msi_list using the safe semantics with
a temporary variable.
A handful of locations still used the generic iterator instead of the
specific macro. Fix the 3 remaining cases. Add a cocci script which can
detect and report any misuse that is introduced in future changes.
Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: Stuart Yoder <stuyoder@gmail.com>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Tero Kristo <t-kristo@ti.com>
Cc: Santosh Shilimkar <ssantosh@kernel.org>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
I noticed that a couple places used the generic _safe iterator. They appear
to be code which was written before the commit that introduced the new
MSI-specific iterator.
drivers/base/platform-msi.c | 2 +-
drivers/bus/fsl-mc/fsl-mc-msi.c | 2 +-
drivers/soc/ti/ti_sci_inta_msi.c | 2 +-
.../iterators/for_each_msi_entry.cocci | 101 ++++++++++++++++++
4 files changed, 104 insertions(+), 3 deletions(-)
create mode 100644 scripts/coccinelle/iterators/for_each_msi_entry.cocci
diff --git a/drivers/base/platform-msi.c b/drivers/base/platform-msi.c
index c4a17e5edf8b..1fd8ac26c245 100644
--- a/drivers/base/platform-msi.c
+++ b/drivers/base/platform-msi.c
@@ -110,7 +110,7 @@ static void platform_msi_free_descs(struct device *dev, int base, int nvec)
{
struct msi_desc *desc, *tmp;
- list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) {
+ for_each_msi_entry_safe(desc, tmp, dev) {
if (desc->platform.msi_index >= base &&
desc->platform.msi_index < (base + nvec)) {
list_del(&desc->list);
diff --git a/drivers/bus/fsl-mc/fsl-mc-msi.c b/drivers/bus/fsl-mc/fsl-mc-msi.c
index 8edadf05cbb7..d0a52ccfa738 100644
--- a/drivers/bus/fsl-mc/fsl-mc-msi.c
+++ b/drivers/bus/fsl-mc/fsl-mc-msi.c
@@ -214,7 +214,7 @@ static void fsl_mc_msi_free_descs(struct device *dev)
{
struct msi_desc *desc, *tmp;
- list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) {
+ for_each_msi_entry_safe(desc, tmp, dev) {
list_del(&desc->list);
free_msi_entry(desc);
}
diff --git a/drivers/soc/ti/ti_sci_inta_msi.c b/drivers/soc/ti/ti_sci_inta_msi.c
index 0eb9462f609e..66f9772dcdfa 100644
--- a/drivers/soc/ti/ti_sci_inta_msi.c
+++ b/drivers/soc/ti/ti_sci_inta_msi.c
@@ -64,7 +64,7 @@ static void ti_sci_inta_msi_free_descs(struct device *dev)
{
struct msi_desc *desc, *tmp;
- list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) {
+ for_each_msi_entry_safe(desc, tmp, dev) {
list_del(&desc->list);
free_msi_entry(desc);
}
diff --git a/scripts/coccinelle/iterators/for_each_msi_entry.cocci b/scripts/coccinelle/iterators/for_each_msi_entry.cocci
new file mode 100644
index 000000000000..45282f93ab6f
--- /dev/null
+++ b/scripts/coccinelle/iterators/for_each_msi_entry.cocci
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Use for_each_msi_entry(_safe) instead of generic iterator
+///
+// Confidence: High
+// Copyright: (C) 2020 Jacob Keller, Intel Corporation.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: --no-includes --include-headers
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+//----------------------------------------------------------
+// For context mode
+//----------------------------------------------------------
+@depends on context@
+identifier member =~ "list";
+struct msi_desc *desc;
+struct msi_desc *tmp;
+struct device *dev;
+iterator name list_for_each_entry_safe;
+iterator name list_for_each_entry;
+statement S;
+@@
+(
+* list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), member)
+S
+|
+* list_for_each_entry(desc, dev_to_msi_list(dev), member)
+S
+)
+
+//----------------------------------------------------------
+// For patch mode
+//----------------------------------------------------------
+@depends on patch@
+identifier member =~ "list";
+struct msi_desc *desc;
+struct msi_desc *tmp;
+struct device *dev;
+iterator name list_for_each_entry_safe;
+iterator name for_each_msi_entry_safe;
+iterator name list_for_each_entry;
+iterator name for_each_msi_entry;
+statement S;
+@@
+(
+- list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), member)
++ for_each_msi_entry_safe(desc, tmp, dev)
+S
+|
+- list_for_each_entry(desc, dev_to_msi_list(dev), member)
++ for_each_msi_entry(desc, dev)
+S
+)
+
+//----------------------------------------------------------
+// For org and report mode
+//----------------------------------------------------------
+
+@r depends on (org || report )@
+identifier member =~ "list";
+struct msi_desc *desc;
+struct msi_desc *tmp;
+struct device *dev;
+iterator name list_for_each_entry_safe;
+iterator name list_for_each_entry;
+statement S;
+position p1, p2;
+@@
+(
+ list_for_each_entry_safe@p1(desc, tmp, dev_to_msi_list(dev), member) S
+|
+ list_for_each_entry@p2(desc, dev_to_msi_list(dev), member) S
+)
+
+@script:python depends on report@
+p << r.p1;
+@@
+
+coccilib.report.print_report(p[0], "WARNING: Use for_each_msi_entry_safe")
+
+@script:python depends on org@
+p << r.p1;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING: Use for_each_msi_entry_safe")
+
+@script:python depends on report@
+p << r.p2;
+@@
+
+coccilib.report.print_report(p[0], "WARNING: Use for_each_msi_entry")
+
+@script:python depends on org@
+p << r.p2;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING: Use for_each_msi_entry")
base-commit: 255b2d524884e4ec60333131aa0ca0ef19826dc2
--
2.29.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] msi: use for_each_msi_entry_safe iterator macro
2020-12-17 0:55 [PATCH] msi: use for_each_msi_entry_safe iterator macro Jacob Keller
@ 2020-12-18 14:19 ` Lokesh Vutla
0 siblings, 0 replies; 2+ messages in thread
From: Lokesh Vutla @ 2020-12-18 14:19 UTC (permalink / raw)
To: Jacob Keller, linux-kernel, linux-pci
Cc: Rafael J . Wysocki, Stuart Yoder, Laurentiu Tudor,
Nishanth Menon, Tero Kristo, Santosh Shilimkar, Miquel Raynal
On 17/12/20 6:25 am, Jacob Keller wrote:
> Commit 81b1e6e6a859 ("platform-msi: Free descriptors in
> platform_msi_domain_free()") introduced for_each_msi_entry_safe as an
> iterator operating on the msi_list using the safe semantics with
> a temporary variable.
>
> A handful of locations still used the generic iterator instead of the
> specific macro. Fix the 3 remaining cases. Add a cocci script which can
> detect and report any misuse that is introduced in future changes.
>
> Cc: Rafael J. Wysocki <rafael@kernel.org>
> Cc: Stuart Yoder <stuyoder@gmail.com>
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Cc: Nishanth Menon <nm@ti.com>
> Cc: Tero Kristo <t-kristo@ti.com>
> Cc: Santosh Shilimkar <ssantosh@kernel.org>
> Cc: Miquel Raynal <miquel.raynal@bootlin.com>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> ---
[..snip..]
> }
> diff --git a/drivers/soc/ti/ti_sci_inta_msi.c b/drivers/soc/ti/ti_sci_inta_msi.c
> index 0eb9462f609e..66f9772dcdfa 100644
> --- a/drivers/soc/ti/ti_sci_inta_msi.c
> +++ b/drivers/soc/ti/ti_sci_inta_msi.c
> @@ -64,7 +64,7 @@ static void ti_sci_inta_msi_free_descs(struct device *dev)
> {
> struct msi_desc *desc, *tmp;
>
> - list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) {
> + for_each_msi_entry_safe(desc, tmp, dev) {
> list_del(&desc->list);
> free_msi_entry(desc);
> }
For ti_sci_inta_msi part:
Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>
Thanks and regards,
Lokesh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-18 14:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 0:55 [PATCH] msi: use for_each_msi_entry_safe iterator macro Jacob Keller
2020-12-18 14:19 ` Lokesh Vutla
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.