[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/7] bt-sdp: fix broken uuids power-of-2 calcula
From: |
Eric Blake |
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 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
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 <address@hidden>
> Signed-off-by: Stefan Hajnoczi <address@hidden>
> ---
> hw/bt/sdp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH 0/7] Convert ffs(3) to ctz32(), Stefan Hajnoczi, 2015/03/17
- [Qemu-devel] [PATCH 1/7] bt-sdp: fix broken uuids power-of-2 calculation, Stefan Hajnoczi, 2015/03/17
- Re: [Qemu-devel] [PATCH 1/7] bt-sdp: fix broken uuids power-of-2 calculation,
Eric Blake <=
- [Qemu-devel] [PATCH 6/7] os-win32: drop ffs(3) prototype, Stefan Hajnoczi, 2015/03/17
- [Qemu-devel] [PATCH 4/7] sd: convert sd_normal_command() ffs(3) call to ctz32(), Stefan Hajnoczi, 2015/03/17
- [Qemu-devel] [PATCH 3/7] Convert ffs() != 0 callers to ctz32(), Stefan Hajnoczi, 2015/03/17
- [Qemu-devel] [PATCH 7/7] checkpatch: complain about ffs(3) calls, Stefan Hajnoczi, 2015/03/17
- [Qemu-devel] [PATCH 5/7] omap_intc: convert ffs(3) to ctz32() in omap_inth_sir_update(), Stefan Hajnoczi, 2015/03/17
- [Qemu-devel] [PATCH 2/7] Convert (ffs(val) - 1) to ctz32(val), Stefan Hajnoczi, 2015/03/17