Fix: power of 2 size check should apply to size_t type, not uint32_t
[lttng-ust.git] / libringbuffer / ring_buffer_backend.c
index 23802e82321416d81782911e081b4359edd1ba35..e949a5e292d2048f306760f329f64d668a0c30cd 100644 (file)
@@ -6,11 +6,12 @@
  * Dual LGPL v2.1/GPL v2 license.
  */
 
+#define _GNU_SOURCE
 #include <urcu/arch.h>
-
-#include "lttng/core.h"
+#include <limits.h>
 
 #include <lttng/ringbuffer-config.h>
+#include "vatomic.h"
 #include "backend.h"
 #include "frontend.h"
 #include "smp.h"
@@ -217,10 +218,13 @@ int channel_backend_init(struct channel_backend *chanb,
                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.
         */
-       CHAN_WARN_ON(chanb, hweight32(subbuf_size) != 1);
-       CHAN_WARN_ON(chanb, hweight32(num_subbuf) != 1);
+       if (!subbuf_size || (subbuf_size & (subbuf_size - 1)))
+               return -EINVAL;
+       if (!num_subbuf || (num_subbuf & (num_subbuf - 1)))
+               return -EINVAL;
 
        ret = subbuffer_id_check_index(config, num_subbuf);
        if (ret)
@@ -293,6 +297,7 @@ int channel_backend_init(struct channel_backend *chanb,
                buf = shmp(handle, chanb->buf[0].shmp);
                if (!buf)
                        goto end;
+               set_shmp(buf->self, chanb->buf[0].shmp._ref);
                ret = lib_ring_buffer_create(buf, chanb, -1,
                                        handle, shmobj);
                if (ret)
This page took 0.024371 seconds and 4 git commands to generate.