Re: [PATCH v2 1/2] list: add missing empty list check to list_cut_before()

From: Andy Shevchenko

Date: Thu Sep 17 2026 - 11:38:21 EST


On Thu, Sep 17, 2026 at 08:55:04PM +0800, Ziran Zhang wrote:
> list_cut_before() lacks the list_empty() guard present
> in list_cut_position().
>
> With an empty head and an entry not on the list, it
> corrupts the list.

The kernel-doc specifically says:

'You should pass in @entry an element you know is on @head.'

Do you have a real life example?

> Add the missing check. When head is empty, initialize
> @list as empty, consistent with the existing
> head->next == entry case.

The room of the lines for the body of the commit message is ~72 characters
and not 56.

...

What makes it different to the similar cases in list_splice(), for example?

--
With Best Regards,
Andy Shevchenko