Skip to content

Commit

Permalink
ALSA: firewire-tascam: Fix integer overflow in midi_port_work()
Browse files Browse the repository at this point in the history
As snd_fw_async_midi_port.consume_bytes is unsigned int, and
NSEC_PER_SEC is 1000000000L, the second multiplication in

    port->consume_bytes * 8 * NSEC_PER_SEC / 31250

always overflows on 32-bit platforms, truncating the result.  Fix this
by precalculating "NSEC_PER_SEC / 31250", which is an integer constant.

Note that this assumes port->consume_bytes <= 16777.

Fixes: 531f471 ("ALSA: firewire-lib/firewire-tascam: localize async midi port")
Reviewed-by: Takashi Sakamoto <[email protected]>
Signed-off-by: Geert Uytterhoeven <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
geertu authored and tiwai committed Jan 12, 2021
1 parent e7c22ee commit 9f65df9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sound/firewire/tascam/tascam-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static void midi_port_work(struct work_struct *work)

/* Set interval to next transaction. */
port->next_ktime = ktime_add_ns(ktime_get(),
port->consume_bytes * 8 * NSEC_PER_SEC / 31250);
port->consume_bytes * 8 * (NSEC_PER_SEC / 31250));

/* Start this transaction. */
port->idling = false;
Expand Down

0 comments on commit 9f65df9

Please sign in to comment.