diff mbox series

ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions

Message ID vxs3fuzdia52pcztueh7g3vug3mgl4s35p3yfwqjz3xh2kdmof@ib4s63vadpwk (mailing list archive)
State Superseded
Headers show
Series ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions | expand

Commit Message

Ethan Carter Edwards Dec. 30, 2024, 5:06 a.m. UTC
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>
---
 sound/pci/ctxfi/ctdaio.c | 52 +++++++++++++---------------------------
 1 file changed, 17 insertions(+), 35 deletions(-)

Comments

Takashi Iwai Dec. 30, 2024, 10:54 a.m. UTC | #1
On Mon, 30 Dec 2024 06:06:47 +0100,
Ethan Carter Edwards wrote:
> 
> 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>

The submitted patch isn't cleanly applicable.  Possibly due to your
mailer setup.

Could you try to resubmit via git-send-email?


thanks,

Takashi
diff mbox series

Patch

diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index 83aaf9441ef3..882afe451dc1 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -211,52 +211,34 @@  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;
-
-	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;
-	}
-
-	kfree(dao->imappers[daio->rscl.msr]);
-	dao->imappers[daio->rscl.msr] = NULL;
+static int dao_clear_left_input(struct dao *dao)
+{
+	u32 offset = dao->daio.rscl.msr;
+
+	return dao_clear_input(dao, 0, 0 + offset);
+}
 
-	return 0;
+static int dao_clear_right_input(struct dao *dao)
+{
+	u32 start = dao->daio.rscl.msr;
+	u32 offset = dao->daio.rscr.msr;
+
+	return dao_clear_input(dao, start, start + offset);
 }
 
 static const struct dao_rsc_ops dao_ops = {