Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: csiostor: Avoid function pointer casts

csiostor uses function pointer casts to keep the csio_ln_ev state machine
hidden, but this causes warnings about control flow integrity (KCFI)
violations in clang-16 and higher:

drivers/scsi/csiostor/csio_lnode.c:1098:33: error: cast from 'void (*)(struct csio_lnode *, enum csio_ln_ev)' to 'csio_sm_state_t' (aka 'void (*)(void *, unsigned int)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
1098 | return (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/csiostor/csio_lnode.c:1369:29: error: cast from 'void (*)(struct csio_lnode *, enum csio_ln_ev)' to 'csio_sm_state_t' (aka 'void (*)(void *, unsigned int)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
1369 | if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_uninit)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/csiostor/csio_lnode.c:1373:29: error: cast from 'void (*)(struct csio_lnode *, enum csio_ln_ev)' to 'csio_sm_state_t' (aka 'void (*)(void *, unsigned int)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
1373 | if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/csiostor/csio_lnode.c:1377:29: error: cast from 'void (*)(struct csio_lnode *, enum csio_ln_ev)' to 'csio_sm_state_t' (aka 'void (*)(void *, unsigned int)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
1377 | if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_offline)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Move the enum into a shared header so the correct types can be used without
the need for casts.

Fixes: a3667aaed569 ("[SCSI] csiostor: Chelsio FCoE offload driver")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20240213100518.457623-1-arnd@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Arnd Bergmann and committed by
Martin K. Petersen
9f3dbcb5 b628db42

+20 -19
+16 -2
drivers/scsi/csiostor/csio_defs.h
··· 73 73 #define csio_list_prev(elem) (((struct list_head *)(elem))->prev) 74 74 75 75 /* State machine */ 76 - typedef void (*csio_sm_state_t)(void *, uint32_t); 76 + struct csio_lnode; 77 + 78 + /* State machine evets */ 79 + enum csio_ln_ev { 80 + CSIO_LNE_NONE = (uint32_t)0, 81 + CSIO_LNE_LINKUP, 82 + CSIO_LNE_FAB_INIT_DONE, 83 + CSIO_LNE_LINK_DOWN, 84 + CSIO_LNE_DOWN_LINK, 85 + CSIO_LNE_LOGO, 86 + CSIO_LNE_CLOSE, 87 + CSIO_LNE_MAX_EVENT, 88 + }; 89 + 90 + typedef void (*csio_sm_state_t)(struct csio_lnode *ln, enum csio_ln_ev evt); 77 91 78 92 struct csio_sm { 79 93 struct list_head sm_list; ··· 97 83 static inline void 98 84 csio_set_state(void *smp, void *state) 99 85 { 100 - ((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state; 86 + ((struct csio_sm *)smp)->sm_state = state; 101 87 } 102 88 103 89 static inline void
+4 -4
drivers/scsi/csiostor/csio_lnode.c
··· 1095 1095 int 1096 1096 csio_is_lnode_ready(struct csio_lnode *ln) 1097 1097 { 1098 - return (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready)); 1098 + return (csio_get_state(ln) == csio_lns_ready); 1099 1099 } 1100 1100 1101 1101 /*****************************************************************************/ ··· 1366 1366 void 1367 1367 csio_lnode_state_to_str(struct csio_lnode *ln, int8_t *str) 1368 1368 { 1369 - if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_uninit)) { 1369 + if (csio_get_state(ln) == csio_lns_uninit) { 1370 1370 strcpy(str, "UNINIT"); 1371 1371 return; 1372 1372 } 1373 - if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready)) { 1373 + if (csio_get_state(ln) == csio_lns_ready) { 1374 1374 strcpy(str, "READY"); 1375 1375 return; 1376 1376 } 1377 - if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_offline)) { 1377 + if (csio_get_state(ln) == csio_lns_offline) { 1378 1378 strcpy(str, "OFFLINE"); 1379 1379 return; 1380 1380 }
-13
drivers/scsi/csiostor/csio_lnode.h
··· 53 53 extern int csio_fcoe_rnodes; 54 54 extern int csio_fdmi_enable; 55 55 56 - /* State machine evets */ 57 - enum csio_ln_ev { 58 - CSIO_LNE_NONE = (uint32_t)0, 59 - CSIO_LNE_LINKUP, 60 - CSIO_LNE_FAB_INIT_DONE, 61 - CSIO_LNE_LINK_DOWN, 62 - CSIO_LNE_DOWN_LINK, 63 - CSIO_LNE_LOGO, 64 - CSIO_LNE_CLOSE, 65 - CSIO_LNE_MAX_EVENT, 66 - }; 67 - 68 - 69 56 struct csio_fcf_info { 70 57 struct list_head list; 71 58 uint8_t priority;