* [PATCH v3] staging: vme_user: simplify bus number allocation using ffz()
@ 2025-12-10 9:42 Dharanitharan R
2025-12-10 9:51 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Dharanitharan R @ 2025-12-10 9:42 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, david.laight.linux, dharanitharan725
David Laight pointed out that the loop in vme_register_bridge()
is effectively searching for the first zero bit in vme_bus_numbers.
Add a check for vme_bus_numbers == ~0UL before calling ffz().
Replace the manual loop with ffz() and use BIT(n) for consistency.
Suggested-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Dharanitharan R <dharanitharan725@gmail.com>
---
drivers/staging/vme_user/vme.c | 15 +++++++++++++----------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/vme_user/vme.c b/drivers/staging/vme_user/vme.c
index 2095de72596a..45381e677475 100644
--- a/drivers/staging/vme_user/vme.c
+++ b/drivers/staging/vme_user/vme.c
@@ -1765,16 +1765,19 @@ int vme_register_bridge(struct vme_bridge *bridge)
int ret = -1;
mutex_lock(&vme_buses_lock);
- for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++){
- if ((vme_bus_numbers & (1 << i)) == 0) {
- vme_bus_numbers |= (1 << i);
- bridge->num = i;
- INIT_LIST_HEAD(&bridge->devices);
- list_add_tail(&bridge->bus_list, &vme_bus_list);
- ret = 0;
- break;
- }
+ /* Ensure we have a free slot before using ffz() */
+ if (vme_bus_numbers == ~0UL)
+ goto out; /* No free bus number */
+
+ /* Find the first clear bit */
+ i = ffz(vme_bus_numbers);
+
+ vme_bus_numbers |= BIT(i);
+ bridge->num = i;
+ INIT_LIST_HEAD(&bridge->devices);
+ list_add_tail(&bridge->bus_list, &vme_bus_list);
+ ret = 0;
+
+out:
mutex_unlock(&vme_buses_lock);
return ret;
@@ -1787,7 +1790,7 @@ void vme_unregister_bridge(struct vme_bridge *bridge)
struct vme_dev *tmp;
mutex_lock(&vme_buses_lock);
- vme_bus_numbers &= ~(1 << bridge->num);
+ vme_bus_numbers &= ~BIT(bridge->num);
list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) {
list_del(&vdev->drv_list);
list_del(&vdev->bridge_list);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v3] staging: vme_user: simplify bus number allocation using ffz()
2025-12-10 9:42 [PATCH v3] staging: vme_user: simplify bus number allocation using ffz() Dharanitharan R
@ 2025-12-10 9:51 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2025-12-10 9:51 UTC (permalink / raw)
To: Dharanitharan R; +Cc: gregkh, linux-staging, linux-kernel, david.laight.linux
On Wed, Dec 10, 2025 at 09:42:08AM +0000, Dharanitharan R wrote:
> David Laight pointed out that the loop in vme_register_bridge()
> is effectively searching for the first zero bit in vme_bus_numbers.
> Add a check for vme_bus_numbers == ~0UL before calling ffz().
>
> Replace the manual loop with ffz() and use BIT(n) for consistency.
>
> Suggested-by: David Laight <david.laight.linux@gmail.com>
> Signed-off-by: Dharanitharan R <dharanitharan725@gmail.com>
> ---
The patch is corrupted somehow and doesn't apply.
patching file drivers/staging/vme_user/vme.c
patch: **** malformed patch at line 204: return ret;
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3] staging: vme_user: simplify bus number allocation using ffz()
@ 2025-12-10 10:00 Dharanitharan R
2025-12-10 11:17 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Dharanitharan R @ 2025-12-10 10:00 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, dharanitharan725, david.laight.linux
David Laight pointed out that the loop in vme_register_bridge()
is effectively searching for the first zero bit in vme_bus_numbers.
Add a check for vme_bus_numbers == ~0UL before calling ffz().
Replace the manual loop with ffz() and use BIT(n) for consistency.
Suggested-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Dharanitharan R <dharanitharan725@gmail.com>
---
drivers/staging/vme_user/vme.c | 15 +++++++++++++----------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/vme_user/vme.c b/drivers/staging/vme_user/vme.c
index 2095de72596a..45381e677475 100644
--- a/drivers/staging/vme_user/vme.c
+++ b/drivers/staging/vme_user/vme.c
@@ -1765,16 +1765,19 @@ int vme_register_bridge(struct vme_bridge *bridge)
int ret = -1;
mutex_lock(&vme_buses_lock);
- for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++){
- if ((vme_bus_numbers & (1 << i)) == 0) {
- vme_bus_numbers |= (1 << i);
- bridge->num = i;
- INIT_LIST_HEAD(&bridge->devices);
- list_add_tail(&bridge->bus_list, &vme_bus_list);
- ret = 0;
- break;
- }
+ /* Ensure we have a free slot before using ffz() */
+ if (vme_bus_numbers == ~0UL)
+ goto out; /* No free bus number */
+
+ /* Find the first clear bit */
+ i = ffz(vme_bus_numbers);
+
+ vme_bus_numbers |= BIT(i);
+ bridge->num = i;
+ INIT_LIST_HEAD(&bridge->devices);
+ list_add_tail(&bridge->bus_list, &vme_bus_list);
+ ret = 0;
+
+out:
mutex_unlock(&vme_buses_lock);
return ret;
@@ -1787,7 +1790,7 @@ void vme_unregister_bridge(struct vme_bridge *bridge)
struct vme_dev *tmp;
mutex_lock(&vme_buses_lock);
- vme_bus_numbers &= ~(1 << bridge->num);
+ vme_bus_numbers &= ~BIT(bridge->num);
list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) {
list_del(&vdev->drv_list);
list_del(&vdev->bridge_list);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-10 11:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 9:42 [PATCH v3] staging: vme_user: simplify bus number allocation using ffz() Dharanitharan R
2025-12-10 9:51 ` Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2025-12-10 10:00 Dharanitharan R
2025-12-10 11:17 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).