Skip to content

Commit 9f3dbcb

Browse files
arndbmartinkpetersen
authored andcommitted
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: a3667aa ("[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>
1 parent b628db4 commit 9f3dbcb

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

drivers/scsi/csiostor/csio_defs.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,21 @@ csio_list_deleted(struct list_head *list)
7373
#define csio_list_prev(elem) (((struct list_head *)(elem))->prev)
7474

7575
/* 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);
7791

7892
struct csio_sm {
7993
struct list_head sm_list;
@@ -83,7 +97,7 @@ struct csio_sm {
8397
static inline void
8498
csio_set_state(void *smp, void *state)
8599
{
86-
((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state;
100+
((struct csio_sm *)smp)->sm_state = state;
87101
}
88102

89103
static inline void

drivers/scsi/csiostor/csio_lnode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ csio_handle_link_down(struct csio_hw *hw, uint8_t portid, uint32_t fcfi,
10951095
int
10961096
csio_is_lnode_ready(struct csio_lnode *ln)
10971097
{
1098-
return (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready));
1098+
return (csio_get_state(ln) == csio_lns_ready);
10991099
}
11001100

11011101
/*****************************************************************************/
@@ -1366,15 +1366,15 @@ csio_free_fcfinfo(struct kref *kref)
13661366
void
13671367
csio_lnode_state_to_str(struct csio_lnode *ln, int8_t *str)
13681368
{
1369-
if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_uninit)) {
1369+
if (csio_get_state(ln) == csio_lns_uninit) {
13701370
strcpy(str, "UNINIT");
13711371
return;
13721372
}
1373-
if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready)) {
1373+
if (csio_get_state(ln) == csio_lns_ready) {
13741374
strcpy(str, "READY");
13751375
return;
13761376
}
1377-
if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_offline)) {
1377+
if (csio_get_state(ln) == csio_lns_offline) {
13781378
strcpy(str, "OFFLINE");
13791379
return;
13801380
}

drivers/scsi/csiostor/csio_lnode.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,6 @@
5353
extern int csio_fcoe_rnodes;
5454
extern int csio_fdmi_enable;
5555

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-
6956
struct csio_fcf_info {
7057
struct list_head list;
7158
uint8_t priority;

0 commit comments

Comments
 (0)