Fix this by using the much simpler x & (x - 1) check (rather than
hweight(x) == 1).
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
return order;
}
-static inline
-unsigned int hweight32(unsigned int value)
-{
- unsigned int r;
-
- r = value;
- r = r - ((r >> 1) & 0x55555555);
- r = (r & 0x33333333) + ((r >> 2) & 0x33333333);
- r += r >> 4;
- r &= 0x0F0F0F0F;
- r += r >> 8;
- r += r >> 16;
- r &= 0x000000FF;
- return r;
-}
-
#endif /* _LINUX_RING_BUFFER_BACKEND_INTERNAL_H */
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);