Skip to content

Commit 9ddae9d

Browse files
rfvirgilvinodkoul
authored andcommitted
soundwire: bandwidth allocation: Use hweight32() to calculate set bits
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 <rf@opensource.cirrus.com> Link: https://lore.kernel.org/r/20230315145051.2299822-1-rf@opensource.cirrus.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 2367e0e commit 9ddae9d

2 files changed

Lines changed: 2 additions & 12 deletions

File tree

drivers/soundwire/bus.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,6 @@ int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg);
158158
int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
159159
u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf);
160160

161-
/* Retrieve and return channel count from channel mask */
162-
static inline int sdw_ch_mask_to_ch(int ch_mask)
163-
{
164-
int c = 0;
165-
166-
for (c = 0; ch_mask; ch_mask >>= 1)
167-
c += ch_mask & 1;
168-
169-
return c;
170-
}
171-
172161
/* Fill transport parameter data structure */
173162
static inline void sdw_fill_xport_params(struct sdw_transport_params *params,
174163
int port_num, bool grp_ctrl_valid,

drivers/soundwire/generic_bandwidth_allocation.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*/
88

9+
#include <linux/bitops.h>
910
#include <linux/device.h>
1011
#include <linux/module.h>
1112
#include <linux/mod_devicetable.h>
@@ -54,7 +55,7 @@ static void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt,
5455
slave_total_ch = 0;
5556

5657
list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
57-
ch = sdw_ch_mask_to_ch(p_rt->ch_mask);
58+
ch = hweight32(p_rt->ch_mask);
5859

5960
sdw_fill_xport_params(&p_rt->transport_params,
6061
p_rt->num, false,

0 commit comments

Comments
 (0)