Re: [PATCH v2] iio: buffer: kfifo: reject lengths exceeding the kmalloc limit
From: YuanZhe Liu
Date: Mon Nov 23 2026 - 01:54:12 EST
Hi Jonathan,
Thanks for the review, and point taken on both process items.
> However that's an implementation detail of KFIFOs sneaking across the
> boundary. Given the allocation call fails anyway, why do we care about
> short cutting it?
The allocation does fail, but not quietly: the request reaches the page
allocator with an order above MAX_PAGE_ORDER, so alloc_order_allowed()
emits a WARN_ON_ONCE_GFP() with a stack trace (once per boot) before
returning NULL. A write to buffer/length followed by a write to
buffer/enable therefore produces a kernel warning for what is only a bad
user-supplied value. The check turns that into a plain -EINVAL; short
cutting the failed allocation is not the goal.
You are right about the changelog. The ABI change is that buffer/enable
now returns -EINVAL instead of -ENOMEM, and it needs to be stated. I'll
use the short form you suggested and trim the code comment so it no
longer explains page allocator internals.
On the placement: the check lives in IIO because that is where the length
is validated and where a useful error can be returned. If you would
rather have lib/kfifo enforce this for every kfifo user instead, I can
move it there - just let me know.
The next version will go out as a new thread, with a few days left for
further comments.
Thanks,
YuanZhe