]> xenbits.xensource.com Git - people/aperard/linux.git/commitdiff
scsi: csiostor: Avoid function pointer casts
authorArnd Bergmann <arnd@arndb.de>
Tue, 13 Feb 2024 10:05:00 +0000 (11:05 +0100)
committerSasha Levin <sashal@kernel.org>
Tue, 26 Mar 2024 22:20:55 +0000 (18:20 -0400)
[ Upstream commit 9f3dbcb5632d6876226031d552ef6163bb3ad215 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/csiostor/csio_defs.h
drivers/scsi/csiostor/csio_lnode.c
drivers/scsi/csiostor/csio_lnode.h

index c38017b4af9826871bec6205f26ee73b115b20d2..e50e93e7fe5a1c3c79225d92f660333a22344db6 100644 (file)
@@ -73,7 +73,21 @@ csio_list_deleted(struct list_head *list)
 #define csio_list_prev(elem)   (((struct list_head *)(elem))->prev)
 
 /* State machine */
-typedef void (*csio_sm_state_t)(void *, uint32_t);
+struct csio_lnode;
+
+/* State machine evets */
+enum csio_ln_ev {
+       CSIO_LNE_NONE = (uint32_t)0,
+       CSIO_LNE_LINKUP,
+       CSIO_LNE_FAB_INIT_DONE,
+       CSIO_LNE_LINK_DOWN,
+       CSIO_LNE_DOWN_LINK,
+       CSIO_LNE_LOGO,
+       CSIO_LNE_CLOSE,
+       CSIO_LNE_MAX_EVENT,
+};
+
+typedef void (*csio_sm_state_t)(struct csio_lnode *ln, enum csio_ln_ev evt);
 
 struct csio_sm {
        struct list_head        sm_list;
@@ -83,7 +97,7 @@ struct csio_sm {
 static inline void
 csio_set_state(void *smp, void *state)
 {
-       ((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state;
+       ((struct csio_sm *)smp)->sm_state = state;
 }
 
 static inline void
index d5ac9389702327fdf6d6767324ec7f8bdaa642cb..5b3ffefae476d011999a9ac66913381080b34920 100644 (file)
@@ -1095,7 +1095,7 @@ csio_handle_link_down(struct csio_hw *hw, uint8_t portid, uint32_t fcfi,
 int
 csio_is_lnode_ready(struct csio_lnode *ln)
 {
-       return (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready));
+       return (csio_get_state(ln) == csio_lns_ready);
 }
 
 /*****************************************************************************/
@@ -1366,15 +1366,15 @@ csio_free_fcfinfo(struct kref *kref)
 void
 csio_lnode_state_to_str(struct csio_lnode *ln, int8_t *str)
 {
-       if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_uninit)) {
+       if (csio_get_state(ln) == csio_lns_uninit) {
                strcpy(str, "UNINIT");
                return;
        }
-       if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready)) {
+       if (csio_get_state(ln) == csio_lns_ready) {
                strcpy(str, "READY");
                return;
        }
-       if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_offline)) {
+       if (csio_get_state(ln) == csio_lns_offline) {
                strcpy(str, "OFFLINE");
                return;
        }
index 372a67d122d38fc161743c105db229c534d26a89..607698a0f06315935a169633a5f2e50038d37f48 100644 (file)
 extern int csio_fcoe_rnodes;
 extern int csio_fdmi_enable;
 
-/* State machine evets */
-enum csio_ln_ev {
-       CSIO_LNE_NONE = (uint32_t)0,
-       CSIO_LNE_LINKUP,
-       CSIO_LNE_FAB_INIT_DONE,
-       CSIO_LNE_LINK_DOWN,
-       CSIO_LNE_DOWN_LINK,
-       CSIO_LNE_LOGO,
-       CSIO_LNE_CLOSE,
-       CSIO_LNE_MAX_EVENT,
-};
-
-
 struct csio_fcf_info {
        struct list_head        list;
        uint8_t                 priority;