Re: [PATCH 2/2] scsi: bfa: fix function pointer type mismatch for state machines

Kees Cook
2023-06-21T18:33:23Z

On Fri, Jun 16, 2023 at 11:22:10AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks for all this! It's a lot of mechanical changes, but looks correct
to me. One nit below...

Reviewed-by: Kees Cook <keescook@chromium.org>

> [...]
> static void
> -bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event);
> +bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event);
> static void
> -bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event event);
> +bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event);
> static void
> -bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event event);
> +bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event);
> static void
> -bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event event);
> +bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event);
> static void
> -bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event);
> +bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event);
> static void
> -bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event);
> +bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event);
> static void
> -bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event);
> +bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event);

This bit doesn't seem needed? i.e. why remove the prototype's argument
names?

--
Kees Cook