Skip to content

Commit b696002

Browse files
arndbmartinkpetersen
authored andcommitted
scsi: bfa: Fix function pointer type mismatch for hcb_qe->cbfn
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. Fixes: 37ea055 ("[SCSI] bfa: Added support to collect and reset fcport stats") Fixes: 3ec4f2c ("[SCSI] bfa: Added support to configure QOS and collect stats.") Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20240222124433.2046570-1-arnd@kernel.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent c121b58 commit b696002

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

drivers/scsi/bfa/bfa.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
struct bfa_s;
2121

2222
typedef void (*bfa_isr_func_t) (struct bfa_s *bfa, struct bfi_msg_s *m);
23-
typedef void (*bfa_cb_cbfn_status_t) (void *cbarg, bfa_status_t status);
2423

2524
/*
2625
* Interrupt message handlers
@@ -437,4 +436,12 @@ struct bfa_cb_pending_q_s {
437436
(__qe)->data = (__data); \
438437
} while (0)
439438

439+
#define bfa_pending_q_init_status(__qe, __cbfn, __cbarg, __data) do { \
440+
bfa_q_qe_init(&((__qe)->hcb_qe.qe)); \
441+
(__qe)->hcb_qe.cbfn_status = (__cbfn); \
442+
(__qe)->hcb_qe.cbarg = (__cbarg); \
443+
(__qe)->hcb_qe.pre_rmv = BFA_TRUE; \
444+
(__qe)->data = (__data); \
445+
} while (0)
446+
440447
#endif /* __BFA_H__ */

drivers/scsi/bfa/bfa_core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,15 +1907,13 @@ bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
19071907
struct list_head *qe;
19081908
struct list_head *qen;
19091909
struct bfa_cb_qe_s *hcb_qe;
1910-
bfa_cb_cbfn_status_t cbfn;
19111910

19121911
list_for_each_safe(qe, qen, comp_q) {
19131912
hcb_qe = (struct bfa_cb_qe_s *) qe;
19141913
if (hcb_qe->pre_rmv) {
19151914
/* qe is invalid after return, dequeue before cbfn() */
19161915
list_del(qe);
1917-
cbfn = (bfa_cb_cbfn_status_t)(hcb_qe->cbfn);
1918-
cbfn(hcb_qe->cbarg, hcb_qe->fw_status);
1916+
hcb_qe->cbfn_status(hcb_qe->cbarg, hcb_qe->fw_status);
19191917
} else
19201918
hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
19211919
}

drivers/scsi/bfa/bfa_ioc.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,18 @@ struct bfa_reqq_wait_s {
361361
void *cbarg;
362362
};
363363

364-
typedef void (*bfa_cb_cbfn_t) (void *cbarg, bfa_boolean_t complete);
364+
typedef void (*bfa_cb_cbfn_t) (void *cbarg, bfa_boolean_t complete);
365+
typedef void (*bfa_cb_cbfn_status_t) (void *cbarg, bfa_status_t status);
365366

366367
/*
367368
* Generic BFA callback element.
368369
*/
369370
struct bfa_cb_qe_s {
370371
struct list_head qe;
371-
bfa_cb_cbfn_t cbfn;
372+
union {
373+
bfa_cb_cbfn_status_t cbfn_status;
374+
bfa_cb_cbfn_t cbfn;
375+
};
372376
bfa_boolean_t once;
373377
bfa_boolean_t pre_rmv; /* set for stack based qe(s) */
374378
bfa_status_t fw_status; /* to access fw status in comp proc */

drivers/scsi/bfa/bfad_bsg.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,7 @@ bfad_iocmd_fcport_get_stats(struct bfad_s *bfad, void *cmd)
21352135
struct bfa_cb_pending_q_s cb_qe;
21362136

21372137
init_completion(&fcomp.comp);
2138-
bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2139-
&fcomp, &iocmd->stats);
2138+
bfa_pending_q_init_status(&cb_qe, bfad_hcb_comp, &fcomp, &iocmd->stats);
21402139
spin_lock_irqsave(&bfad->bfad_lock, flags);
21412140
iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
21422141
spin_unlock_irqrestore(&bfad->bfad_lock, flags);
@@ -2159,7 +2158,7 @@ bfad_iocmd_fcport_reset_stats(struct bfad_s *bfad, void *cmd)
21592158
struct bfa_cb_pending_q_s cb_qe;
21602159

21612160
init_completion(&fcomp.comp);
2162-
bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, &fcomp, NULL);
2161+
bfa_pending_q_init_status(&cb_qe, bfad_hcb_comp, &fcomp, NULL);
21632162

21642163
spin_lock_irqsave(&bfad->bfad_lock, flags);
21652164
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)
24432442
struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
24442443

24452444
init_completion(&fcomp.comp);
2446-
bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2447-
&fcomp, &iocmd->stats);
2445+
bfa_pending_q_init_status(&cb_qe, bfad_hcb_comp, &fcomp, &iocmd->stats);
24482446

24492447
spin_lock_irqsave(&bfad->bfad_lock, flags);
24502448
WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
@@ -2474,8 +2472,7 @@ bfad_iocmd_qos_reset_stats(struct bfad_s *bfad, void *cmd)
24742472
struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
24752473

24762474
init_completion(&fcomp.comp);
2477-
bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2478-
&fcomp, NULL);
2475+
bfa_pending_q_init_status(&cb_qe, bfad_hcb_comp, &fcomp, NULL);
24792476

24802477
spin_lock_irqsave(&bfad->bfad_lock, flags);
24812478
WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));

0 commit comments

Comments
 (0)