Add braces to avoid "ambiguous ‘else’" compiler warnings
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Jul 2016 03:03:31 +0000 (20:03 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 30 Sep 2016 08:18:35 +0000 (10:18 +0200)
commit 194dc870a5890e855ecffb30f3b80ba7c88f96d6 upstream.

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: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iommu/dmar.c
drivers/iommu/intel-iommu.c

index 3821c4786662a4841f9e83c33d6bd7f70cf6d53d..565bb2c140ed9e15e34cf11f7bac5d789b7b0bfb 100644 (file)
@@ -1858,10 +1858,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.
         */
-       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,
                                          dmaru->devices_cnt, i, dev)
                        return -EBUSY;
+       }
 
        ret = dmar_ir_hotplug(dmaru, false);
        if (ret == 0)
index 24d81308a1a6ac9b73cd6365f5db6d2324afc97b..b7f852d824a3126f5a35233b2c9c71fab9c60265 100644 (file)
@@ -4182,10 +4182,11 @@ int dmar_check_one_atsr(struct acpi_dmar_header *hdr, void *arg)
        if (!atsru)
                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,
                                          i, dev)
                        return -EBUSY;
+       }
 
        return 0;
 }