From patchwork Mon Dec 30 05:06:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ethan Carter Edwards X-Patchwork-Id: 13923060 Received: from mail-10625.protonmail.ch (mail-10625.protonmail.ch [79.135.106.25]) (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 08BAEA59 for ; Mon, 30 Dec 2024 05:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735535217; cv=none; b=Nj2vUMkhMNKqW+UVEXSANKSbBL9GEPF8D1Q5lVgQhPPMpa3/b7dbMfhaB+7dRDQfX8vwdlNejYYza+t17M2/uu7ylUJDRFbSwjDkQocMnJqxVxU+/KHYnx2Pv8ZBaLcahWPQifUDjsNGwiOTXoJQRCkmaxA5E/BvmA+tGWyECAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735535217; c=relaxed/simple; bh=5+Zs7PAC/Sq/9+SqtfPStEN8kzJl369O2vRSi9YYIZ4=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=PqiAs2y1tM2Ool7fHDfUhO1PTPgLrLlKCS/aa1pZzQkC2FIvb9LDIJwen1BINoXcznJUnOmmRrx7Hfzc+a92XmCoEWjzb35/ZE5wKW2aj9NIaAkRH+x1X5sG0TaIysPPhvplZdqRiYpZP8Pm6M/zpx0+avIEMmgwWgewO2ATKaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ethancedwards.com; spf=pass smtp.mailfrom=ethancedwards.com; dkim=pass (2048-bit key) header.d=ethancedwards.com header.i=@ethancedwards.com header.b=YJ5mTYvN; arc=none smtp.client-ip=79.135.106.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ethancedwards.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ethancedwards.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ethancedwards.com header.i=@ethancedwards.com header.b="YJ5mTYvN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ethancedwards.com; s=protonmail3; t=1735535211; x=1735794411; bh=5+Zs7PAC/Sq/9+SqtfPStEN8kzJl369O2vRSi9YYIZ4=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=YJ5mTYvNiioGhpDbIHkM0RYf7kfvHZ5gMpUXok8l9VuK07QEXOA+iExkenlj9+59Y 6VTvAHDNRhjDSiCpT4hcHrDCGFA6OPM7F4ALKKCwlwWUeiEtuESIE/6/lWATc29Ji/ 7aEd/nKQa5D7Djl00Ydy4s6PCAwY8aaVdmens7LPRE/8QJfGbZ4KU5rC6H3l0hLyyv m6021VMn8dUYUV7kahiYkwY4kwJQe+aDn9MKrWLESfExgofNww2rvLrgvj+JQpRUTL mKiVHDMLcBJ4KfUF1ptCHeKYb+CW+B6Hdd45fG+gqm3cHPXf8L7+lxN9PP0Np2dWqF LdkxXGQodoSqA== Date: Mon, 30 Dec 2024 05:06:47 +0000 To: perex@perex.cz From: Ethan Carter Edwards Cc: tiwai@suse.com, arnd@arndb.de, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, ryan_richards@creativelabs.com, wychay@ctl.creative.com Subject: [PATCH] ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions Message-ID: Feedback-ID: 28410670:user:proton X-Pm-Message-ID: 0a033f8720ff3cef809a72c98d79dec388f48051 Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Co-developed-by: David Laight --- sound/pci/ctxfi/ctdaio.c | 52 +++++++++++++--------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) 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 = {