ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions
PATCH v2 1/1 ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions
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.
---
Changes in V2: Fixed formatting caused by email client. Sorry!
sound/pci/ctxfi/ctdaio.c | 50 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 33 deletions(-)
sound/pci/ctxfi/ctdaio.c +17 -33
@@ -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 = {
Signature · 1 line
2.47.1
Quoted 5 lines · Ethan Carter Edwards
There was a lote of code duplication in the
dao_clear_left_input()anddao_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.
Quoted 8 lines
Signed-off-by Ethan Carter Edwards <[email protected]>Co-developed-by David Laight <[email protected]>---
Changes in V2: Fixed formatting caused by email client. Sorry!sound/pci/ctxfi/ctdaio.c | 50 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 33 deletions(-)
Alright. It appears my email server is mangling my patches somehow. I have tried using both mutt and git send-email, and it appears that they are still messed up.
I'm using Protonmail as my server with its bridge locally. Does anyone have any experience with working around this? I can't immediately find anything online.
Apologies.
Ethan
Signature · 5 lines
Ethan Carter Edwards CompTIA A+, Security+, and ISC2 (CC) Ham Radio: AE4CE Website: https://ethancedwards.com GPG: 2E51 F618 39D1 FA94 7A73 00C2 34C0 4305 D581 DBFE
Hi Ethan,
Thank you for your patch. However, there are a few issues:
Quoted 7 lines · Ethan Carter Edwards
There was a lote of code duplication in the
dao_clear_left_input()anddao_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.
Please move the Link: tag to the SoB area without an empty line.
Quoted 2 lines
Signed-off-by Ethan Carter Edwards <[email protected]>Co-developed-by David Laight <[email protected]>
The Co-developed-by: tag should be immediately followed by the co-author's Signed-off-by: tag. Additionally, the last Signed-off-by:
tag must always belong to the patch submitter.
See: https://docs.kernel.org/process/submitting-patches.html#when-to-use-acked-by-cc-and-co-developed-by
Regards,
Kuan-Wei
Quoted 64 lines · On Mon, 30 Dec 2024 15:32:58 +0000 Ethan Carter Edwards…
There was a lote of code duplication in the
dao_clear_left_input()anddao_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.Signed-off-by Ethan Carter Edwards <[email protected]>Co-developed-by David Laight <[email protected]>---
Changes in V2: Fixed formatting caused by email client. Sorry!sound/pci/ctxfi/ctdaio.c | 50 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 33 deletions(-)sound/pci/ctxfi/ctdaio.c +10
-22@@ -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;
sound/pci/ctxfi/ctdaio.c static int dao_set_right_input(struct dao *dao, struct rsc *input) · line 235
Quoted 10 lines
sound/pci/ctxfi/ctdaio.c +1
-8- 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);
I really wouldn't bother with the temporary variable.
It is also a 'length' not an offset and you can't decide on the type. 'unsigned int' is fine.
But I suspect it really is worth checking if that *imappers[] is needed at all. (Rename and see where the build breaks!)
You might just need struct imappers *imappers_left and *imappers_right to hold base of the kmalloc()ed block.
At that point the functions collapse down even more.
David
Quoted 14 lines
sound/pci/ctxfi/ctdaio.c +6
-3+} -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 = {