scsi: bfa: fix function pointer type mismatch for hcb_qe->cbfn
Subsystems (2)
PATCH v2 1/2 scsi: bfa: fix function pointer type mismatch for hcb_qe->cbfn
From: Arnd Bergmann <[email protected]>
Some callback functions used here take a boolean argument, others take a status argument. This breaks KCFI type checking, so clang now warns about the function pointer cast:
drivers/scsi/bfa/bfad_bsg.c:2138:29: error: cast from 'void (*)(void *, enum bfa_status)' to 'bfa_cb_cbfn_t' (aka 'void (*)(void *, enum bfa_boolean)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
Assuming the code is actually correct here and the callers always match the argument types of the callee, rework this to replace the explicit cast with a union of the two pointer types. This does not change the behavior of the code, so if something is actually broken here, a larger rework may be necessary.
---
v2: no changes, just rending after I noticed I forgot to follow up
after https://lore.kernel.org/all/[email protected]/
--- drivers/scsi/bfa/bfa.h | 9 ++++++++- drivers/scsi/bfa/bfa_core.c | 4 +--- drivers/scsi/bfa/bfa_ioc.h | 8 ++++++-- drivers/scsi/bfa/bfad_bsg.c | 11 ++++------- 4 files changed, 19 insertions(+), 13 deletions(-)
drivers/scsi/bfa/bfa.h +8 -1
@@ -20,7 +20,6 @@struct bfa_s ;typedef void (*bfa_isr_func_t ) (struct bfa_s *bfa,struct bfi_msg_s *m); -typedef void (*bfa_cb_cbfn_status_t ) (void *cbarg,bfa_status_t status);/* * Interrupt message handlers
@@ -437,4 +436,12 @@ struct bfa_cb_pending_q_s { (__qe)->data = (__data); \ } while (0) +#define bfa_pending_q_init_status (__qe, __cbfn, __cbarg, __data) do { \ + bfa_q_qe_init(&((__qe)->hcb_qe.qe)); \ + (__qe)->hcb_qe.cbfn_status = (__cbfn); \ + (__qe)->hcb_qe.cbarg = (__cbarg); \ + (__qe)->hcb_qe.pre_rmv = BFA_TRUE; \ + (__qe)->data = (__data); \ +} while (0) +#endif /* __BFA_H__ */
drivers/scsi/bfa/bfa_core.c +1 -3
@@ -1907,15 +1907,13 @@ bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)struct list_head *qe;struct list_head *qen;struct bfa_cb_qe_s *hcb_qe; -bfa_cb_cbfn_status_t cbfn;list_for_each_safe (qe, qen, comp_q) { hcb_qe = (struct bfa_cb_qe_s *) qe;if (hcb_qe->pre_rmv) {/* qe is invalid after return, dequeue before cbfn() */ list_del (qe); - cbfn = (bfa_cb_cbfn_status_t)(hcb_qe->cbfn); -cbfn (hcb_qe->cbarg, hcb_qe->fw_status); + hcb_qe->cbfn_status (hcb_qe->cbarg, hcb_qe->fw_status); }else hcb_qe->cbfn (hcb_qe->cbarg,BFA_TRUE ); }
drivers/scsi/bfa/bfa_ioc.h +6 -2
@@ -361,14 +361,18 @@ struct bfa_reqq_wait_s {void *cbarg; }; -typedef void (*bfa_cb_cbfn_t ) (void *cbarg,bfa_boolean_t complete); +typedef void (*bfa_cb_cbfn_t ) (void *cbarg,bfa_boolean_t complete); +typedef void (*bfa_cb_cbfn_status_t ) (void *cbarg,bfa_status_t status);/* * Generic BFA callback element. */ struct bfa_cb_qe_s {struct list_head qe; -bfa_cb_cbfn_t cbfn; +union { +bfa_cb_cbfn_status_t cbfn_status; +bfa_cb_cbfn_t cbfn; + };bfa_boolean_t once;bfa_boolean_t pre_rmv;/* set for stack based qe(s) */ bfa_status_t fw_status;/* to access fw status in comp proc */
drivers/scsi/bfa/bfad_bsg.c +4 -7
@@ -2135,8 +2135,7 @@ bfad_iocmd_fcport_get_stats(struct bfad_s *bfad, void *cmd)struct bfa_cb_pending_q_s cb_qe;init_completion (&fcomp.comp); -bfa_pending_q_init (&cb_qe, (bfa_cb_cbfn_t )bfad_hcb_comp, - &fcomp, &iocmd->stats); +bfa_pending_q_init_status (&cb_qe, bfad_hcb_comp, &fcomp, &iocmd->stats);spin_lock_irqsave (&bfad->bfad_lock, flags); iocmd->status =bfa_fcport_get_stats (&bfad->bfa, &cb_qe);spin_unlock_irqrestore (&bfad->bfad_lock, flags);
@@ -2159,7 +2158,7 @@ bfad_iocmd_fcport_reset_stats(struct bfad_s *bfad, void *cmd)struct bfa_cb_pending_q_s cb_qe;init_completion (&fcomp.comp); -bfa_pending_q_init (&cb_qe, (bfa_cb_cbfn_t )bfad_hcb_comp, &fcomp,NULL ); +bfa_pending_q_init_status (&cb_qe, bfad_hcb_comp, &fcomp,NULL );spin_lock_irqsave (&bfad->bfad_lock, flags); iocmd->status =bfa_fcport_clear_stats (&bfad->bfa, &cb_qe);
@@ -2443,8 +2442,7 @@ bfad_iocmd_qos_get_stats(struct bfad_s *bfad, void *cmd)struct bfa_fcport_s *fcport =BFA_FCPORT_MOD (&bfad->bfa);init_completion (&fcomp.comp); -bfa_pending_q_init (&cb_qe, (bfa_cb_cbfn_t )bfad_hcb_comp, - &fcomp, &iocmd->stats); +bfa_pending_q_init_status (&cb_qe, bfad_hcb_comp, &fcomp, &iocmd->stats);spin_lock_irqsave (&bfad->bfad_lock, flags);WARN_ON (!bfa_ioc_get_fcmode (&bfad->bfa.ioc));
@@ -2474,8 +2472,7 @@ bfad_iocmd_qos_reset_stats(struct bfad_s *bfad, void *cmd)struct bfa_fcport_s *fcport =BFA_FCPORT_MOD (&bfad->bfa);init_completion (&fcomp.comp); -bfa_pending_q_init (&cb_qe, (bfa_cb_cbfn_t )bfad_hcb_comp, - &fcomp,NULL ); +bfa_pending_q_init_status (&cb_qe, bfad_hcb_comp, &fcomp,NULL );spin_lock_irqsave (&bfad->bfad_lock, flags);WARN_ON (!bfa_ioc_get_fcmode (&bfad->bfa.ioc));
Signature · 1 line
2.39.2
PATCH v2 2/2 scsi: bfa: fix function pointer type mismatch for state machines
From: Arnd Bergmann <[email protected]>
The bfa driver is full of state machines and a generic abstraction layer for them. This relies on casting function pointers, but that is no longer allowed when CONFIG_CFI_CLANG is enabled and causes a huge number of warnings like:
drivers/scsi/bfa/bfad.c:169:3: error: cast from 'void (*)(struct bfad_s *, enum bfad_sm_event)' to 'bfa_sm_t' (aka 'void (*)(void *, int)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
bfa_sm_set_state(bfad, bfad_sm_created);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Rework the mechanism to no longer require the function pointer casts, by having separate types for each individual state machine. This in turn requires moving the enum definitions for each state machine into the header files in order to define the typedef.
---
v2: drop inadvertant changes to prototype (reported by Kees)
--- drivers/scsi/bfa/bfa.h | 21 ++- drivers/scsi/bfa/bfa_cs.h | 21 +-- drivers/scsi/bfa/bfa_fcpim.c | 51 ----- drivers/scsi/bfa/bfa_fcpim.h | 66 ++++++- drivers/scsi/bfa/bfa_fcs.h | 310 +++++++++++++++++++++---------- drivers/scsi/bfa/bfa_fcs_fcpim.c | 23 ++- drivers/scsi/bfa/bfa_fcs_lport.c | 112 ++--------- drivers/scsi/bfa/bfa_fcs_rport.c | 34 ++-- drivers/scsi/bfa/bfa_ioc.c | 85 ++++----- drivers/scsi/bfa/bfa_ioc.h | 76 ++++++-- drivers/scsi/bfa/bfa_svc.c | 72 +++---- drivers/scsi/bfa/bfa_svc.h | 115 +++++++++--- drivers/scsi/bfa/bfad_drv.h | 31 ++-- 13 files changed, 582 insertions(+), 435 deletions(-)
drivers/scsi/bfa/bfa.h +20 -1
@@ -215,8 +215,27 @@ struct bfa_faa_args_s {bfa_boolean_t busy; }; +/* +* IOCFC state machine definitions/declarations +*/ +enum iocfc_event { +IOCFC_E_INIT =1 ,/* IOCFC init request */ +IOCFC_E_START =2 ,/* IOCFC mod start request */ +IOCFC_E_STOP =3 ,/* IOCFC stop request */ +IOCFC_E_ENABLE =4 ,/* IOCFC enable request */ +IOCFC_E_DISABLE =5 ,/* IOCFC disable request */ +IOCFC_E_IOC_ENABLED =6 ,/* IOC enabled message */ +IOCFC_E_IOC_DISABLED =7 ,/* IOC disabled message */ +IOCFC_E_IOC_FAILED =8 ,/* failure notice by IOC sm */ +IOCFC_E_DCONF_DONE =9 ,/* dconf read/write done */ +IOCFC_E_CFG_DONE =10 ,/* IOCFC config complete */ +}; + +struct bfa_iocfc_s ; +typedef void (*bfa_iocfs_fsm_t )(struct bfa_iocfc_s *,enum iocfc_event ); +struct bfa_iocfc_s { -bfa_fsm_t fsm; +bfa_iocfs_fsm_t fsm;struct bfa_s *bfa;struct bfa_iocfc_cfg_s cfg;u32 req_cq_pi[BFI_IOC_MAX_CQS ];
drivers/scsi/bfa/bfa_cs.h +5 -16
@@ -187,10 +187,10 @@ typedef void (*bfa_sm_t)(void *sm, int event);#define bfa_sm_state_decl (oc, st, otype, etype) \ static void oc ## _sm_ ## st(otype * fsm, etype event) -#define bfa_sm_set_state (_sm, _state) ((_sm)->sm = (bfa_sm_t)(_state)) +#define bfa_sm_set_state (_sm, _state) ((_sm)->sm = (_state))#define bfa_sm_send_event (_sm, _event) ((_sm)->sm((_sm), (_event)))#define bfa_sm_get_state (_sm) ((_sm)->sm) -#define bfa_sm_cmp_state (_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state)) +#define bfa_sm_cmp_state (_sm, _state) ((_sm)->sm == (_state))/* * For converting from state machine function to state encoding.
@@ -200,7 +200,7 @@ struct bfa_sm_table_s {int state;/* state machine encoding */ char *name;/* state name for display */ }; -#define BFA_SM (_sm) ((bfa_sm_t)(_sm)) +#define BFA_SM (_sm) (_sm)/* * State machine with entry actions.
@@ -218,24 +218,13 @@ typedef void (*bfa_fsm_t)(void *fsm, int event); static void oc ## _sm_ ## st ## _entry(otype * fsm)#define bfa_fsm_set_state (_fsm, _state) do { \ - (_fsm)->fsm = (bfa_fsm_t)(_state); \ + (_fsm)->fsm = (_state); \ _state ## _entry(_fsm); \ } while (0)#define bfa_fsm_send_event (_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))#define bfa_fsm_get_state (_fsm) ((_fsm)->fsm) -#define bfa_fsm_cmp_state (_fsm, _state) \ - ((_fsm)->fsm == (bfa_fsm_t)(_state)) - -static inline int -bfa_sm_to_state (struct bfa_sm_table_s *smt,bfa_sm_t sm) -{ -int i =0 ; - -while (smt[i].sm && smt[i].sm != sm) - i++; -return smt[i].state; -} +#define bfa_fsm_cmp_state (_fsm, _state) ((_fsm)->fsm == (_state))/* * @ Generic wait counter.
drivers/scsi/bfa/bfa_fcpim.c +0 -51
69 lines not on this page · raw message
drivers/scsi/bfa/bfa_fcpim.h +63 -3
99 lines not on this page · raw message
drivers/scsi/bfa/bfa_fcs.h +212 -98
411 lines not on this page · raw message
drivers/scsi/bfa/bfa_fcs_fcpim.c +20 -3
@@ -16,6 +16,7 @@#include "bfa_fcs.h" #include "bfa_fcbuild.h" #include "bfad_im.h" +#include "bfa_fcpim.h" BFA_TRC_FILE (FCS ,FCPIM );
@@ -52,7 +53,23 @@ static void bfa_fcs_itnim_sm_hcb_offline(struct bfa_fcs_itnim_s *itnim,static void bfa_fcs_itnim_sm_initiator (struct bfa_fcs_itnim_s *itnim,enum bfa_fcs_itnim_event event); -static struct bfa_sm_table_s itnim_sm_table[] = { +struct bfa_fcs_itnim_sm_table_s { +bfa_fcs_itnim_sm_t sm;/* state machine function */ +enum bfa_itnim_state state;/* state machine encoding */ +char *name;/* state name for display */ +}; + +static inline enum bfa_itnim_state +bfa_fcs_itnim_sm_to_state (struct bfa_fcs_itnim_sm_table_s *smt,bfa_fcs_itnim_sm_t sm) +{ +int i =0 ; + +while (smt[i].sm && smt[i].sm != sm) + i++; +return smt[i].state; +} + +static struct bfa_fcs_itnim_sm_table_s itnim_sm_table[] = { {BFA_SM (bfa_fcs_itnim_sm_offline),BFA_ITNIM_OFFLINE }, {BFA_SM (bfa_fcs_itnim_sm_prli_send),BFA_ITNIM_PRLI_SEND }, {BFA_SM (bfa_fcs_itnim_sm_prli),BFA_ITNIM_PRLI_SENT },
@@ -665,7 +682,7 @@ bfa_status_t bfa_fcs_itnim_get_online_state(struct bfa_fcs_itnim_s *itnim) {bfa_trc (itnim->fcs, itnim->rport->pid); -switch (bfa_sm_to_state (itnim_sm_table, itnim->sm)) { +switch (bfa_fcs_itnim_sm_to_state (itnim_sm_table, itnim->sm)) {case BFA_ITNIM_ONLINE :case BFA_ITNIM_INITIATIOR :return BFA_STATUS_OK ;
@@ -765,7 +782,7 @@ bfa_fcs_itnim_attr_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn,if (itnim ==NULL )return BFA_STATUS_NO_FCPIM_NEXUS ; - attr->state =bfa_sm_to_state (itnim_sm_table, itnim->sm); + attr->state =bfa_fcs_itnim_sm_to_state (itnim_sm_table, itnim->sm); attr->retry = itnim->seq_rec; attr->rec_support = itnim->rec_support; attr->conf_comp = itnim->conf_comp;
drivers/scsi/bfa/bfa_fcs_lport.c +18 -94
160 lines not on this page · raw message
drivers/scsi/bfa/bfa_fcs_rport.c +18 -16
@@ -136,7 +136,23 @@ static void bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,static void bfa_fcs_rport_sm_delete_pending (struct bfa_fcs_rport_s *rport,enum rport_event event); -static struct bfa_sm_table_s rport_sm_table[] = { +struct bfa_fcs_rport_sm_table_s { +bfa_fcs_rport_sm_t sm;/* state machine function */ +enum bfa_rport_state state;/* state machine encoding */ +char *name;/* state name for display */ +}; + +static inline enum bfa_rport_state +bfa_rport_sm_to_state (struct bfa_fcs_rport_sm_table_s *smt,bfa_fcs_rport_sm_t sm) +{ +int i =0 ; + +while (smt[i].sm && smt[i].sm != sm) + i++; +return smt[i].state; +} + +static struct bfa_fcs_rport_sm_table_s rport_sm_table[] = { {BFA_SM (bfa_fcs_rport_sm_uninit),BFA_RPORT_UNINIT }, {BFA_SM (bfa_fcs_rport_sm_plogi_sending),BFA_RPORT_PLOGI }, {BFA_SM (bfa_fcs_rport_sm_plogiacc_sending),BFA_RPORT_ONLINE },
@@ -2964,7 +2980,7 @@ bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,int bfa_fcs_rport_get_state (struct bfa_fcs_rport_s *rport) { -return bfa_sm_to_state (rport_sm_table, rport->sm); +return bfa_rport_sm_to_state (rport_sm_table, rport->sm); }
@@ -3107,20 +3123,6 @@ static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,static void bfa_fcs_rpf_timeout (void *arg); -/* -* fcs_rport_ftrs_sm FCS rport state machine events -*/ - -enum rpf_event { -RPFSM_EVENT_RPORT_OFFLINE =1 ,/* Rport offline */ -RPFSM_EVENT_RPORT_ONLINE =2 ,/* Rport online */ -RPFSM_EVENT_FCXP_SENT =3 ,/* Frame from has been sent */ -RPFSM_EVENT_TIMEOUT =4 ,/* Rport SM timeout event */ -RPFSM_EVENT_RPSC_COMP =5 , -RPFSM_EVENT_RPSC_FAIL =6 , -RPFSM_EVENT_RPSC_ERROR =7 , -}; -static void bfa_fcs_rpf_sm_uninit (struct bfa_fcs_rpf_s *rpf,enum rpf_event event); static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
drivers/scsi/bfa/bfa_ioc.c +36 -49
131 lines not on this page · raw message
drivers/scsi/bfa/bfa_ioc.h +57 -19
108 lines not on this page · raw message
drivers/scsi/bfa/bfa_svc.c +22 -50
120 lines not on this page · raw message
drivers/scsi/bfa/bfa_svc.h +94 -21
174 lines not on this page · raw message
drivers/scsi/bfa/bfad_drv.h +17 -14
@@ -175,11 +175,27 @@ union bfad_tmp_buf {wwn_t wwn[BFA_FCS_MAX_LPORTS ]; }; +/* BFAD state machine events */ +enum bfad_sm_event { +BFAD_E_CREATE =1 , +BFAD_E_KTHREAD_CREATE_FAILED =2 , +BFAD_E_INIT =3 , +BFAD_E_INIT_SUCCESS =4 , +BFAD_E_HAL_INIT_FAILED =5 , +BFAD_E_INIT_FAILED =6 , +BFAD_E_FCS_EXIT_COMP =7 , +BFAD_E_EXIT_COMP =8 , +BFAD_E_STOP =9 +}; + +struct bfad_s ; +typedef void (*bfad_sm_t )(struct bfad_s *,enum bfad_sm_event ); +/* * BFAD (PCI function) data structure */ struct bfad_s { -bfa_sm_t sm;/* state machine */ +bfad_sm_t sm;/* state machine */ struct list_head list_entry;struct bfa_s bfa;struct bfa_fcs_s bfa_fcs;
@@ -226,19 +242,6 @@ struct bfad_s {struct list_head vport_list; }; -/* BFAD state machine events */ -enum bfad_sm_event { -BFAD_E_CREATE =1 , -BFAD_E_KTHREAD_CREATE_FAILED =2 , -BFAD_E_INIT =3 , -BFAD_E_INIT_SUCCESS =4 , -BFAD_E_HAL_INIT_FAILED =5 , -BFAD_E_INIT_FAILED =6 , -BFAD_E_FCS_EXIT_COMP =7 , -BFAD_E_EXIT_COMP =8 , -BFAD_E_STOP =9 -}; -/* * RPORT data structure */
Signature · 1 line
2.39.2
Quoted 2 lines · Arnd Bergmann
v2: no changes, just rending after I noticed I forgot to follow up
after https://lore.kernel.org/all/[email protected]/
Thanks!
I assume Martin or James will pick this up?
-Kees
Signature · 1 line
Kees Cook
Arnd,
Quoted 3 lines
Some callback functions used here take a boolean argument, others take a status argument. This breaks KCFI type checking, so clang now warns about the function pointer cast:
Applied 1+2 to 6.9/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Martin K. Petersen
AppliedQuoted 6 lines · Arnd Bergmann
Some callback functions used here take a boolean argument, others take a status argument. This breaks KCFI type checking, so clang now warns about the function pointer cast:
drivers/scsi/bfa/bfad_bsg.c:2138:29: error: cast from 'void (*)(void *, enumbfa_status)' to 'bfa_cb_cbfn_t' (aka 'void (*)(void *, enumbfa_boolean)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
Quoted 7 lines
Assuming the code is actually correct here and the callers always match the argument types of the callee, rework this to replace the explicit cast with a union of the two pointer types. This does not change the behavior of the code, so if something is actually broken here, a larger rework may be necessary.
[...]
Applied to 6.9/scsi-queue, thanks!
[1/2] scsi: bfa: fix function pointer type mismatch for hcb_qe->cbfn
https://git.kernel.org/mkp/scsi/c/b69600231f75 [2/2] scsi: bfa: fix function pointer type mismatch for state machines https://git.kernel.org/mkp/scsi/c/37126399da15
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering