Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Ethan Carter Edwards <ethan@ethancedwards.com>
To: tiwai@suse.de
Cc: tiwai@suse.com, perex@perex.cz, arnd@arndb.de,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	ryan_richards@creativelabs.com, wychay@ctl.creative.com,
	Ethan Carter Edwards <ethan@ethancedwards.com>,
	David Laight <david.laight.linux@gmail.com>
Subject: [PATCH v2] ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions
Date: Mon, 30 Dec 2024 15:32:58 +0000	[thread overview]
Message-ID: <20241230153243.2874102-1-ethan@ethancedwards.com> (raw)

There was a lote of code duplication in the dao_clear_left_input() and
dao_clear_right_input() functions. A new function, dao_clear_input(),
was created and now the left and right functions call it instead of
repeating themselves.

Link: https://lore.kernel.org/lkml/NyKCr2VHK_xCQDwNxFKKx2LVd2d_AC2f2j4eAvnD9uRPtb50i2AruCLOp6mHxsGiyYJ0Tgd3Z50Oy1JTi5gPhjd2WQM2skrv7asp3fLl8HU=@ethancedwards.com/

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
Co-developed-by: David Laight <david.laight.linux@gmail.com>
---
 Changes in V2: Fixed formatting caused by email client. Sorry!
 sound/pci/ctxfi/ctdaio.c | 50 ++++++++++++++--------------------------
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index 83aaf9441ef3..d46542d0b454 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -211,52 +211,36 @@ static int dao_set_right_input(struct dao *dao, struct rsc *input)
 	return 0;
 }
 
-static int dao_clear_left_input(struct dao *dao)
+static int dao_clear_input(struct dao *dao, unsigned int start, unsigned int end)
 {
-	struct imapper *entry;
-	struct daio *daio = &dao->daio;
-	int i;
+	struct imapper *to_free = dao->imappers[start];
+	unsigned int i;
 
-	if (!dao->imappers[0])
+	if (!to_free)
 		return 0;
-
-	entry = dao->imappers[0];
-	dao->mgr->imap_delete(dao->mgr, entry);
-	/* Program conjugate resources */
-	for (i = 1; i < daio->rscl.msr; i++) {
-		entry = dao->imappers[i];
-		dao->mgr->imap_delete(dao->mgr, entry);
+	for (i = start; i < end; i++) {
+		dao->mgr->imap_delete(dao->mgr, dao->imappers[i]);
 		dao->imappers[i] = NULL;
 	}
 
-	kfree(dao->imappers[0]);
-	dao->imappers[0] = NULL;
-
+	kfree(to_free);
 	return 0;
 }
 
-static int dao_clear_right_input(struct dao *dao)
-{
-	struct imapper *entry;
-	struct daio *daio = &dao->daio;
-	int i;
 
-	if (!dao->imappers[daio->rscl.msr])
-		return 0;
+static int dao_clear_left_input(struct dao *dao)
+{
+	u32 offset = dao->daio.rscl.msr;
 
-	entry = dao->imappers[daio->rscl.msr];
-	dao->mgr->imap_delete(dao->mgr, entry);
-	/* Program conjugate resources */
-	for (i = 1; i < daio->rscr.msr; i++) {
-		entry = dao->imappers[daio->rscl.msr + i];
-		dao->mgr->imap_delete(dao->mgr, entry);
-		dao->imappers[daio->rscl.msr + i] = NULL;
-	}
+	return dao_clear_input(dao, 0, 0 + offset);
+}
 
-	kfree(dao->imappers[daio->rscl.msr]);
-	dao->imappers[daio->rscl.msr] = NULL;
+static int dao_clear_right_input(struct dao *dao)
+{
+	u32 start = dao->daio.rscl.msr;
+	u32 offset = dao->daio.rscr.msr;
 
-	return 0;
+	return dao_clear_input(dao, start, start + offset);
 }
 
 static const struct dao_rsc_ops dao_ops = {
-- 
2.47.1



             reply	other threads:[~2024-12-30 15:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-30 15:32 Ethan Carter Edwards [this message]
2024-12-30 15:40 ` [PATCH v2] ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions Ethan Carter Edwards
2024-12-30 15:47 ` Kuan-Wei Chiu
2024-12-30 18:11 ` David Laight

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=20241230153243.2874102-1-ethan@ethancedwards.com \
    --to=ethan@ethancedwards.com \
    --cc=arnd@arndb.de \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=ryan_richards@creativelabs.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    --cc=wychay@ctl.creative.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