Re: [PATCH v2 1/2] list: add missing empty list check to list_cut_before()
From: Ziran Zhang
Date: Thu Sep 17 2026 - 12:41:28 EST
On Thu, 17 Sep 2026 18:21:45 +0300, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> The kernel-doc specifically says:
>
> 'You should pass in @entry an element you know is on @head.'
>
> Do you have a real life example?
No, I do not have a real life example. It was based on code
analysis only.
> The room of the lines for the body of the commit message is ~72
> characters and not 56.
Noted, I will keep that in mind for future patches.
> What makes it different to the similar cases in list_splice(), for
> example?
list_splice() has an empty-list check too, on its source list:
if (!list_empty(list))
__list_splice(list, head, head->next);
list_cut_position() does the same for its source list:
if (list_empty(head))
return;
But list_cut_position() has the same kernel-doc wording:
'You should pass on @entry an element you know is on @head.'
and still returns early for an empty head.
So list_cut_position() handles an empty head before doing any pointer
updates, even though the kernel-doc contract only requires @entry to
be on @head. My patch makes list_cut_before() do the same.
I agree this is a defensive change, not a bug fix. If the consensus
is to rely strictly on the caller contract, I will drop this series.
For list_cut_before() specifically, making it match list_cut_position()
seemed reasonable.
Thanks,
Ziran Zhang