[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 03/76] bt-sdp: fix broken uuids power-of-2 calculatio
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 03/76] bt-sdp: fix broken uuids power-of-2 calculation |
Date: |
Tue, 28 Apr 2015 16:59:45 +0200 |
From: Stefan Hajnoczi <address@hidden>
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)!
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.
Cc: Andrzej Zaborowski <address@hidden>
Cc: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
Message-id: address@hidden
Signed-off-by: Kevin Wolf <address@hidden>
---
hw/bt/sdp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/bt/sdp.c b/hw/bt/sdp.c
index 218e075..c903747 100644
--- a/hw/bt/sdp.c
+++ b/hw/bt/sdp.c
@@ -707,7 +707,7 @@ static void sdp_service_record_build(struct
sdp_service_record_s *record,
len += sdp_attr_max_size(&def->attributes[record->attributes ++].data,
&record->uuids);
}
- record->uuids = 1 << ffs(record->uuids - 1);
+ record->uuids = pow2ceil(record->uuids);
record->attribute_list =
g_malloc0(record->attributes * sizeof(*record->attribute_list));
record->uuid =
--
1.8.3.1
- [Qemu-block] [PULL 00/76] Block patches, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 02/76] MAINTAINERS: Add myself as the maintainer of the Quorum driver, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 01/76] savevm: create snapshot failed when id_str already exists, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 03/76] bt-sdp: fix broken uuids power-of-2 calculation,
Kevin Wolf <=
- [Qemu-block] [PULL 04/76] hw/arm/nseries: convert ffs(3) to ctz32(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 05/76] uninorth: convert ffs(3) to ctz32(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 07/76] Convert ffs() != 0 callers to ctz32(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 08/76] sd: convert sd_normal_command() ffs(3) call to ctz32(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 09/76] omap_intc: convert ffs(3) to ctz32() in omap_inth_sir_update(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 06/76] Convert (ffs(val) - 1) to ctz32(val), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 10/76] os-win32: drop ffs(3) prototype, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 11/76] checkpatch: complain about ffs(3) calls, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 12/76] block: Switch to host monotonic clock for IO throttling, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 13/76] aio-posix: move pollfds to thread-local storage, Kevin Wolf, 2015/04/28