Fix: ensure power of 2 check handles 64-bit size_t entirely
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 8 Mar 2012 16:00:30 +0000 (11:00 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 8 Mar 2012 16:00:30 +0000 (11:00 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lib/ringbuffer/ring_buffer_backend.c

index bfe63d7b34b913c8307ba4ae7cb17221a18287f1..f18ccc1a59c6f1972c5110b64a2341883fa6fe0c 100644 (file)
@@ -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);
This page took 0.026531 seconds and 4 git commands to generate.