From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 858FE246348 for ; Mon, 30 Jun 2025 21:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751320015; cv=none; b=SJADvLa4GDaY2nIlG+JON1M45r1g15fbsYMEdK3PL4PFhxKLo7vLa7kXlT2sjYZAuWYp2Vfojlwpl/j0uhJ5dUKYzN1zEYkDPP0F2Nhf5c/FQNS4JHJznSlFWUlZUg4a2o+CJlOSvciXKp1xDhm279EmaXfCCJr6UrC2nsi/jrM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751320015; c=relaxed/simple; bh=u5s6k4Jdz2z8AXFLPplnaz3wYjFvVjXxszMHR4lBcFk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LUW1qbAaa8rfGp1mGCgZDGapjK4LFCMsIRO6znRerZb+ZwczRaj5zoOqHRpVJVYIC3G66pL6FVbyvA5BPk7sO1MkohtFkpo7+DMbK5G718yCFyNs4aTUvzvFa9ZcnfZ9B9iEKxE8aUhkOEPKAOsrRfiqrT2BeCtAdS5dF1kY7nU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DNl5fFOk; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DNl5fFOk" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1751320001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=RELCbEFu2DUPB6wgDcJ2J6c7pTcMWEgqSGU5NMKW/pQ=; b=DNl5fFOkj01YlNGt5Gz54+QW0c8ib+XC0OxLuFv87r2xZgE0JXwhRZSEd71XTbBhHSyqF2 Tsbjp7c9MSSxsY3hPxfS04kbrQF8i+bfanAlO/xoiJsG6pWU7eRmkesO9C9dI173EJ0HxC E0eG3vpM7wETg33YPFHU+i1N9oHWcg8= From: Thorsten Blum To: Jaroslav Kysela , Takashi Iwai , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Thorsten Blum , Takashi Iwai , 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 Message-ID: <20250630214554.182953-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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 --- 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