[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250630214554.182953-2-thorsten.blum@linux.dev>
Date: Mon, 30 Jun 2025 23:45:52 +0200
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: Jaroslav Kysela <perex@...ex.cz>,
Takashi Iwai <tiwai@...e.com>,
Uwe Kleine-König <u.kleine-koenig@...libre.com>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
Takashi Iwai <tiwai@...e.de>,
linux-sound@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] ALSA: mips/hal2: Refactor and improve hal2_compute_rate()
Assign 'codec->inc' first and then use it instead of the hardcoded
value 4 repeatedly.
Replace the if/else statement with a ternary operator and calculate
'codec->mod' directly. Remove the unnecessary local variable 'mod'.
Return the computed rate directly instead of updating the local variable
first.
No functional changes intended.
Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
---
sound/mips/hal2.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/sound/mips/hal2.c b/sound/mips/hal2.c
index 991793e6bda9..dd74bab531b4 100644
--- a/sound/mips/hal2.c
+++ b/sound/mips/hal2.c
@@ -313,21 +313,11 @@ static irqreturn_t hal2_interrupt(int irq, void *dev_id)
static int hal2_compute_rate(struct hal2_codec *codec, unsigned int rate)
{
- unsigned short mod;
-
- if (44100 % rate < 48000 % rate) {
- mod = 4 * 44100 / rate;
- codec->master = 44100;
- } else {
- mod = 4 * 48000 / rate;
- codec->master = 48000;
- }
-
codec->inc = 4;
- codec->mod = mod;
- rate = 4 * codec->master / mod;
+ codec->master = (44100 % rate < 48000 % rate) ? 44100 : 48000;
+ codec->mod = codec->inc * codec->master / rate;
- return rate;
+ return codec->inc * codec->master / codec->mod;
}
static void hal2_set_dac_rate(struct snd_hal2 *hal2)
--
2.50.0
Powered by blists - more mailing lists