From nobody Wed Feb 11 10:19:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90399C61DA4 for ; Wed, 15 Mar 2023 14:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233217AbjCOOyd (ORCPT ); Wed, 15 Mar 2023 10:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232713AbjCOOxw (ORCPT ); Wed, 15 Mar 2023 10:53:52 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA64F73018 for ; Wed, 15 Mar 2023 07:53:09 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32FDfUgM005537; Wed, 15 Mar 2023 09:50:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=pWMqDfEbuDPsT+Ceamk5KjkKsq+KJmIB8Gqk1dqazgg=; b=gYNIDjMBTt+Sod5XDBaB75NnRFotHmJzrdT8SLq0FSfAfFWXCgGNbxS5XPbJ3mEkCmNp V4kx50nOxt3LMMw+g517S8CPKgr2ocsnLo2Nbn8W0bc+4ta1AZHQc2Y1FrcerozdUhy9 5F9sP79hL52r3qo9B0cr6za1LO4QPZGWeTsCOeKLl5/K3YH1pTyjCJItkuNBK4zAUnCH FfQRNPwUBSz3YtmUDkinjpRZqZ3sGnMOGF627YXfuGDNa6lir65P7qbjaAHTJYNOPAGK K2nYNEszSuCczRdLtH/eQSSUJgSFC7ev9EV8BQw/wthn0UNwGQo4gkvGTvkbYwZQgYgC PA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3pb2cr8ngr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Mar 2023 09:50:53 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Wed, 15 Mar 2023 09:50:51 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Wed, 15 Mar 2023 09:50:51 -0500 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.127]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 5C2322A1; Wed, 15 Mar 2023 14:50:51 +0000 (UTC) From: Richard Fitzgerald To: CC: , , , , , , Richard Fitzgerald Subject: [PATCH v2] soundwire: bandwidth allocation: Use hweight32() to calculate set bits Date: Wed, 15 Mar 2023 14:50:51 +0000 Message-ID: <20230315145051.2299822-1-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: jD3WVWl48rhYLIXtKbWC8wHIP6IIUMbz X-Proofpoint-GUID: jD3WVWl48rhYLIXtKbWC8wHIP6IIUMbz X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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); =20 -/* Retrieve and return channel count from channel mask */ -static inline int sdw_ch_mask_to_ch(int ch_mask) -{ - int c =3D 0; - - for (c =3D 0; ch_mask; ch_mask >>=3D 1) - c +=3D ch_mask & 1; - - return c; -} - /* Fill transport parameter data structure */ static inline void sdw_fill_xport_params(struct sdw_transport_params *para= ms, int port_num, bool grp_ctrl_valid, diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/sou= ndwire/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 @@ * */ =20 +#include #include #include #include @@ -54,7 +55,7 @@ static void sdw_compute_slave_ports(struct sdw_master_run= time *m_rt, slave_total_ch =3D 0; =20 list_for_each_entry(p_rt, &s_rt->port_list, port_node) { - ch =3D sdw_ch_mask_to_ch(p_rt->ch_mask); + ch =3D hweight32(p_rt->ch_mask); =20 sdw_fill_xport_params(&p_rt->transport_params, p_rt->num, false, --=20 2.30.2