From: David Laight <david.laight.linux@gmail.com>
To: Dharanitharan R <dharanitharan725@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] staging: vme_user: simplify bus number allocation using ffz()
Date: Sun, 7 Dec 2025 17:50:18 +0000 [thread overview]
Message-ID: <20251207175018.43b29806@pumpkin> (raw)
In-Reply-To: <20251207164317.4835-1-dharanitharan725@gmail.com>
On Sun, 7 Dec 2025 16:43:17 +0000
Dharanitharan R <dharanitharan725@gmail.com> wrote:
> David Laight pointed out that the loop in vme_register_bridge()
> is effectively searching for the first zero bit in vme_bus_numbers.
>
> 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, 9 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;
> - }
> +
> + /* Find the first clear bit */
> + i = ffz(vme_bus_numbers);
You need to check for ~0u first:
* ffz - find first zero in word.
* @word: The word to search
*
* Undefined if no zero exists, so code should check against ~0UL first.
David
> +
> + /* Ensure we have a free slot */
> + if (i < BITS_PER_LONG) {
> + vme_bus_numbers |= BIT(i);
> + bridge->num = i;
> + INIT_LIST_HEAD(&bridge->devices);
> + list_add_tail(&bridge->bus_list, &vme_bus_list);
> + ret = 0;
> + }
> 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);
prev parent reply other threads:[~2025-12-07 17:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-07 16:43 [PATCH v2] staging: vme_user: simplify bus number allocation using ffz() Dharanitharan R
2025-12-07 17:50 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251207175018.43b29806@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=dharanitharan725@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox