Skip to content

Commit f80cea8

Browse files
TanZhengfloatious
authored andcommitted
ata: ahci: use hweight_long() to count port_map bits
Replace the open loop used to calculate the number of set bits in the port mapping with the `hweight_long()` function, which simplifies the code without altering its functionality. Signed-off-by: TanZheng <tanzheng@kylinos.cn> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@kernel.org> Signed-off-by: Niklas Cassel <cassel@kernel.org>
1 parent aa0ae1c commit f80cea8

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

drivers/ata/libahci.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,7 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv)
552552

553553
/* cross check port_map and cap.n_ports */
554554
if (port_map) {
555-
int map_ports = 0;
556-
557-
for (i = 0; i < AHCI_MAX_PORTS; i++)
558-
if (port_map & (1 << i))
559-
map_ports++;
555+
int map_ports = hweight_long(port_map);
560556

561557
/* If PI has more ports than n_ports, whine, clear
562558
* port_map and let it be generated from n_ports.

0 commit comments

Comments
 (0)