diff mbox series

[v4,07/40] sparc: optimize alloc_msi() by using find_and_set_bit()

Message ID 20240620175703.605111-8-yury.norov@gmail.com
State New
Headers show
Series lib/find: add atomic find_bit() primitives | expand

Commit Message

Yury Norov June 20, 2024, 5:56 p.m. UTC
alloc_msi() opencodes find_and_set_bit(). Simplify it by using the
dedicated function, and make a nice one-liner.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 arch/sparc/kernel/pci_msi.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/arch/sparc/kernel/pci_msi.c b/arch/sparc/kernel/pci_msi.c
index acb2f83a1d5c..55ff78a8f37c 100644
--- a/arch/sparc/kernel/pci_msi.c
+++ b/arch/sparc/kernel/pci_msi.c
@@ -3,6 +3,7 @@ 
  *
  * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
  */
+#include <linux/find_atomic.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/of.h>
@@ -96,14 +97,9 @@  static u32 pick_msiq(struct pci_pbm_info *pbm)
 
 static int alloc_msi(struct pci_pbm_info *pbm)
 {
-	int i;
-
-	for (i = 0; i < pbm->msi_num; i++) {
-		if (!test_and_set_bit(i, pbm->msi_bitmap))
-			return i + pbm->msi_first;
-	}
+	int i = find_and_set_bit(pbm->msi_bitmap, pbm->msi_num);
 
-	return -ENOENT;
+	return i < pbm->msi_num ? i + pbm->msi_first : -ENOENT;
 }
 
 static void free_msi(struct pci_pbm_info *pbm, int msi_num)