Skip to content

Commit 38cf8c0

Browse files
behlendorftonyhutter
authored andcommitted
Use fallthrough macro
As of the Linux 5.9 kernel a fallthrough macro has been added which should be used to anotate all intentional fallthrough paths. Once all of the kernel code paths have been updated to use fallthrough the -Wimplicit-fallthrough option will because the default. To avoid warnings in the OpenZFS code base when this happens apply the fallthrough macro. Additional reading: https://lwn.net/Articles/794944/ Reviewed-by: Tony Nguyen <[email protected]> Reviewed-by: George Melikov <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #12441
1 parent ca3c3f1 commit 38cf8c0

34 files changed

+84
-39
lines changed

cmd/mount_zfs/mount_zfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ main(int argc, char **argv)
367367
"mount the filesystem again.\n"), dataset);
368368
return (MOUNT_SYSERR);
369369
}
370-
/* fallthru */
370+
fallthrough;
371371
#endif
372372
default:
373373
(void) fprintf(stderr, gettext("filesystem "

cmd/zdb/zdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4564,7 +4564,7 @@ dump_path_impl(objset_t *os, uint64_t obj, char *name)
45644564
case DMU_OT_DIRECTORY_CONTENTS:
45654565
if (s != NULL && *(s + 1) != '\0')
45664566
return (dump_path_impl(os, child_obj, s + 1));
4567-
/*FALLTHROUGH*/
4567+
fallthrough;
45684568
case DMU_OT_PLAIN_FILE_CONTENTS:
45694569
dump_object(os, child_obj, dump_opt['v'], &header, NULL, 0);
45704570
return (0);

cmd/zfs/zfs_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7310,6 +7310,7 @@ unshare_unmount(int op, int argc, char **argv)
73107310
if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) ==
73117311
ZFS_CANMOUNT_NOAUTO)
73127312
continue;
7313+
break;
73137314
default:
73147315
break;
73157316
}

config/Rules.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ AM_LIBTOOLFLAGS = --silent
2626
AM_CFLAGS = -std=gnu99 -Wall -Wstrict-prototypes -Wmissing-prototypes
2727
AM_CFLAGS += -fno-strict-aliasing
2828
AM_CFLAGS += $(NO_OMIT_FRAME_POINTER)
29+
AM_CFLAGS += $(IMPLICIT_FALLTHROUGH)
2930
AM_CFLAGS += $(DEBUG_CFLAGS)
3031
AM_CFLAGS += $(ASAN_CFLAGS)
3132
AM_CFLAGS += $(CODE_COVERAGE_CFLAGS) $(NO_FORMAT_ZERO_LENGTH)

config/always-compiler-options.m4

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,29 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_UNUSED_BUT_SET_VARIABLE], [
161161
AC_SUBST([NO_UNUSED_BUT_SET_VARIABLE])
162162
])
163163

164+
dnl #
165+
dnl # Check if gcc supports -Wimplicit-fallthrough option.
166+
dnl #
167+
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH], [
168+
AC_MSG_CHECKING([whether $CC supports -Wimplicit-fallthrough])
169+
170+
saved_flags="$CFLAGS"
171+
CFLAGS="$CFLAGS -Werror -Wimplicit-fallthrough"
172+
173+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
174+
IMPLICIT_FALLTHROUGH=-Wimplicit-fallthrough
175+
AC_DEFINE([HAVE_IMPLICIT_FALLTHROUGH], 1,
176+
[Define if compiler supports -Wimplicit-fallthrough])
177+
AC_MSG_RESULT([yes])
178+
], [
179+
IMPLICIT_FALLTHROUGH=
180+
AC_MSG_RESULT([no])
181+
])
182+
183+
CFLAGS="$saved_flags"
184+
AC_SUBST([IMPLICIT_FALLTHROUGH])
185+
])
186+
164187
dnl #
165188
dnl # Check if gcc supports -fno-omit-frame-pointer option.
166189
dnl #

config/zfs-build.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
158158
159159
ZFS_AC_CONFIG_ALWAYS_CC_NO_UNUSED_BUT_SET_VARIABLE
160160
ZFS_AC_CONFIG_ALWAYS_CC_NO_BOOL_COMPARE
161+
ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH
161162
ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
162163
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION
163164
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH

include/os/freebsd/linux/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#define __always_inline inline
6868
#define noinline __noinline
6969
#define ____cacheline_aligned __aligned(CACHE_LINE_SIZE)
70+
#define fallthrough __attribute__((__fallthrough__))
7071

7172
#if !defined(_KERNEL) && !defined(_STANDALONE)
7273
#define likely(x) __builtin_expect(!!(x), 1)

include/os/linux/kernel/linux/compiler_compat.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828

2929
#include <linux/compiler.h>
3030

31+
#if !defined(fallthrough)
32+
#if defined(HAVE_IMPLICIT_FALLTHROUGH)
33+
#define fallthrough __attribute__((__fallthrough__))
34+
#else
35+
#define fallthrough ((void)0)
36+
#endif
37+
#endif
38+
3139
#if !defined(READ_ONCE)
3240
#define READ_ONCE(x) ACCESS_ONCE(x)
3341
#endif

include/os/linux/zfs/sys/zfs_context_os.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
#include <sys/uio_impl.h>
2727
#include <linux/dcache_compat.h>
2828
#include <linux/utsname_compat.h>
29+
#include <linux/compiler_compat.h>
2930

3031
#endif

include/sys/zfs_context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,6 @@ extern void spl_fstrans_unmark(fstrans_cookie_t);
759759
extern int __spl_pf_fstrans_check(void);
760760
extern int kmem_cache_reap_active(void);
761761

762-
#define ____cacheline_aligned
763762

764763
/*
765764
* Kernel modules

lib/libspl/include/sys/feature_tests.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
#ifndef _SYS_FEATURE_TESTS_H
2828
#define _SYS_FEATURE_TESTS_H
2929

30-
#define __NORETURN __attribute__((__noreturn__))
30+
#define ____cacheline_aligned
31+
#define __NORETURN __attribute__((__noreturn__))
32+
33+
#if !defined(fallthrough)
34+
#if defined(HAVE_IMPLICIT_FALLTHROUGH)
35+
#define fallthrough __attribute__((__fallthrough__))
36+
#else
37+
#define fallthrough ((void)0)
38+
#endif
39+
#endif
3140

3241
#endif

lib/libzfs/libzfs_dataset.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,10 +1365,9 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
13651365
(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
13661366
goto error;
13671367
}
1368+
fallthrough;
13681369
}
13691370

1370-
/*FALLTHRU*/
1371-
13721371
case ZFS_PROP_SHARESMB:
13731372
case ZFS_PROP_SHARENFS:
13741373
/*
@@ -3767,8 +3766,8 @@ zfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type,
37673766
if (type == ZFS_TYPE_VOLUME)
37683767
return (zfs_error(hdl, EZFS_VOLTOOBIG,
37693768
errbuf));
3769+
fallthrough;
37703770
#endif
3771-
/* FALLTHROUGH */
37723771
default:
37733772
return (zfs_standard_error(hdl, errno, errbuf));
37743773
}

lib/libzfs/libzfs_pool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
309309
len);
310310
break;
311311
}
312-
/* FALLTHROUGH */
312+
fallthrough;
313313
default:
314314
(void) strlcpy(buf, "-", len);
315315
break;
@@ -400,7 +400,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
400400
(void) snprintf(buf, len, "-");
401401
break;
402402
}
403-
/* FALLTHROUGH */
403+
fallthrough;
404404
default:
405405
(void) snprintf(buf, len, "%llu", (u_longlong_t)intval);
406406
}

lib/libzfs/libzfs_sendrecv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4883,7 +4883,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
48834883
(void) zfs_error(hdl, EZFS_BUSY, errbuf);
48844884
break;
48854885
}
4886-
/* fallthru */
4886+
fallthrough;
48874887
default:
48884888
(void) zfs_standard_error(hdl, ioctl_errno, errbuf);
48894889
}

lib/libzfs/libzfs_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ zfs_setprop_error(libzfs_handle_t *hdl, zfs_prop_t prop, int err,
598598
break;
599599
}
600600
#endif
601-
/* FALLTHROUGH */
601+
fallthrough;
602602
default:
603603
(void) zfs_standard_error(hdl, err, errbuf);
604604
}

lib/libzfsbootenv/lzbe_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ lzbe_set_boot_device(const char *pool, lzbe_flags_t flag, const char *device)
6363
/* Drop this nvlist */
6464
fnvlist_free(nv);
6565
}
66-
/* FALLTHROUGH */
66+
fallthrough;
6767
case lzbe_replace:
6868
nv = fnvlist_alloc();
6969
break;

module/icp/core/kcf_prov_tabs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ kcf_provider_zero_refcnt(kcf_provider_desc_t *desc)
377377
mutex_exit(&desc->pd_lock);
378378
break;
379379
}
380-
/* FALLTHRU */
380+
fallthrough;
381381

382382
case CRYPTO_HW_PROVIDER:
383383
case CRYPTO_LOGICAL_PROVIDER:

module/icp/io/aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ aes_encrypt_atomic(crypto_provider_handle_t provider,
976976
case AES_GMAC_MECH_INFO_TYPE:
977977
if (plaintext->cd_length != 0)
978978
return (CRYPTO_ARGUMENTS_BAD);
979-
/* FALLTHRU */
979+
fallthrough;
980980
case AES_GCM_MECH_INFO_TYPE:
981981
length_needed = plaintext->cd_length + aes_ctx.ac_tag_len;
982982
break;

module/lua/lcode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#define lcode_c
99
#define LUA_CORE
1010

11+
#if defined(HAVE_IMPLICIT_FALLTHROUGH)
12+
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
13+
#endif
14+
1115
#include <sys/lua/lua.h>
1216

1317
#include "lcode.h"

module/lua/lgc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ static void freeobj (lua_State *L, GCObject *o) {
676676
case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
677677
case LUA_TSHRSTR:
678678
G(L)->strt.nuse--;
679-
/* FALLTHROUGH */
679+
fallthrough;
680680
case LUA_TLNGSTR: {
681681
luaM_freemem(L, o, sizestring(gco2ts(o)));
682682
break;

module/lua/llex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static int llex (LexState *ls, SemInfo *seminfo) {
477477
else if (!lisdigit(ls->current)) return '.';
478478
/* else go through */
479479
}
480-
/* FALLTHROUGH */
480+
fallthrough;
481481
case '0': case '1': case '2': case '3': case '4':
482482
case '5': case '6': case '7': case '8': case '9': {
483483
read_numeral(ls, seminfo);

module/lua/lstrlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
501501
}
502502
case '+': /* 1 or more repetitions */
503503
s++; /* 1 match already done */
504-
/* FALLTHROUGH */
504+
fallthrough;
505505
case '*': /* 0 or more repetitions */
506506
s = max_expand(ms, s, p, ep);
507507
break;

module/lua/ltable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
492492
return luaH_getint(t, k); /* use specialized version */
493493
/* else go through */
494494
}
495-
/* FALLTHROUGH */
495+
fallthrough;
496496
default: {
497497
Node *n = mainposition(t, key);
498498
do { /* check whether `key' is somewhere in the chain */

module/os/freebsd/zfs/zfs_acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ zfs_ace_fuid_size(void *acep)
269269
entry_type == OWNING_GROUP ||
270270
entry_type == ACE_EVERYONE)
271271
return (sizeof (zfs_ace_hdr_t));
272-
/*FALLTHROUGH*/
272+
fallthrough;
273273
default:
274274
return (sizeof (zfs_ace_t));
275275
}
@@ -2151,7 +2151,7 @@ zfs_zaccess_aces_check(znode_t *zp, uint32_t *working_mode,
21512151
break;
21522152
case OWNING_GROUP:
21532153
who = gowner;
2154-
/*FALLTHROUGH*/
2154+
fallthrough;
21552155
case ACE_IDENTIFIER_GROUP:
21562156
checkit = zfs_groupmember(zfsvfs, who, cr);
21572157
break;

module/os/freebsd/zfs/zfs_vnops_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ zfs_lookup(vnode_t *dvp, const char *nm, vnode_t **vpp,
974974
cnp->cn_flags |= SAVENAME;
975975
break;
976976
}
977-
/* FALLTHROUGH */
977+
fallthrough;
978978
case DELETE:
979979
if (error == 0)
980980
cnp->cn_flags |= SAVENAME;

module/os/linux/zfs/zfs_acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ zfs_ace_fuid_size(void *acep)
269269
entry_type == OWNING_GROUP ||
270270
entry_type == ACE_EVERYONE)
271271
return (sizeof (zfs_ace_hdr_t));
272-
/*FALLTHROUGH*/
272+
fallthrough;
273273
default:
274274
return (sizeof (zfs_ace_t));
275275
}
@@ -2317,7 +2317,7 @@ zfs_zaccess_aces_check(znode_t *zp, uint32_t *working_mode,
23172317
break;
23182318
case OWNING_GROUP:
23192319
who = gowner;
2320-
/*FALLTHROUGH*/
2320+
fallthrough;
23212321
case ACE_IDENTIFIER_GROUP:
23222322
checkit = zfs_groupmember(zfsvfs, who, cr);
23232323
break;

module/os/linux/zfs/zfs_znode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ zfs_inode_set_ops(zfsvfs_t *zfsvfs, struct inode *ip)
430430
case S_IFBLK:
431431
(void) sa_lookup(ITOZ(ip)->z_sa_hdl, SA_ZPL_RDEV(zfsvfs), &rdev,
432432
sizeof (rdev));
433-
/*FALLTHROUGH*/
433+
fallthrough;
434434
case S_IFIFO:
435435
case S_IFSOCK:
436436
init_special_inode(ip, ip->i_mode, rdev);

module/zfs/abd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,10 @@ abd_raidz_gen_iterate(abd_t **cabds, abd_t *dabd,
10641064
switch (parity) {
10651065
case 3:
10661066
len = MIN(caiters[2].iter_mapsize, len);
1067-
/* falls through */
1067+
fallthrough;
10681068
case 2:
10691069
len = MIN(caiters[1].iter_mapsize, len);
1070-
/* falls through */
1070+
fallthrough;
10711071
case 1:
10721072
len = MIN(caiters[0].iter_mapsize, len);
10731073
}
@@ -1177,11 +1177,11 @@ abd_raidz_rec_iterate(abd_t **cabds, abd_t **tabds,
11771177
case 3:
11781178
len = MIN(xiters[2].iter_mapsize, len);
11791179
len = MIN(citers[2].iter_mapsize, len);
1180-
/* falls through */
1180+
fallthrough;
11811181
case 2:
11821182
len = MIN(xiters[1].iter_mapsize, len);
11831183
len = MIN(citers[1].iter_mapsize, len);
1184-
/* falls through */
1184+
fallthrough;
11851185
case 1:
11861186
len = MIN(xiters[0].iter_mapsize, len);
11871187
len = MIN(citers[0].iter_mapsize, len);

module/zfs/dsl_prop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ dsl_prop_set_sync_impl(dsl_dataset_t *ds, const char *propname,
749749
ASSERT(err == 0 || err == ENOENT);
750750
err = zap_remove(mos, zapobj, inheritstr, tx);
751751
ASSERT(err == 0 || err == ENOENT);
752-
/* FALLTHRU */
752+
fallthrough;
753753
case (ZPROP_SRC_NONE | ZPROP_SRC_RECEIVED):
754754
/*
755755
* remove propname$recvd

module/zfs/spa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9533,7 +9533,7 @@ spa_activity_in_progress(spa_t *spa, zpool_wait_activity_t activity,
95339533
case ZPOOL_WAIT_RESILVER:
95349534
if ((*in_progress = vdev_rebuild_active(spa->spa_root_vdev)))
95359535
break;
9536-
/* fall through */
9536+
fallthrough;
95379537
case ZPOOL_WAIT_SCRUB:
95389538
{
95399539
boolean_t scanning, paused, is_scrub;

module/zfs/vdev_label.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ vdev_label_read_bootenv(vdev_t *rvd, nvlist_t *bootenv)
12881288
nvlist_free(config);
12891289
break;
12901290
}
1291-
/* FALLTHROUGH */
1291+
fallthrough;
12921292
default:
12931293
/* Check for FreeBSD zfs bootonce command string */
12941294
buf = abd_to_buf(abd);

module/zfs/vdev_raidz_math_scalar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static const struct {
142142
a.b[6] = mul_lt[a.b[6]]; \
143143
a.b[5] = mul_lt[a.b[5]]; \
144144
a.b[4] = mul_lt[a.b[4]]; \
145-
/* falls through */ \
145+
fallthrough; \
146146
case 4: \
147147
a.b[3] = mul_lt[a.b[3]]; \
148148
a.b[2] = mul_lt[a.b[2]]; \

0 commit comments

Comments
 (0)