[PATCH v2] ata: ahci: use hweight_long() to count port_map bits

kensanya@163.com posted 1 patch 1 week, 4 days ago
drivers/ata/libahci.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
[PATCH v2] ata: ahci: use hweight_long() to count port_map bits
Posted by kensanya@163.com 1 week, 4 days ago
From: TanZheng <tanzheng@kylinos.cn>

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.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: TanZheng <tanzheng@kylinos.cn>
---
v2:
- Add the prefix "ata:" to the patch title

---
 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
Re: [PATCH v2] ata: ahci: use hweight_long() to count port_map bits
Posted by Damien Le Moal 1 week, 3 days ago
On 2026/05/28 15:00, kensanya@163.com wrote:
> From: TanZheng <tanzheng@kylinos.cn>
> 
> 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.
> 
> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> Signed-off-by: TanZheng <tanzheng@kylinos.cn>

Title: I suggested:

ata: libahci: ...

You did not fix that.


-- 
Damien Le Moal
Western Digital Research
Re: [PATCH v2] ata: ahci: use hweight_long() to count port_map bits
Posted by Niklas Cassel 1 week, 4 days ago
On Thu, 28 May 2026 14:00:50 +0800, kensanya@163.com wrote:
> 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.

Applied to libata/linux.git (for-next), thanks!

[1/1] ata: ahci: use hweight_long() to count port_map bits
      https://git.kernel.org/libata/linux/c/b7ed008e

Kind regards,
Niklas
Re: [PATCH v2] ata: ahci: use hweight_long() to count port_map bits
Posted by Hannes Reinecke 1 week, 4 days ago
On 5/28/26 08:00, kensanya@163.com wrote:
> From: TanZheng <tanzheng@kylinos.cn>
> 
> 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.
> 
> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> Signed-off-by: TanZheng <tanzheng@kylinos.cn>
> ---
> v2:
> - Add the prefix "ata:" to the patch title
> 
Reviewed-by: Hannes Reinecke <hare@kernel.org>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich