Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: "Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
	Takashi Iwai <tiwai@suse.de>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ALSA: mips/hal2: Refactor and improve hal2_compute_rate()
Date: Mon, 30 Jun 2025 23:45:52 +0200	[thread overview]
Message-ID: <20250630214554.182953-2-thorsten.blum@linux.dev> (raw)

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@linux.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


             reply	other threads:[~2025-06-30 21:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-30 21:45 Thorsten Blum [this message]
2025-07-01  9:25 ` [PATCH] ALSA: mips/hal2: Refactor and improve hal2_compute_rate() Takashi Iwai
2025-07-01 10:18   ` Thorsten Blum
2025-07-01 11:49     ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250630214554.182953-2-thorsten.blum@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox