Page MenuHomeFreeBSD

mlx4: use enum constants instead of const vars for case exprs
ClosedPublic

Authored by rlibby on Oct 14 2017, 8:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 18 2024, 9:06 PM
Unknown Object (File)
Sep 30 2024, 6:11 PM
Unknown Object (File)
Sep 4 2024, 1:14 PM
Unknown Object (File)
Sep 2 2024, 2:39 AM
Unknown Object (File)
Sep 1 2024, 3:13 PM
Unknown Object (File)
Aug 27 2024, 10:05 PM
Unknown Object (File)
Aug 15 2024, 7:35 PM
Unknown Object (File)
Jul 26 2024, 11:28 PM
Subscribers
None

Details

Summary

mlx4: use enum constants instead of const vars for case exprs

Follow up from r324201 to fix compilation with gcc, which complains
about non-ICE case expressions.

Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D12675

Test Plan

buildkernel (clang & gcc)

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

What is the purpose of this change?

What is the purpose of this change?

This unbreaks compilation with gcc after r324201. Gcc wants case expressions to be constant expressions.

% make CROSS_TOOLCHAIN=amd64-gcc TARGET=amd64 TARGET_ARCH=amd64 buildkernel
[...]
===> mlx4en (all)
/usr/local/bin/x86_64-unknown-freebsd12.0-gcc -isystem /usr/obj/amd64-gcc/usr/src/freebsd/tmp/usr/include -L/usr/obj/amd64-gcc/usr/src/freebsd/tmp/usr/lib -B/usr/obj/amd64-gcc/usr/src/freebsd/tmp/usr/lib --sysroot=/usr/obj/amd64-gcc/usr/src/freebsd/tmp -B/usr/local/x86_64-freebsd/bin/  -O2 -pipe  -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc  -I/usr/src/freebsd/sys/ofed/include -I/usr/src/freebsd/sys/compat/linuxkpi/common/include -DHAVE_KERNEL_OPTION_HEADERS -include /usr/obj/amd64-gcc/usr/src/freebsd/sys/GENERIC/opt_global.h -I. -I/usr/src/freebsd/sys -fno-common -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -I/usr/obj/amd64-gcc/usr/src/freebsd/sys/GENERIC   -MD  -MF.depend.mlx4_en_rx.o -MTmlx4_en_rx.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -gdwarf-2 -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -fformat-extensions -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=address -Wno-error=aggressive-loop-optimizations -Wno-error=array-bounds -Wno-error=attributes -Wno-error=cast-qual -Wno-error=enum-compare -Wno-error=inline -Wno-error=maybe-uninitialized -Wno-error=overflow -Wno-error=sequence-point -Wno-error=unused-but-set-variable -Wno-error=misleading-indentation -Wno-error=nonnull-compare -Wno-error=shift-overflow -Wno-error=tautological-compare  -finline-limit=8000 -fms-extensions --param inline-unit-growth=100 --param large-function-growth=1000  -std=iso9899:1999 -c /usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c -o mlx4_en_rx.o
In file included from /usr/src/freebsd/sys/compat/linuxkpi/common/include/linux/types.h:38:0,
                 from /usr/src/freebsd/sys/dev/mlx4/cq.h:36,
                 from /usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:34:
/usr/src/freebsd/sys/compat/linuxkpi/common/include/linux/list.h: In function '__list_del':
/usr/src/freebsd/sys/compat/linuxkpi/common/include/linux/compiler.h:82:28: warning: to be safe all intermediate pointers in cast from 'struct list_head **' to 'struct list_head * volatile*' must be 'const' qualified [-Wcast-qual]
 #define ACCESS_ONCE(x)   (*(volatile __typeof(x) *)&(x))
                            ^
/usr/src/freebsd/sys/compat/linuxkpi/common/include/linux/compiler.h:86:2: note: in expansion of macro 'ACCESS_ONCE'
  ACCESS_ONCE(x) = (v);  \
  ^~~~~~~~~~~
/usr/src/freebsd/sys/compat/linuxkpi/common/include/linux/list.h:116:2: note: in expansion of macro 'WRITE_ONCE'
  WRITE_ONCE(prev->next, next);
  ^~~~~~~~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c: In function 'mlx4_en_rss_hash':
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:584:2: error: case label does not reduce to an integer constant
  case status_ipv4_tcp:
  ^~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:586:2: error: case label does not reduce to an integer constant
  case status_ipv6_tcp:
  ^~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:588:2: error: case label does not reduce to an integer constant
  case status_ipv4_udp:
  ^~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:591:2: error: case label does not reduce to an integer constant
  case status_ipv6_udp:
  ^~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:576:15: warning: variable 'status_ipv6_udp' set but not used [-Wunused-but-set-variable]
  const __be16 status_ipv6_udp = cpu_to_be16(
               ^~~~~~~~~~~~~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:573:15: warning: variable 'status_ipv4_udp' set but not used [-Wunused-but-set-variable]
  const __be16 status_ipv4_udp = cpu_to_be16(
               ^~~~~~~~~~~~~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:570:15: warning: variable 'status_ipv6_tcp' set but not used [-Wunused-but-set-variable]
  const __be16 status_ipv6_tcp = cpu_to_be16(
               ^~~~~~~~~~~~~~~
/usr/src/freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c:567:15: warning: variable 'status_ipv4_tcp' set but not used [-Wunused-but-set-variable]
  const __be16 status_ipv4_tcp = cpu_to_be16(
               ^~~~~~~~~~~~~~~
*** Error code 1

Stop.
make[4]: stopped in /usr/src/freebsd/sys/modules/mlx4en
*** Error code 1

Stop.
make[3]: stopped in /usr/src/freebsd/sys/modules
*** Error code 1

Stop.
make[2]: stopped in /usr/obj/amd64-gcc/usr/src/freebsd/sys/GENERIC
*** Error code 1

Stop.
make[1]: stopped in /usr/src/freebsd
*** Error code 1

Stop.
make: stopped in /usr/src/freebsd
sys/dev/mlx4/mlx4_en/mlx4_en_rx.c
567 ↗(On Diff #33993)

I suggest you use "enum" to fix this.

enum {
status_all = ... ,
status_ipv4_tcp = ...,
};

OK?

sys/dev/mlx4/mlx4_en/mlx4_en_rx.c
567 ↗(On Diff #33993)

Keep the cpu_to_be16() inside the enum definition..

rlibby added inline comments.
sys/dev/mlx4/mlx4_en/mlx4_en_rx.c
567 ↗(On Diff #33993)

Ah, much better, thanks. Update coming.

hselasky feedback: replace const vars with enum constants

Just give this patch a spin with clang aswell before committing. I'll handle this issue towards Mellanox.

Thank you!

--HPS

This revision is now accepted and ready to land.Oct 14 2017, 10:18 PM
rlibby retitled this revision from mlx4: make case labels ICE to please gcc to mlx4: use enum constants instead of const vars for case exprs.Oct 14 2017, 10:22 PM
rlibby edited the summary of this revision. (Show Details)
rlibby edited the test plan for this revision. (Show Details)

Just give this patch a spin with clang aswell before committing. I'll handle this issue towards Mellanox.

Thank you!

--HPS

Yep, just checked with gcc and clang.

+ Update the commit message :-)

Updated summary to intended commit message.

Thanks!

This revision was automatically updated to reflect the committed changes.