Skip to content

Commit d7bf738

Browse files
committed
ALSA: seq: fix function cast warnings
clang-16 points out a control flow integrity (kcfi) issue when event callbacks get converted to incompatible types: sound/core/seq/seq_midi.c:135:30: error: cast from 'int (*)(struct snd_rawmidi_substream *, const char *, int)' to 'snd_seq_dump_func_t' (aka 'int (*)(void *, void *, int)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 135 | snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)dump_midi, substream); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sound/core/seq/seq_virmidi.c:83:31: error: cast from 'int (*)(struct snd_rawmidi_substream *, const unsigned char *, int)' to 'snd_seq_dump_func_t' (aka 'int (*)(void *, void *, int)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] 83 | snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)snd_rawmidi_receive, vmidi->substream); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For addressing those errors, introduce wrapper functions that are used for callbacks and bridge to the actual function call with pointer cast. The code was originally added with the initial ALSA merge in linux-2.5.4. [ the patch description shamelessly copied from Arnd's original patch -- tiwai ] Fixes: 1da177e ("Linux-2.6.12-rc2") Reported-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 022a13a commit d7bf738

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

sound/core/seq/seq_midi.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ static int dump_midi(struct snd_rawmidi_substream *substream, const char *buf, i
113113
return 0;
114114
}
115115

116+
/* callback for snd_seq_dump_var_event(), bridging to dump_midi() */
117+
static int __dump_midi(void *ptr, void *buf, int count)
118+
{
119+
return dump_midi(ptr, buf, count);
120+
}
121+
116122
static int event_process_midi(struct snd_seq_event *ev, int direct,
117123
void *private_data, int atomic, int hop)
118124
{
@@ -132,7 +138,7 @@ static int event_process_midi(struct snd_seq_event *ev, int direct,
132138
pr_debug("ALSA: seq_midi: invalid sysex event flags = 0x%x\n", ev->flags);
133139
return 0;
134140
}
135-
snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)dump_midi, substream);
141+
snd_seq_dump_var_event(ev, __dump_midi, substream);
136142
snd_midi_event_reset_decode(msynth->parser);
137143
} else {
138144
if (msynth->parser == NULL)

sound/core/seq/seq_virmidi.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ static void snd_virmidi_init_event(struct snd_virmidi *vmidi,
6262
/*
6363
* decode input event and put to read buffer of each opened file
6464
*/
65+
66+
/* callback for snd_seq_dump_var_event(), bridging to snd_rawmidi_receive() */
67+
static int dump_to_rawmidi(void *ptr, void *buf, int count)
68+
{
69+
return snd_rawmidi_receive(ptr, buf, count);
70+
}
71+
6572
static int snd_virmidi_dev_receive_event(struct snd_virmidi_dev *rdev,
6673
struct snd_seq_event *ev,
6774
bool atomic)
@@ -80,7 +87,7 @@ static int snd_virmidi_dev_receive_event(struct snd_virmidi_dev *rdev,
8087
if (ev->type == SNDRV_SEQ_EVENT_SYSEX) {
8188
if ((ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK) != SNDRV_SEQ_EVENT_LENGTH_VARIABLE)
8289
continue;
83-
snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)snd_rawmidi_receive, vmidi->substream);
90+
snd_seq_dump_var_event(ev, dump_to_rawmidi, vmidi->substream);
8491
snd_midi_event_reset_decode(vmidi->parser);
8592
} else {
8693
len = snd_midi_event_decode(vmidi->parser, msg, sizeof(msg), ev);

0 commit comments

Comments
 (0)