From: Eric Blake <eblake@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Andrzej Zaborowski <balrog@zabor.org>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/7] bt-sdp: fix broken uuids power-of-2 calculation
Date: Tue, 17 Mar 2015 08:37:56 -0600 [thread overview]
Message-ID: <55083C44.2010805@redhat.com> (raw)
In-Reply-To: <1426593410-21405-2-git-send-email-stefanha@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1406 bytes --]
On 03/17/2015 05:56 AM, Stefan Hajnoczi wrote:
> The binary search in sdp_uuid_match() only works when the number of
> elements to search is a power of two.
>
> lo = record->uuid;
> hi = record->uuids;
> while (hi >>= 1)
> if (lo[hi] <= val)
> lo += hi;
>
> return *lo == val;
>
> I noticed that the record->uuids calculation in
> sdp_service_record_build() was suspect:
>
> record->uuids = 1 << ffs(record->uuids - 1);
>
> Unlike most ffs(val) - 1 users, the expression is ffs(val - 1)!
Indeed, quite likely to be quite wrong.
>
> Actually ffs() is the wrong function to use for power-of-2. Use
> pow2ceil() to achieve the correct effect. Now the record->uuid[] array
> is sized correctly and the binary search in sdp_uuid_match() should
> work.
>
> I'm not sure how to run/test this code.
Me neither. But I can still analyze the code for sanity. Counts as a
bug fix, so I'd put this in 2.3, even if the rest of the series is
deferred to 2.4 as being a style cleanup rather than bug fix.
>
> Cc: Andrzej Zaborowski <balrog@zabor.org>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> hw/bt/sdp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-03-17 14:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 11:56 [Qemu-devel] [PATCH 0/7] Convert ffs(3) to ctz32() Stefan Hajnoczi
2015-03-17 11:56 ` [Qemu-devel] [PATCH 1/7] bt-sdp: fix broken uuids power-of-2 calculation Stefan Hajnoczi
2015-03-17 14:37 ` Eric Blake [this message]
2015-03-17 11:56 ` [Qemu-devel] [PATCH 2/7] Convert (ffs(val) - 1) to ctz32(val) Stefan Hajnoczi
2015-03-17 12:09 ` Peter Maydell
2015-03-17 14:54 ` Stefan Hajnoczi
2015-03-17 11:56 ` [Qemu-devel] [PATCH 3/7] Convert ffs() != 0 callers to ctz32() Stefan Hajnoczi
2015-03-30 15:42 ` Richard Henderson
2015-03-17 11:56 ` [Qemu-devel] [PATCH 4/7] sd: convert sd_normal_command() ffs(3) call " Stefan Hajnoczi
2015-03-17 11:56 ` [Qemu-devel] [PATCH 5/7] omap_intc: convert ffs(3) to ctz32() in omap_inth_sir_update() Stefan Hajnoczi
2015-03-17 14:58 ` Paolo Bonzini
2015-03-30 15:44 ` Richard Henderson
2015-03-17 11:56 ` [Qemu-devel] [PATCH 6/7] os-win32: drop ffs(3) prototype Stefan Hajnoczi
2015-03-17 11:56 ` [Qemu-devel] [PATCH 7/7] checkpatch: complain about ffs(3) calls Stefan Hajnoczi
2015-03-17 12:02 ` [Qemu-devel] [PATCH 0/7] Convert ffs(3) to ctz32() Stefan Hajnoczi
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=55083C44.2010805@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=balrog@zabor.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).