Linux io-uring development
 help / color / mirror / Atom feed
* [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
@ 2026-05-14  8:34 Yi Xie
  2026-05-14 13:24 ` Jens Axboe
  2026-05-14 14:22 ` Caleb Sander Mateos
  0 siblings, 2 replies; 8+ messages in thread
From: Yi Xie @ 2026-05-14  8:34 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, Yi Xie

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 <xieyi@kylinos.cn>
---
 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)])
 
 struct io_provide_buf {
 	struct file			*file;

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
  2026-05-14  8:34 [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion Yi Xie
@ 2026-05-14 13:24 ` Jens Axboe
  2026-05-14 14:22 ` Caleb Sander Mateos
  1 sibling, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2026-05-14 13:24 UTC (permalink / raw)
  To: io-uring, Yi Xie


On Thu, 14 May 2026 16:34:43 +0800, Yi Xie 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.

Applied, thanks!

[1/1] io_uring: parenthesize io_ring_head_to_buf() expansion
      commit: c84701cfc90a90a6a9dfbdb138706a6d79f5b186

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
  2026-05-14  8:34 [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion Yi Xie
  2026-05-14 13:24 ` Jens Axboe
@ 2026-05-14 14:22 ` Caleb Sander Mateos
  2026-05-14 14:25   ` Jens Axboe
  1 sibling, 1 reply; 8+ messages in thread
From: Caleb Sander Mateos @ 2026-05-14 14:22 UTC (permalink / raw)
  To: Yi Xie; +Cc: io-uring, Jens Axboe

On Thu, May 14, 2026 at 1:35 AM Yi Xie <xieyi@kylinos.cn> 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 <xieyi@kylinos.cn>
> ---
>  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?

Best,
Caleb

>
>  struct io_provide_buf {
>         struct file                     *file;
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
  2026-05-14 14:22 ` Caleb Sander Mateos
@ 2026-05-14 14:25   ` Jens Axboe
  2026-05-14 14:43     ` Caleb Sander Mateos
  2026-05-14 14:58     ` Gabriel Krisman Bertazi
  0 siblings, 2 replies; 8+ messages in thread
From: Jens Axboe @ 2026-05-14 14:25 UTC (permalink / raw)
  To: Caleb Sander Mateos, Yi Xie; +Cc: io-uring

On 5/14/26 8:22 AM, Caleb Sander Mateos wrote:
> On Thu, May 14, 2026 at 1:35?AM Yi Xie <xieyi@kylinos.cn> 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 <xieyi@kylinos.cn>
>> ---
>>  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.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
  2026-05-14 14:25   ` Jens Axboe
@ 2026-05-14 14:43     ` Caleb Sander Mateos
  2026-05-14 14:44       ` Jens Axboe
  2026-05-14 14:58     ` Gabriel Krisman Bertazi
  1 sibling, 1 reply; 8+ messages in thread
From: Caleb Sander Mateos @ 2026-05-14 14:43 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Yi Xie, io-uring

On Thu, May 14, 2026 at 7:25 AM Jens Axboe <axboe@kernel.dk> wrote:
>
> On 5/14/26 8:22 AM, Caleb Sander Mateos wrote:
> > On Thu, May 14, 2026 at 1:35?AM Yi Xie <xieyi@kylinos.cn> 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 <xieyi@kylinos.cn>
> >> ---
> >>  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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
  2026-05-14 14:43     ` Caleb Sander Mateos
@ 2026-05-14 14:44       ` Jens Axboe
  0 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2026-05-14 14:44 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Yi Xie, io-uring

On 5/14/26 8:43 AM, Caleb Sander Mateos wrote:
> On Thu, May 14, 2026 at 7:25 AM Jens Axboe <axboe@kernel.dk> wrote:
>>
>> On 5/14/26 8:22 AM, Caleb Sander Mateos wrote:
>>> On Thu, May 14, 2026 at 1:35?AM Yi Xie <xieyi@kylinos.cn> 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 <xieyi@kylinos.cn>
>>>> ---
>>>>  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.

I do know the benefits of a function over a macro :-)

I just don't think it'll buy us anything in this case.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
  2026-05-14 14:25   ` Jens Axboe
  2026-05-14 14:43     ` Caleb Sander Mateos
@ 2026-05-14 14:58     ` Gabriel Krisman Bertazi
  2026-05-14 15:02       ` Jens Axboe
  1 sibling, 1 reply; 8+ messages in thread
From: Gabriel Krisman Bertazi @ 2026-05-14 14:58 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Caleb Sander Mateos, Yi Xie, io-uring

Jens Axboe <axboe@kernel.dk> writes:

>>>  /* 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?
>
> And generally I don't like cleanups like this, but this one
> at least made sense to me.

The annoying part, IMO, is that we/I look at every trivial fix
wondering if it really is just a parenthesis fix, or if it's the next
CopyFail/Fragnesia fix with an obfuscated commit message..

ty

-- 
Gabriel Krisman Bertazi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion
  2026-05-14 14:58     ` Gabriel Krisman Bertazi
@ 2026-05-14 15:02       ` Jens Axboe
  0 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2026-05-14 15:02 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: Caleb Sander Mateos, Yi Xie, io-uring

On 5/14/26 8:58 AM, Gabriel Krisman Bertazi wrote:
> Jens Axboe <axboe@kernel.dk> writes:
> 
>>>>  /* 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?
>>
>> And generally I don't like cleanups like this, but this one
>> at least made sense to me.
> 
> The annoying part, IMO, is that we/I look at every trivial fix
> wondering if it really is just a parenthesis fix, or if it's the next
> CopyFail/Fragnesia fix with an obfuscated commit message..

No kidding, trust no one these days, it's mostly all LLM and suspect :/

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-05-14 15:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-14  8:34 [PATCH] io_uring: parenthesize io_ring_head_to_buf() expansion Yi Xie
2026-05-14 13:24 ` Jens Axboe
2026-05-14 14:22 ` Caleb Sander Mateos
2026-05-14 14:25   ` Jens Axboe
2026-05-14 14:43     ` Caleb Sander Mateos
2026-05-14 14:44       ` Jens Axboe
2026-05-14 14:58     ` Gabriel Krisman Bertazi
2026-05-14 15:02       ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox