From: Mathieu Desnoyers Date: Thu, 8 Mar 2012 16:00:30 +0000 (-0500) Subject: Fix: ensure power of 2 check handles 64-bit size_t entirely X-Git-Tag: v2.0.0-rc4~6 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=bbda3a00431e819ecfbe0056eaa598100c848e0c;p=lttng-modules.git Fix: ensure power of 2 check handles 64-bit size_t entirely Signed-off-by: Mathieu Desnoyers --- diff --git a/lib/ringbuffer/ring_buffer_backend.c b/lib/ringbuffer/ring_buffer_backend.c index bfe63d7b..f18ccc1a 100644 --- a/lib/ringbuffer/ring_buffer_backend.c +++ b/lib/ringbuffer/ring_buffer_backend.c @@ -307,19 +307,17 @@ int channel_backend_init(struct channel_backend *chanb, if (!name) return -EPERM; - if (!(subbuf_size && num_subbuf)) - return -EPERM; - /* Check that the subbuffer size is larger than a page. */ if (subbuf_size < PAGE_SIZE) return -EINVAL; /* - * Make sure the number of subbuffers and subbuffer size are power of 2. + * Make sure the number of subbuffers and subbuffer size are + * power of 2 and nonzero. */ - if (hweight32(subbuf_size) != 1) + if (!subbuf_size || (subbuf_size & (subbuf_size - 1))) return -EINVAL; - if (hweight32(num_subbuf) != 1) + if (!num_subbuf || (num_subbuf & (num_subbuf - 1))) return -EINVAL; ret = subbuffer_id_check_index(config, num_subbuf);