From patchwork Wed Mar 15 14:50:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 13175988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22E51C7618D for ; Wed, 15 Mar 2023 14:52:23 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 8DA281134; Wed, 15 Mar 2023 15:51:30 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8DA281134 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1678891940; bh=U1T8gpYRnqUZqZkjW+AJ1ntz+/l5aR38aSJemQntQuk=; h=To:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From:Reply-To:Cc:From; b=U8nB9T4eO08P+mhqG+DL3Gor6bCprEe2VqAgLkwo1hZ2Cs4ZEYcZmEnxXV2Hmr31y Tt256m2AuzeoI0izZWwQUwmS0OLVVfvnjY2VFw527eKsSP+65ug/FpYuVbvGpDWAYw ikVd7gpv1TidvK2SQL7L7iNCZd4PWlWcyRi1dhtM= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 508A8F80423; Wed, 15 Mar 2023 15:51:09 +0100 (CET) To: Subject: [PATCH v2] soundwire: bandwidth allocation: Use hweight32() to calculate set bits Date: Wed, 15 Mar 2023 14:50:51 +0000 X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <167889186802.26.13027272550025447563@mailman-core.alsa-project.org> X-Patchwork-Original-From: Richard Fitzgerald via Alsa-devel From: Richard Fitzgerald Reply-To: Richard Fitzgerald Cc: yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.intel.com, sanyog.r.kale@intel.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com, Richard Fitzgerald Content-Disposition: inline Replace the call to sdw_ch_mask_to_ch() with a call to hweight32(). sdw_ch_mask_to_ch() is counting the number of set bits. The hweight() family of functions already do this, and they have an advantage of using a bit-counting instruction if it is available on the target CPU. This also fixes a potential infinite loop bug in the implementation of sdw_ch_mask_to_ch(). Signed-off-by: Richard Fitzgerald --- drivers/soundwire/bus.h | 11 ----------- drivers/soundwire/generic_bandwidth_allocation.c | 3 ++- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/soundwire/bus.h b/drivers/soundwire/bus.h index 7631ef5e71fb..4ce8d708a39c 100644 --- a/drivers/soundwire/bus.h +++ b/drivers/soundwire/bus.h @@ -159,17 +159,6 @@ int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg, int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave, u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf); -/* Retrieve and return channel count from channel mask */ -static inline int sdw_ch_mask_to_ch(int ch_mask) -{ - int c = 0; - - for (c = 0; ch_mask; ch_mask >>= 1) - c += ch_mask & 1; - - return c; -} - /* Fill transport parameter data structure */ static inline void sdw_fill_xport_params(struct sdw_transport_params *params, int port_num, bool grp_ctrl_valid, diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/soundwire/generic_bandwidth_allocation.c index f7c66083a4dd..ea3e8ef408e4 100644 --- a/drivers/soundwire/generic_bandwidth_allocation.c +++ b/drivers/soundwire/generic_bandwidth_allocation.c @@ -6,6 +6,7 @@ * */ +#include #include #include #include @@ -54,7 +55,7 @@ static void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt, slave_total_ch = 0; list_for_each_entry(p_rt, &s_rt->port_list, port_node) { - ch = sdw_ch_mask_to_ch(p_rt->ch_mask); + ch = hweight32(p_rt->ch_mask); sdw_fill_xport_params(&p_rt->transport_params, p_rt->num, false,