- /* TODO Replace atoi with strtol and check for errors */
- chan.attr.num_subbuf = atoi(poptGetOptArg(pc));
+ {
+ uint64_t rounded_size;
+ int order;
+
+ errno = 0;
+ opt_arg = poptGetOptArg(pc);
+ chan.attr.num_subbuf = strtoull(opt_arg, NULL, 0);
+ if (errno != 0 || !chan.attr.num_subbuf || !isdigit(opt_arg[0])) {
+ ERR("Wrong value in --num-subbuf parameter: %s", opt_arg);
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ order = get_count_order_u64(chan.attr.num_subbuf);
+ assert(order >= 0);
+ rounded_size = 1ULL << order;
+ if (rounded_size != chan.attr.num_subbuf) {
+ WARN("The number of subbuffers (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")",
+ chan.attr.num_subbuf, rounded_size);
+ chan.attr.num_subbuf = rounded_size;
+ }
+
+ /* Should now be power of 2 */
+ assert(!((chan.attr.num_subbuf - 1) & chan.attr.num_subbuf));
+