From aabdedf4d2fe2f83cb025ae972202dcee4eb024b Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Tue, 13 Feb 2024 11:12:46 +0100 Subject: ALSA: ctxfi: avoid casting function pointers This driver creates an abstraction for different components by casting function pointers to slightly incompatible types for each one to get the correct argument even when the caller does not know those types. This is a bit unreliable and not allowed in combination with control flow integrity (KCFI): sound/pci/ctxfi/ctatc.c:115:25: error: cast from 'int (*)(struct hw *, struct src_mgr **)' to 'create_t' (aka 'int (*)(struct hw *, void **)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 115 | [SRC] = { .create = (create_t)src_mgr_create, | ^~~~~~~~~~~~~~~~~~~~~~~~ sound/pci/ctxfi/ctatc.c:116:20: error: cast from 'int (*)(struct src_mgr *)' to 'destroy_t' (aka 'int (*)(void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 116 | .destroy = (destroy_t)src_mgr_destroy }, | ^~~~~~~~~~~~~~~~~~~~~~~~~~ sound/pci/ctxfi/ctatc.c:117:27: error: cast from 'int (*)(struct hw *, struct srcimp_mgr **)' to 'create_t' (aka 'int (*)(struct hw *, void **)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 117 | [SRCIMP] = { .create = (create_t)srcimp_mgr_create, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ sound/pci/ctxfi/ctatc.c:118:20: error: cast from 'int (*)(struct srcimp_mgr *)' to 'destroy_t' (aka 'int (*)(void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 118 | .destroy = (destroy_t)srcimp_mgr_destroy }, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Change these to always pass void pointers and move the abstraction one level down. Fixes: 8cc72361481f ("ALSA: SB X-Fi driver merge") Signed-off-by: Arnd Bergmann Link: https://lore.kernel.org/r/20240213101303.460008-1-arnd@kernel.org Signed-off-by: Takashi Iwai --- sound/pci/ctxfi/ctamixer.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sound/pci/ctxfi/ctamixer.c') diff --git a/sound/pci/ctxfi/ctamixer.c b/sound/pci/ctxfi/ctamixer.c index d074727c3e21..397900929aa6 100644 --- a/sound/pci/ctxfi/ctamixer.c +++ b/sound/pci/ctxfi/ctamixer.c @@ -292,7 +292,7 @@ static int put_amixer_rsc(struct amixer_mgr *mgr, struct amixer *amixer) return 0; } -int amixer_mgr_create(struct hw *hw, struct amixer_mgr **ramixer_mgr) +int amixer_mgr_create(struct hw *hw, void **ramixer_mgr) { int err; struct amixer_mgr *amixer_mgr; @@ -321,8 +321,9 @@ error: return err; } -int amixer_mgr_destroy(struct amixer_mgr *amixer_mgr) +int amixer_mgr_destroy(void *ptr) { + struct amixer_mgr *amixer_mgr = ptr; rsc_mgr_uninit(&amixer_mgr->mgr); kfree(amixer_mgr); return 0; @@ -446,7 +447,7 @@ static int put_sum_rsc(struct sum_mgr *mgr, struct sum *sum) return 0; } -int sum_mgr_create(struct hw *hw, struct sum_mgr **rsum_mgr) +int sum_mgr_create(struct hw *hw, void **rsum_mgr) { int err; struct sum_mgr *sum_mgr; @@ -475,8 +476,9 @@ error: return err; } -int sum_mgr_destroy(struct sum_mgr *sum_mgr) +int sum_mgr_destroy(void *ptr) { + struct sum_mgr *sum_mgr = ptr; rsc_mgr_uninit(&sum_mgr->mgr); kfree(sum_mgr); return 0; -- cgit v1.2.3