]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ata: ahci: use hweight_long() to count port_map bits
authorTanZheng <tanzheng@kylinos.cn>
Thu, 28 May 2026 06:00:50 +0000 (14:00 +0800)
committerNiklas Cassel <cassel@kernel.org>
Mon, 1 Jun 2026 17:07:37 +0000 (19:07 +0200)
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>
drivers/ata/libahci.c

index 0c5e5b29bce4cd6bc56571bbfdc4f05579800720..e0af4b5716b3f2c3859210956f5ee93a2f7061f6 100644 (file)
@@ -552,11 +552,7 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv)
 
        /* cross check port_map and cap.n_ports */
        if (port_map) {
-               int map_ports = 0;
-
-               for (i = 0; i < AHCI_MAX_PORTS; i++)
-                       if (port_map & (1 << i))
-                               map_ports++;
+               int map_ports = hweight_long(port_map);
 
                /* If PI has more ports than n_ports, whine, clear
                 * port_map and let it be generated from n_ports.