Re: [PATCH] ahci: use hweight_long() to count port_map bits
From: Niklas Cassel
Date: Wed May 27 2026 - 09:10:51 EST
On Wed, May 27, 2026 at 05:17:29PM +0800, kensanya@xxxxxxx wrote:
> From: TanZheng <tanzheng@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> ---
> drivers/ata/libahci.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
> index c79abdfcd7a9..15d44266c9df 100644
> --- a/drivers/ata/libahci.c
> +++ b/drivers/ata/libahci.c
> @@ -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.
> --
> 2.25.1
>
Hello TanZheng,
Is it a coincidence that you send this the same day as Michael pointed out
the same, or was this sent as a response to Michael's email?
Kind regards,
Niklas