Commit 194dc870 authored by Linus Torvalds's avatar Linus Torvalds

Add braces to avoid "ambiguous ‘else’" compiler warnings

Some of our "for_each_xyz()" macro constructs make gcc unhappy about
lack of braces around if-statements inside or outside the loop, because
the loop construct itself has a "if-then-else" statement inside of it.

The resulting warnings look something like this:

  drivers/gpu/drm/i915/i915_debugfs.c: In function ‘i915_dump_lrc’:
  drivers/gpu/drm/i915/i915_debugfs.c:2103:6: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses]
     if (ctx != dev_priv->kernel_context)
        ^

even if the code itself is fine.

Since the warning is fairly easy to avoid by adding a braces around the
if-statement near the for_each_xyz() construct, do so, rather than
disabling the otherwise potentially useful warning.

(The if-then-else statements used in the "for_each_xyz()" constructs are
designed to be inherently safe even with no braces, but in this case
it's quite understandable that gcc isn't really able to tell that).

This finally leaves the standard "allmodconfig" build with just a
handful of remaining warnings, so new and valid warnings hopefully will
stand out.
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 124a3d88
...@@ -2100,9 +2100,10 @@ static int i915_dump_lrc(struct seq_file *m, void *unused) ...@@ -2100,9 +2100,10 @@ static int i915_dump_lrc(struct seq_file *m, void *unused)
return ret; return ret;
list_for_each_entry(ctx, &dev_priv->context_list, link) list_for_each_entry(ctx, &dev_priv->context_list, link)
if (ctx != dev_priv->kernel_context) if (ctx != dev_priv->kernel_context) {
for_each_engine(engine, dev_priv) for_each_engine(engine, dev_priv)
i915_dump_lrc_obj(m, ctx, engine); i915_dump_lrc_obj(m, ctx, engine);
}
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
......
...@@ -1871,10 +1871,11 @@ static int dmar_hp_remove_drhd(struct acpi_dmar_header *header, void *arg) ...@@ -1871,10 +1871,11 @@ static int dmar_hp_remove_drhd(struct acpi_dmar_header *header, void *arg)
/* /*
* All PCI devices managed by this unit should have been destroyed. * All PCI devices managed by this unit should have been destroyed.
*/ */
if (!dmaru->include_all && dmaru->devices && dmaru->devices_cnt) if (!dmaru->include_all && dmaru->devices && dmaru->devices_cnt) {
for_each_active_dev_scope(dmaru->devices, for_each_active_dev_scope(dmaru->devices,
dmaru->devices_cnt, i, dev) dmaru->devices_cnt, i, dev)
return -EBUSY; return -EBUSY;
}
ret = dmar_ir_hotplug(dmaru, false); ret = dmar_ir_hotplug(dmaru, false);
if (ret == 0) if (ret == 0)
......
...@@ -4272,10 +4272,11 @@ int dmar_check_one_atsr(struct acpi_dmar_header *hdr, void *arg) ...@@ -4272,10 +4272,11 @@ int dmar_check_one_atsr(struct acpi_dmar_header *hdr, void *arg)
if (!atsru) if (!atsru)
return 0; return 0;
if (!atsru->include_all && atsru->devices && atsru->devices_cnt) if (!atsru->include_all && atsru->devices && atsru->devices_cnt) {
for_each_active_dev_scope(atsru->devices, atsru->devices_cnt, for_each_active_dev_scope(atsru->devices, atsru->devices_cnt,
i, dev) i, dev)
return -EBUSY; return -EBUSY;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment