Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Some overlooked fallthrough switch cases vs GCC7 pedantry



For kernels with "pseudo-device pf" (i386 at least, PF-enabled kernels
on other arches I build didn't complain), GCC7 complains about a
fallthrough case in a switch{} statement:

[...]
--- pf.o ---
/x/current/src/sys/dist/pf/net/pf.c: In function 'pf_test6':
/x/current/src/sys/dist/pf/net/pf.c:6170:25: error: this statement may fall through [-Werror=implicit-fallthrough=]
   case IPPROTO_ROUTING: {
                         ^
/x/current/src/sys/dist/pf/net/pf.c:6200:3: note: here
   case IPPROTO_AH:
   ^~~~
[...]

While the case statement and code block have a "/* FALLTHROUGH */"
comment, it appears before the closing brace of the block associated
with the case.

The following change mollifies GCC7:

+Index: sys/dist/pf/net/pf.c
+===================================================================
+RCS file: /cvsroot/src/sys/dist/pf/net/pf.c,v
+retrieving revision 1.83
+diff -u -p -r1.83 pf.c
+--- sys/dist/pf/net/pf.c        3 Sep 2018 16:29:34 -0000       1.83
++++ sys/dist/pf/net/pf.c        9 Feb 2019 20:04:12 -0000
+@@ -6195,8 +6195,7 @@ pf_test6(int dir, struct ifnet *ifp, str
+                                log = 1;
+                                goto done;
+                        }
+-                       /* FALLTHROUGH */
+-               }
++               } /* FALLTHROUGH */
+                case IPPROTO_AH:
+                case IPPROTO_HOPOPTS:
+                case IPPROTO_DSTOPTS: {


Also, for kernels using legacy DRM UMS drivers (at least radeondrm and
viadrmums) some files are missing "/* FALLTHROUGH */" comments entirely,
incurring the wrath of GCC7.

For "radeondrm":

[...]
--- radeon_cs.o ---
/x/current/src/sys/external/bsd/drm/dist/shared-core/radeon_cs.c: In function 'radeon_cs_ioctl':
/x/current/src/sys/external/bsd/drm/dist/shared-core/radeon_cs.c:218:7: error: this statement may fall through [-Werror=implicit-fallthrough=]
    if (size == 0) {
       ^
/x/current/src/sys/external/bsd/drm/dist/shared-core/radeon_cs.c:222:3: note: here
   case RADEON_CHUNK_ID_RELOCS:
   ^~~~
cc1: all warnings being treated as errors
*** [radeon_cs.o] Error code 1

nbmake: stopped in /r0/build/current/obj/i386/sys/arch/i386/compile/RACKMOUNT
[...]

The following patch satisfies GCC7:

+Index: sys/external/bsd/drm/dist/shared-core/radeon_cs.c
+===================================================================
+RCS file: /cvsroot/src/sys/external/bsd/drm/dist/shared-core/radeon_cs.c,v
+retrieving revision 1.2
+diff -u -p -r1.2 radeon_cs.c
+--- sys/external/bsd/drm/dist/shared-core/radeon_cs.c   17 Oct 2013 21:15:18 -0000      1.2
++++ sys/external/bsd/drm/dist/shared-core/radeon_cs.c   10 Feb 2019 01:10:02 -0000
+@@ -218,7 +218,7 @@ int radeon_cs_ioctl(struct drm_device *d
+                        if (size == 0) {
+                                r = -EINVAL;
+                                goto out;
+-                       }
++                       } /* FALLTHROUGH */
+                case RADEON_CHUNK_ID_RELOCS:
+                        if (size) {
+                                parser.chunks[i].kdata = drm_alloc(size, DRM_MEM_DRIVER);


And in "viadrmums":

[...]
--- via_dmablit.o ---
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c: In function 'via_free_sg_info':
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:209:3: error: this statement may fall through [-Werror=implicit-fallthrough=]
   via_unmap_blit_from_device(dev, pdev, vsg);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:210:2: note: here
  case dr_via_desc_pages_alloc:
  ^~~~
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:224:3: error: this statement may fall through [-Werror=implicit-fallthrough=]
   kfree(vsg->desc_pages);
   ^~~~~~~~~~~~~~~~~~~~~~
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:225:2: note: here
  case dr_via_pages_locked:
  ^~~~
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:228:3: error: this statement may fall through [-Werror=implicit-fallthrough=]
   bus_dmamap_sync(dev->dmat, vsg->dmamap, 0,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       vsg->num_pages << PAGE_SHIFT,
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       (vsg->direction == DMA_FROM_DEVICE?
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE));
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:241:2: note: here
  case dr_via_pages_alloc:
  ^~~~
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:243:3: error: this statement may fall through [-Werror=implicit-fallthrough=]
   bus_dmamap_destroy(dev->dmat, vsg->dmamap);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/x/current/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c:247:2: note: here
  default:
  ^~~~~~~
[...]


Patch to satisfy GCC7:

+Index: sys/external/bsd/drm2/dist/drm/via/via_dmablit.c
+===================================================================
+RCS file: /cvsroot/src/sys/external/bsd/drm2/dist/drm/via/via_dmablit.c,v
+retrieving revision 1.6
+diff -u -p -r1.6 via_dmablit.c
+--- sys/external/bsd/drm2/dist/drm/via/via_dmablit.c    27 Aug 2018 04:58:37 -0000      1.6
++++ sys/external/bsd/drm2/dist/drm/via/via_dmablit.c    10 Feb 2019 03:15:05 -0000
+@@ -207,6 +207,7 @@ via_free_sg_info(struct drm_device *dev,
+        switch (vsg->state) {
+        case dr_via_device_mapped:
+                via_unmap_blit_from_device(dev, pdev, vsg);
++               /* FALLTHROUGH */
+        case dr_via_desc_pages_alloc:
+ #ifdef __NetBSD__
+                bus_dmamap_unload(dev->dmat, vsg->desc_dmamap);
+@@ -222,6 +223,7 @@ via_free_sg_info(struct drm_device *dev,
+                }
+ #endif
+                kfree(vsg->desc_pages);
++               /* FALLTHROUGH */
+        case dr_via_pages_locked:
+ #ifdef __NetBSD__
+                /* Make sure any completed transfer is synced.  */
+@@ -238,12 +240,14 @@ via_free_sg_info(struct drm_device *dev,
+                        }
+                }
+ #endif
++               /* FALLTHROUGH */
+        case dr_via_pages_alloc:
+ #ifdef __NetBSD__
+                bus_dmamap_destroy(dev->dmat, vsg->dmamap);
+ #else
+                vfree(vsg->pages);
+ #endif
++               /* FALLTHROUGH */
+        default:
+                vsg->state = dr_via_sg_init;
+        }



-- 
|/"\ John D. Baker, KN5UKS               NetBSD     Darwin/MacOS X
|\ / jdbaker[snail]consolidated[flyspeck]net  OpenBSD            FreeBSD
| X  No HTML/proprietary data in email.   BSD just sits there and works!
|/ \ GPGkeyID:  D703 4A7E 479F 63F8 D3F4  BD99 9572 8F23 E4AD 1645


Home | Main Index | Thread Index | Old Index