Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
Caleb Sander Mateos <[email protected]>
| Newsgroups | org.kernel.vger.io-uring |
|---|---|
| Message-ID | <CADUfDZqGmQd0t0614yU6FKYWs74iFWnuEhp0BaxTfgDWwLDLLA@mail.gmail.com> |
On Thu, May 14, 2026 at 7:25 AM Jens Axboe <[email protected]> wrote: > > On 5/14/26 8:22 AM, Caleb Sander Mateos wrote: > > On Thu, May 14, 2026 at 1:35?AM Yi Xie <[email protected]> wrote: > >> > >> Wrap the io_ring_head_to_buf() macro value in an extra pair of parentheses > >> so it is safe when composed into larger expressions, and to satisfy > >> scripts/checkpatch.pl. > >> > >> Signed-off-by: Yi Xie <[email protected]> > >> --- > >> io_uring/kbuf.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c > >> index 63061aa1cab9..dd54e43e9ddf 100644 > >> --- a/io_uring/kbuf.c > >> +++ b/io_uring/kbuf.c > >> @@ -21,7 +21,7 @@ > >> #define MAX_BIDS_PER_BGID (1 << 16) > >> > >> /* Mapped buffer ring, return io_uring_buf from head */ > >> -#define io_ring_head_to_buf(br, head, mask) &(br)->bufs[(head) & (mask)] > >> +#define io_ring_head_to_buf(br, head, mask) (&(br)->bufs[(head) & (mask)]) > > > > Is there a reason this can't just be an inline function? > > No reason at all. But also don't see a strong reason why it can't just > be a define. And generally I don't like cleanups like this, but this one > at least made sense to me. A macro can certainly work, but as this patch shows, it's tricky to remember all the parentheses. An inline function also results in better compiler error messages since the arguments are strongly typed. And not applicable in this case, but if an argument is used multiple times, a function ensures it's only evaluated once. I would generally only reach for a macro when something can't be expressed as an inline function. Best, Caleb