From patchwork Mon Dec 30 15:32:58 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: 13923342 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 3BD87142905 for ; Mon, 30 Dec 2024 15:33:06 +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=1735572790; cv=none; b=MSJLdkybyQmcc06X/f4+XPbsf3WunLFvs3Snk+0T2YoX0Up7Qhuajiazx90EijRtc+dRnoXOPhmhv0dNrNT1DhbE62yK33gQW/l4wnB8aDbVJ4LaYTSMgwG7rMU3Icq3+otCwkLyTYx1MK/TIE3UmxHyNuWK/SIbgaqUF5bphYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735572790; c=relaxed/simple; bh=BiwcDEI2vECSei2cw+UtETBJRtoS+pSaYPD5QT/HKEw=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=SnPft0xC3IS2wQM3HX4eYuITyiieSZxuvfAVI2Aqh4du6PgccoczwCZCUMy+8AOfzguncQRMiO/EoRadAcFPhGGStFYBUnrs4j+1agN4VRYzaqkHJkezUqaAJCzhQFIGfyPrceTZg4OsBqBkon4cP3q1DS/BQTN3G9BBgi1aT6Y= 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=j4mmJMHO; 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="j4mmJMHO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ethancedwards.com; s=protonmail3; t=1735572784; x=1735831984; bh=BiwcDEI2vECSei2cw+UtETBJRtoS+pSaYPD5QT/HKEw=; 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=j4mmJMHOjOjYRZlx9iBUEXQsaiZ0fXqpGa2EaS+e68Ic4bqWCEhV4iFSdJIY1noEK gbk4v58se2urPdE1ce7rXtu1CzxkZG+i+404+mub1rcMsGe/exynC5ybowq7m8un3+ t4H1j8m1RpPmffH5U8PihtA6xP3wMLrHJdJyrxM/cxHmbSN+WTVPdC4RwXCoqi0uA6 BsMqENkeh4ogdGqIPLZvw92YaTqrmtIN/Wl/zeLhsiOEo+eGckPptWLMGPbPeUzSn+ mNz20kv6AcCSTIHvs593bcyhKPq/cP88sPfDV0gVREMDPgVbrZd2t6+GkKiG38DhdX +z6EVMrrXrNgQ== Date: Mon, 30 Dec 2024 15:32:58 +0000 To: tiwai@suse.de From: Ethan Carter Edwards 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 , David Laight Subject: [PATCH v2] ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions Message-ID: <20241230153243.2874102-1-ethan@ethancedwards.com> Feedback-ID: 28410670:user:proton X-Pm-Message-ID: 9cf0945da37f615659ee72242c50eb6ef575ce11 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 --- 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 = {