[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240620175703.605111-29-yury.norov@gmail.com>
Date: Thu, 20 Jun 2024 10:56:51 -0700
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org,
Karsten Keil <isdn@...ux-pingi.de>,
Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Luiz Augusto von Dentz <luiz.dentz@...il.com>,
Yury Norov <yury.norov@...il.com>,
netdev@...r.kernel.org,
linux-bluetooth@...r.kernel.org
Cc: Alexey Klimov <alexey.klimov@...aro.org>,
Bart Van Assche <bvanassche@....org>,
Jan Kara <jack@...e.cz>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Matthew Wilcox <willy@...radead.org>,
Mirsad Todorovac <mirsad.todorovac@....unizg.hr>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Sergey Shtylyov <s.shtylyov@....ru>
Subject: [PATCH v4 28/40] bluetooth: optimize cmtp_alloc_block_id()
Instead of polling every bit in blockids, use a dedicated
find_and_set_bit(), and make the function a simple one-liner.
Signed-off-by: Yury Norov <yury.norov@...il.com>
---
net/bluetooth/cmtp/core.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index 90d130588a3e..06732cf2661b 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -22,6 +22,7 @@
#include <linux/module.h>
+#include <linux/find_atomic.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/kernel.h>
@@ -88,15 +89,9 @@ static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_connin
static inline int cmtp_alloc_block_id(struct cmtp_session *session)
{
- int i, id = -1;
+ int id = find_and_set_bit(&session->blockids, 16);
- for (i = 0; i < 16; i++)
- if (!test_and_set_bit(i, &session->blockids)) {
- id = i;
- break;
- }
-
- return id;
+ return id < 16 ? id : -1;
}
static inline void cmtp_free_block_id(struct cmtp_session *session, int id)
--
2.43.0
Powered by blists - more mailing lists