drbd: fix function cast warnings in state machine
authorArnd Bergmann <arnd@arndb.de>
Tue, 13 Feb 2024 10:03:01 +0000 (11:03 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 13 Feb 2024 15:55:40 +0000 (08:55 -0700)
There are four state machines in drbd that use a common infrastructure, with
a cast to an incompatible function type in REMEMBER_STATE_CHANGE that clang-16
now warns about:

drivers/block/drbd/drbd_state.c:1632:3: error: cast from 'int (*)(struct sk_buff *, unsigned int, struct drbd_resource_state_change *, enum drbd_notification_type)' to 'typeof (last_func)' (aka 'int (*)(struct sk_buff *, unsigned int, void *, enum drbd_notification_type)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 1632 |                 REMEMBER_STATE_CHANGE(notify_resource_state_change,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1633 |                                       resource_state_change, NOTIFY_CHANGE);
      |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/drbd/drbd_state.c:1619:17: note: expanded from macro 'REMEMBER_STATE_CHANGE'
 1619 |            last_func = (typeof(last_func))func; \
      |                        ^~~~~~~~~~~~~~~~~~~~~~~
drivers/block/drbd/drbd_state.c:1641:4: error: cast from 'int (*)(struct sk_buff *, unsigned int, struct drbd_connection_state_change *, enum drbd_notification_type)' to 'typeof (last_func)' (aka 'int (*)(struct sk_buff *, unsigned int, void *, enum drbd_notification_type)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
 1641 |                         REMEMBER_STATE_CHANGE(notify_connection_state_change,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1642 |                                               connection_state_change, NOTIFY_CHANGE);
      |                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change these all to actually expect a void pointer to be passed, which
matches the caller.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20240213100354.457128-1-arnd@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/drbd/drbd_state.c
drivers/block/drbd/drbd_state_change.h

index 287a8d1d3f707f217c2e715c62decb4e83e27d1f..e858e7e0383f262fa0bf412c5867ee6832ffcb64 100644 (file)
@@ -1542,9 +1542,10 @@ int drbd_bitmap_io_from_worker(struct drbd_device *device,
 
 int notify_resource_state_change(struct sk_buff *skb,
                                  unsigned int seq,
-                                 struct drbd_resource_state_change *resource_state_change,
+                                 void *state_change,
                                  enum drbd_notification_type type)
 {
+       struct drbd_resource_state_change *resource_state_change = state_change;
        struct drbd_resource *resource = resource_state_change->resource;
        struct resource_info resource_info = {
                .res_role = resource_state_change->role[NEW],
@@ -1558,13 +1559,14 @@ int notify_resource_state_change(struct sk_buff *skb,
 
 int notify_connection_state_change(struct sk_buff *skb,
                                    unsigned int seq,
-                                   struct drbd_connection_state_change *connection_state_change,
+                                   void *state_change,
                                    enum drbd_notification_type type)
 {
-       struct drbd_connection *connection = connection_state_change->connection;
+       struct drbd_connection_state_change *p = state_change;
+       struct drbd_connection *connection = p->connection;
        struct connection_info connection_info = {
-               .conn_connection_state = connection_state_change->cstate[NEW],
-               .conn_role = connection_state_change->peer_role[NEW],
+               .conn_connection_state = p->cstate[NEW],
+               .conn_role = p->peer_role[NEW],
        };
 
        return notify_connection_state(skb, seq, connection, &connection_info, type);
@@ -1572,9 +1574,10 @@ int notify_connection_state_change(struct sk_buff *skb,
 
 int notify_device_state_change(struct sk_buff *skb,
                                unsigned int seq,
-                               struct drbd_device_state_change *device_state_change,
+                               void *state_change,
                                enum drbd_notification_type type)
 {
+       struct drbd_device_state_change *device_state_change = state_change;
        struct drbd_device *device = device_state_change->device;
        struct device_info device_info = {
                .dev_disk_state = device_state_change->disk_state[NEW],
@@ -1585,9 +1588,10 @@ int notify_device_state_change(struct sk_buff *skb,
 
 int notify_peer_device_state_change(struct sk_buff *skb,
                                     unsigned int seq,
-                                    struct drbd_peer_device_state_change *p,
+                                    void *state_change,
                                     enum drbd_notification_type type)
 {
+       struct drbd_peer_device_state_change *p = state_change;
        struct drbd_peer_device *peer_device = p->peer_device;
        struct peer_device_info peer_device_info = {
                .peer_repl_state = p->repl_state[NEW],
@@ -1605,8 +1609,8 @@ static void broadcast_state_change(struct drbd_state_change *state_change)
        struct drbd_resource_state_change *resource_state_change = &state_change->resource[0];
        bool resource_state_has_changed;
        unsigned int n_device, n_connection, n_peer_device, n_peer_devices;
-       int (*last_func)(struct sk_buff *, unsigned int, void *,
-                         enum drbd_notification_type) = NULL;
+       int (*last_func)(struct sk_buff *, unsigned int,
+               void *, enum drbd_notification_type) = NULL;
        void *last_arg = NULL;
 
 #define HAS_CHANGED(state) ((state)[OLD] != (state)[NEW])
@@ -1616,7 +1620,7 @@ static void broadcast_state_change(struct drbd_state_change *state_change)
        })
 #define REMEMBER_STATE_CHANGE(func, arg, type) \
        ({ FINAL_STATE_CHANGE(type | NOTIFY_CONTINUES); \
-          last_func = (typeof(last_func))func; \
+          last_func = func; \
           last_arg = arg; \
         })
 
index 9d78d8e3912eee6d581a2a70dc683665a2b91e97..a56a57d67686291a8fd6401b28a1a70473d336c2 100644 (file)
@@ -46,19 +46,19 @@ extern void forget_state_change(struct drbd_state_change *);
 
 extern int notify_resource_state_change(struct sk_buff *,
                                         unsigned int,
-                                        struct drbd_resource_state_change *,
+                                        void *,
                                         enum drbd_notification_type type);
 extern int notify_connection_state_change(struct sk_buff *,
                                           unsigned int,
-                                          struct drbd_connection_state_change *,
+                                          void *,
                                           enum drbd_notification_type type);
 extern int notify_device_state_change(struct sk_buff *,
                                       unsigned int,
-                                      struct drbd_device_state_change *,
+                                      void *,
                                       enum drbd_notification_type type);
 extern int notify_peer_device_state_change(struct sk_buff *,
                                            unsigned int,
-                                           struct drbd_peer_device_state_change *,
+                                           void *,
                                            enum drbd_notification_type type);
 
 #endif  /* DRBD_STATE_CHANGE_H */