* re: usb: gadget: Add support for USB MIDI 2.0 function driver
@ 2024-11-07 12:30 Colin King (gmail)
2024-11-07 13:04 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Colin King (gmail) @ 2024-11-07 12:30 UTC (permalink / raw)
To: Takashi Iwai
Cc: Paul Cercueil, Simona Vetter, Christian König,
Michael Grzeschik, linux-usb, Greg Kroah-Hartman, linux-kernel
Hi,
Static analysis has found a minor issue in the following commit:
commit 8b645922b22303cec4628dbbbf6c8553d1cdec87
Author: Takashi Iwai <tiwai@suse.de>
Date: Tue Jul 25 08:22:00 2023 +0200
usb: gadget: Add support for USB MIDI 2.0 function driver
The issue is in function f_midi2_set_alt in
drivers/usb/gadget/function/f_midi2.c as follows:
if (intf != midi2->midi_if || alt > 1)
return 0;
if (alt == 0)
op_mode = MIDI_OP_MODE_MIDI1;
else if (alt == 1)
op_mode = MIDI_OP_MODE_MIDI2;
else
op_mode = MIDI_OP_MODE_UNSET;
the first if statement will return if alt is 2 or more, so at the
following cascaded if/else if/else statement alt is either 0 or 1, hence
the final else that sets op_mode = MIDI_OP_MODE_UNSET can never be
reached.
Either the last else statement is redundant and can be removed, or the
first if statement needs to check for alt > 2 rather than > 1. I'm not
sure which one is the valid fix to make. Any ideas?
Colin
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: usb: gadget: Add support for USB MIDI 2.0 function driver
2024-11-07 12:30 usb: gadget: Add support for USB MIDI 2.0 function driver Colin King (gmail)
@ 2024-11-07 13:04 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-11-07 13:04 UTC (permalink / raw)
To: Colin King (gmail)
Cc: Takashi Iwai, Paul Cercueil, Simona Vetter, Christian König,
Michael Grzeschik, linux-usb, Greg Kroah-Hartman, linux-kernel
On Thu, 07 Nov 2024 13:30:12 +0100,
Colin King (gmail) wrote:
>
> Hi,
>
> Static analysis has found a minor issue in the following commit:
>
> commit 8b645922b22303cec4628dbbbf6c8553d1cdec87
> Author: Takashi Iwai <tiwai@suse.de>
> Date: Tue Jul 25 08:22:00 2023 +0200
>
> usb: gadget: Add support for USB MIDI 2.0 function driver
>
> The issue is in function f_midi2_set_alt in
> drivers/usb/gadget/function/f_midi2.c as follows:
>
> if (intf != midi2->midi_if || alt > 1)
> return 0;
>
> if (alt == 0)
> op_mode = MIDI_OP_MODE_MIDI1;
> else if (alt == 1)
> op_mode = MIDI_OP_MODE_MIDI2;
> else
> op_mode = MIDI_OP_MODE_UNSET;
>
>
> the first if statement will return if alt is 2 or more, so at the
> following cascaded if/else if/else statement alt is either 0 or 1,
> hence the final else that sets op_mode = MIDI_OP_MODE_UNSET can never
> be reached.
>
> Either the last else statement is redundant and can be removed, or the
> first if statement needs to check for alt > 2 rather than > 1. I'm not
> sure which one is the valid fix to make. Any ideas?
We can fix in either way, as it won't happen practically :)
I guess I thought of alt < 0, but it's an unsigned int, so this is
nonsense. I'd rather drop the redundant else statement.
thanks,
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-07 13:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-07 12:30 usb: gadget: Add support for USB MIDI 2.0 function driver Colin King (gmail)
2024-11-07 13:04 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®