Skip to content

Commit

Permalink
Use fallthrough macro
Browse files Browse the repository at this point in the history
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 <tony.nguyen@delphix.com>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#12441
  • Loading branch information
behlendorf authored and tonyhutter committed Nov 2, 2021
1 parent d8a97a7 commit 143476c
Show file tree
Hide file tree
Showing 36 changed files with 87 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/mount_zfs/mount_zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ main(int argc, char **argv)
"mount the filesystem again.\n"), dataset);
return (MOUNT_SYSERR);
}
/* fallthru */
fallthrough;
#endif
default:
(void) fprintf(stderr, gettext("filesystem "
Expand Down
2 changes: 1 addition & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4573,7 +4573,7 @@ dump_path_impl(objset_t *os, uint64_t obj, char *name, uint64_t *retobj)
case DMU_OT_DIRECTORY_CONTENTS:
if (s != NULL && *(s + 1) != '\0')
return (dump_path_impl(os, child_obj, s + 1, retobj));
/*FALLTHROUGH*/
fallthrough;
case DMU_OT_PLAIN_FILE_CONTENTS:
if (retobj != NULL) {
*retobj = child_obj;
Expand Down
1 change: 1 addition & 0 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7475,6 +7475,7 @@ unshare_unmount(int op, int argc, char **argv)
if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) ==
ZFS_CANMOUNT_NOAUTO)
continue;
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions cmd/zpool_influxdb/zpool_influxdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ escape_string(char *s)
case '=':
case '\\':
*d++ = '\\';
fallthrough;
default:
*d = *c;
}
Expand Down
1 change: 1 addition & 0 deletions config/Rules.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ AM_LIBTOOLFLAGS = --silent
AM_CFLAGS = -std=gnu99 -Wall -Wstrict-prototypes -Wmissing-prototypes
AM_CFLAGS += -fno-strict-aliasing
AM_CFLAGS += $(NO_OMIT_FRAME_POINTER)
AM_CFLAGS += $(IMPLICIT_FALLTHROUGH)
AM_CFLAGS += $(DEBUG_CFLAGS)
AM_CFLAGS += $(ASAN_CFLAGS)
AM_CFLAGS += $(CODE_COVERAGE_CFLAGS) $(NO_FORMAT_ZERO_LENGTH)
Expand Down
23 changes: 23 additions & 0 deletions config/always-compiler-options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_UNUSED_BUT_SET_VARIABLE], [
AC_SUBST([NO_UNUSED_BUT_SET_VARIABLE])
])

dnl #
dnl # Check if gcc supports -Wimplicit-fallthrough option.
dnl #
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH], [
AC_MSG_CHECKING([whether $CC supports -Wimplicit-fallthrough])
saved_flags="$CFLAGS"
CFLAGS="$CFLAGS -Werror -Wimplicit-fallthrough"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
IMPLICIT_FALLTHROUGH=-Wimplicit-fallthrough
AC_DEFINE([HAVE_IMPLICIT_FALLTHROUGH], 1,
[Define if compiler supports -Wimplicit-fallthrough])
AC_MSG_RESULT([yes])
], [
IMPLICIT_FALLTHROUGH=
AC_MSG_RESULT([no])
])
CFLAGS="$saved_flags"
AC_SUBST([IMPLICIT_FALLTHROUGH])
])

dnl #
dnl # Check if gcc supports -fno-omit-frame-pointer option.
dnl #
Expand Down
1 change: 1 addition & 0 deletions config/zfs-build.m4
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
ZFS_AC_CONFIG_ALWAYS_CC_NO_UNUSED_BUT_SET_VARIABLE
ZFS_AC_CONFIG_ALWAYS_CC_NO_BOOL_COMPARE
ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH
ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION
ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH
Expand Down
1 change: 1 addition & 0 deletions include/os/freebsd/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define __always_inline inline
#define noinline __noinline
#define ____cacheline_aligned __aligned(CACHE_LINE_SIZE)
#define fallthrough __attribute__((__fallthrough__))

#if !defined(_KERNEL) && !defined(_STANDALONE)
#define likely(x) __builtin_expect(!!(x), 1)
Expand Down
8 changes: 8 additions & 0 deletions include/os/linux/kernel/linux/compiler_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@

#include <linux/compiler.h>

#if !defined(fallthrough)
#if defined(HAVE_IMPLICIT_FALLTHROUGH)
#define fallthrough __attribute__((__fallthrough__))
#else
#define fallthrough ((void)0)
#endif
#endif

#if !defined(READ_ONCE)
#define READ_ONCE(x) ACCESS_ONCE(x)
#endif
Expand Down
1 change: 1 addition & 0 deletions include/os/linux/zfs/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <linux/dcache_compat.h>
#include <linux/utsname_compat.h>
#include <linux/compiler_compat.h>
#include <linux/module.h>

#if THREAD_SIZE >= 16384
Expand Down
1 change: 0 additions & 1 deletion include/sys/zfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ extern void spl_fstrans_unmark(fstrans_cookie_t);
extern int __spl_pf_fstrans_check(void);
extern int kmem_cache_reap_active(void);

#define ____cacheline_aligned

/*
* Kernel modules
Expand Down
11 changes: 10 additions & 1 deletion lib/libspl/include/sys/feature_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
#ifndef _SYS_FEATURE_TESTS_H
#define _SYS_FEATURE_TESTS_H

#define __NORETURN __attribute__((__noreturn__))
#define ____cacheline_aligned
#define __NORETURN __attribute__((__noreturn__))

#if !defined(fallthrough)
#if defined(HAVE_IMPLICIT_FALLTHROUGH)
#define fallthrough __attribute__((__fallthrough__))
#else
#define fallthrough ((void)0)
#endif
#endif

#endif
5 changes: 2 additions & 3 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,9 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
goto error;
}
fallthrough;
}

/*FALLTHRU*/

case ZFS_PROP_SHARESMB:
case ZFS_PROP_SHARENFS:
/*
Expand Down Expand Up @@ -3765,8 +3764,8 @@ zfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type,
if (type == ZFS_TYPE_VOLUME)
return (zfs_error(hdl, EZFS_VOLTOOBIG,
errbuf));
fallthrough;
#endif
/* FALLTHROUGH */
default:
return (zfs_standard_error(hdl, errno, errbuf));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
len);
break;
}
/* FALLTHROUGH */
fallthrough;
default:
(void) strlcpy(buf, "-", len);
break;
Expand Down Expand Up @@ -405,7 +405,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
(void) snprintf(buf, len, "-");
break;
}
/* FALLTHROUGH */
fallthrough;
default:
(void) snprintf(buf, len, "%llu", (u_longlong_t)intval);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4878,7 +4878,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
(void) zfs_error(hdl, EZFS_BUSY, errbuf);
break;
}
/* fallthru */
fallthrough;
default:
(void) zfs_standard_error(hdl, ioctl_errno, errbuf);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ zfs_setprop_error(libzfs_handle_t *hdl, zfs_prop_t prop, int err,
break;
}
#endif
/* FALLTHROUGH */
fallthrough;
default:
(void) zfs_standard_error(hdl, err, errbuf);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfsbootenv/lzbe_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ lzbe_set_boot_device(const char *pool, lzbe_flags_t flag, const char *device)
/* Drop this nvlist */
fnvlist_free(nv);
}
/* FALLTHROUGH */
fallthrough;
case lzbe_replace:
nv = fnvlist_alloc();
break;
Expand Down
2 changes: 2 additions & 0 deletions lib/libzutil/zutil_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,11 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
// This shouldn't be possible to
// encounter, die if we do.
ASSERT(B_FALSE);
fallthrough;
case EOPNOTSUPP:
case ENOSYS:
do_slow = B_TRUE;
fallthrough;
case 0:
default:
(void) aio_return(&aiocbs[l]);
Expand Down
2 changes: 1 addition & 1 deletion module/icp/core/kcf_prov_tabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ kcf_provider_zero_refcnt(kcf_provider_desc_t *desc)
mutex_exit(&desc->pd_lock);
break;
}
/* FALLTHRU */
fallthrough;

case CRYPTO_HW_PROVIDER:
case CRYPTO_LOGICAL_PROVIDER:
Expand Down
2 changes: 1 addition & 1 deletion module/icp/io/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ aes_encrypt_atomic(crypto_provider_handle_t provider,
case AES_GMAC_MECH_INFO_TYPE:
if (plaintext->cd_length != 0)
return (CRYPTO_ARGUMENTS_BAD);
/* FALLTHRU */
fallthrough;
case AES_GCM_MECH_INFO_TYPE:
length_needed = plaintext->cd_length + aes_ctx.ac_tag_len;
break;
Expand Down
4 changes: 4 additions & 0 deletions module/lua/lcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#define lcode_c
#define LUA_CORE

#if defined(HAVE_IMPLICIT_FALLTHROUGH)
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif

#include <sys/lua/lua.h>

#include "lcode.h"
Expand Down
2 changes: 1 addition & 1 deletion module/lua/lgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ static void freeobj (lua_State *L, GCObject *o) {
case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
case LUA_TSHRSTR:
G(L)->strt.nuse--;
/* FALLTHROUGH */
fallthrough;
case LUA_TLNGSTR: {
luaM_freemem(L, o, sizestring(gco2ts(o)));
break;
Expand Down
2 changes: 1 addition & 1 deletion module/lua/llex.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static int llex (LexState *ls, SemInfo *seminfo) {
else if (!lisdigit(ls->current)) return '.';
/* else go through */
}
/* FALLTHROUGH */
fallthrough;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
read_numeral(ls, seminfo);
Expand Down
2 changes: 1 addition & 1 deletion module/lua/lstrlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
}
case '+': /* 1 or more repetitions */
s++; /* 1 match already done */
/* FALLTHROUGH */
fallthrough;
case '*': /* 0 or more repetitions */
s = max_expand(ms, s, p, ep);
break;
Expand Down
2 changes: 1 addition & 1 deletion module/lua/ltable.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
return luaH_getint(t, k); /* use specialized version */
/* else go through */
}
/* FALLTHROUGH */
fallthrough;
default: {
Node *n = mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
Expand Down
4 changes: 2 additions & 2 deletions module/os/freebsd/zfs/zfs_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ zfs_ace_fuid_size(void *acep)
entry_type == OWNING_GROUP ||
entry_type == ACE_EVERYONE)
return (sizeof (zfs_ace_hdr_t));
/*FALLTHROUGH*/
fallthrough;
default:
return (sizeof (zfs_ace_t));
}
Expand Down Expand Up @@ -2153,7 +2153,7 @@ zfs_zaccess_aces_check(znode_t *zp, uint32_t *working_mode,
break;
case OWNING_GROUP:
who = gowner;
/*FALLTHROUGH*/
fallthrough;
case ACE_IDENTIFIER_GROUP:
checkit = zfs_groupmember(zfsvfs, who, cr);
break;
Expand Down
2 changes: 1 addition & 1 deletion module/os/freebsd/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ zfs_lookup(vnode_t *dvp, const char *nm, vnode_t **vpp,
cnp->cn_flags |= SAVENAME;
break;
}
/* FALLTHROUGH */
fallthrough;
case DELETE:
if (error == 0)
cnp->cn_flags |= SAVENAME;
Expand Down
4 changes: 2 additions & 2 deletions module/os/linux/zfs/zfs_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ zfs_ace_fuid_size(void *acep)
entry_type == OWNING_GROUP ||
entry_type == ACE_EVERYONE)
return (sizeof (zfs_ace_hdr_t));
/*FALLTHROUGH*/
fallthrough;
default:
return (sizeof (zfs_ace_t));
}
Expand Down Expand Up @@ -2317,7 +2317,7 @@ zfs_zaccess_aces_check(znode_t *zp, uint32_t *working_mode,
break;
case OWNING_GROUP:
who = gowner;
/*FALLTHROUGH*/
fallthrough;
case ACE_IDENTIFIER_GROUP:
checkit = zfs_groupmember(zfsvfs, who, cr);
break;
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/zfs/zfs_znode.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ zfs_inode_set_ops(zfsvfs_t *zfsvfs, struct inode *ip)
case S_IFBLK:
(void) sa_lookup(ITOZ(ip)->z_sa_hdl, SA_ZPL_RDEV(zfsvfs), &rdev,
sizeof (rdev));
/*FALLTHROUGH*/
fallthrough;
case S_IFIFO:
case S_IFSOCK:
init_special_inode(ip, ip->i_mode, rdev);
Expand Down
8 changes: 4 additions & 4 deletions module/zfs/abd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,10 @@ abd_raidz_gen_iterate(abd_t **cabds, abd_t *dabd,
switch (parity) {
case 3:
len = MIN(caiters[2].iter_mapsize, len);
/* falls through */
fallthrough;
case 2:
len = MIN(caiters[1].iter_mapsize, len);
/* falls through */
fallthrough;
case 1:
len = MIN(caiters[0].iter_mapsize, len);
}
Expand Down Expand Up @@ -1179,11 +1179,11 @@ abd_raidz_rec_iterate(abd_t **cabds, abd_t **tabds,
case 3:
len = MIN(xiters[2].iter_mapsize, len);
len = MIN(citers[2].iter_mapsize, len);
/* falls through */
fallthrough;
case 2:
len = MIN(xiters[1].iter_mapsize, len);
len = MIN(citers[1].iter_mapsize, len);
/* falls through */
fallthrough;
case 1:
len = MIN(xiters[0].iter_mapsize, len);
len = MIN(citers[0].iter_mapsize, len);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ dsl_prop_set_sync_impl(dsl_dataset_t *ds, const char *propname,
ASSERT(err == 0 || err == ENOENT);
err = zap_remove(mos, zapobj, inheritstr, tx);
ASSERT(err == 0 || err == ENOENT);
/* FALLTHRU */
fallthrough;
case (ZPROP_SRC_NONE | ZPROP_SRC_RECEIVED):
/*
* remove propname$recvd
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/spa.c
Original file line number Diff line number Diff line change
Expand Up @@ -9710,7 +9710,7 @@ spa_activity_in_progress(spa_t *spa, zpool_wait_activity_t activity,
case ZPOOL_WAIT_RESILVER:
if ((*in_progress = vdev_rebuild_active(spa->spa_root_vdev)))
break;
/* fall through */
fallthrough;
case ZPOOL_WAIT_SCRUB:
{
boolean_t scanning, paused, is_scrub;
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/vdev_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ vdev_label_read_bootenv(vdev_t *rvd, nvlist_t *bootenv)
nvlist_free(config);
break;
}
/* FALLTHROUGH */
fallthrough;
default:
/* Check for FreeBSD zfs bootonce command string */
buf = abd_to_buf(abd);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/vdev_raidz_math_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static const struct {
a.b[6] = mul_lt[a.b[6]]; \
a.b[5] = mul_lt[a.b[5]]; \
a.b[4] = mul_lt[a.b[4]]; \
/* falls through */ \
fallthrough; \
case 4: \
a.b[3] = mul_lt[a.b[3]]; \
a.b[2] = mul_lt[a.b[2]]; \
Expand Down
Loading

0 comments on commit 143476c

Please sign in to comment.