Check for size==1 before rounding to power of two in epoll init.
authorDan Cross <crossd@gmail.com>
Wed, 10 Aug 2016 17:43:15 +0000 (13:43 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 10 Aug 2016 19:36:04 +0000 (15:36 -0400)
While technically 1==2^0 is a power of two, the ROUNDUPPWR2
was changing the size of the epoll set to 2 before we tested
for two; since this set does not grow, we were getting errors
trying to add low-value FDs to the set, causing errors.

Slightly rearranging the order in which we do these operations
fixes this.

Change-Id: I2d068416941e8e1e9d7cfa98d56f5ea5b159802b
Signed-off-by: Dan Cross <crossd@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/iplib/epoll.c

index 87fdae5..b370981 100644 (file)
@@ -211,10 +211,12 @@ static void epoll_close(struct user_fd *ufd)
 
 static int init_ep_ctlr(struct epoll_ctlr *ep, int size)
 {
-       unsigned int ceq_size = ROUNDUPPWR2(size);
+       unsigned int ceq_size;
+
        /* TODO: we don't grow yet.  Until then, we help out a little. */
        if (size == 1)
                size = 128;
+       ceq_size = ROUNDUPPWR2(size);
        ep->size = ceq_size;
        ep->mtx = uth_mutex_alloc();
        ep->ufd.magic = EPOLL_UFD_MAGIC;