Skip to contentSkip to conversation

ALSA: seq: oss/midi: Cleanup with guard and auto-cleanup

bug report Dan Carpenter 2 participants 2 messages Aug 14, 2025 Sound

lore
Share & tools
lore
#0 lore raw

Hello Takashi Iwai,

Commit 8b887676dc1f ("ALSA: seq: oss/midi: Cleanup with guard and auto-cleanup") from Aug 11, 2025 (linux-next), leads to the following Smatch static checker warning:

	sound/core/seq/oss/seq_oss_midi.c:196 snd_seq_oss_midi_check_new_port()
	warn: dereferencing no_free_ptr: 'mdev'

sound/core/seq/oss/seq_oss_midi.c

    187         if (i >= max_midi_devs) {
    188                 if (max_midi_devs >= SNDRV_SEQ_OSS_MAX_MIDI_DEVS) {
    189                         snd_midi_event_free(mdev->coder);
    190                         kfree(no_free_ptr(mdev));
    191                         return -ENOMEM;
    192                 }
    193                 max_midi_devs++;
    194         }
    195         mdev->seq_device = i;
--> 196         midi_devs[mdev->seq_device] = no_free_ptr(mdev);
                          ^^^^^^^^^^^^^^^^                ^^^^

The no_free_ptr() macro sets mdev to NULL but it's dereferenced on the left hand side.

    197 
    198         return 0;
    199 }

regards,
dan carpenter

#1 lore raw
Quoted 22 lines · Dan Carpenter

Hello Takashi Iwai,

Commit 8b887676dc1f ("ALSA: seq: oss/midi: Cleanup with guard and auto-cleanup") from Aug 11, 2025 (linux-next), leads to the following Smatch static checker warning:

	sound/core/seq/oss/seq_oss_midi.c:196 snd_seq_oss_midi_check_new_port()
	warn: dereferencing no_free_ptr: 'mdev'

sound/core/seq/oss/seq_oss_midi.c

    187         if (i >= max_midi_devs) {
    188                 if (max_midi_devs >= SNDRV_SEQ_OSS_MAX_MIDI_DEVS) {
    189                         snd_midi_event_free(mdev->coder);
    190                         kfree(no_free_ptr(mdev));
    191                         return -ENOMEM;
    192                 }
    193                 max_midi_devs++;
    194         }
    195         mdev->seq_device = i;
--> 196         midi_devs[mdev->seq_device] = no_free_ptr(mdev);
                          ^^^^^^^^^^^^^^^^                ^^^^
Quoted 6 lines

The no_free_ptr() macro sets mdev to NULL but it's dereferenced on the left hand side.

    197 
    198         return 0;
    199 }

Yes, a known issue, the patch series have been already dropped from today's tree (and the fix was folded for the next time).

thanks,

Takashi