Re: [PATCH] firewire: remove check of list iterator against head past the loop body

From: Takashi Sakamoto
Date: Sun Apr 03 2022 - 01:10:20 EST


Hi,

On Fri, Apr 01, 2022 at 12:36:01AM +0200, Jakob Koschel wrote:
> When list_for_each_entry() completes the iteration over the whole list
> without breaking the loop, the iterator value will be a bogus pointer
> computed based on the head element.
>
> While it is safe to use the pointer to determine if it was computed
> based on the head element, either with list_entry_is_head() or
> &pos->member == head, using the iterator variable after the loop should
> be avoided.
>
> In preparation to limit the scope of a list iterator to the list
> traversal loop, use a dedicated pointer to point to the found element [1].
>
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@xxxxxxxxxxxxxx/ [1]
> Signed-off-by: Jakob Koschel <jakobkoschel@xxxxxxxxx>
> ---
> drivers/firewire/core-transaction.c | 30 +++++++++++++++--------------
> drivers/firewire/sbp2.c | 13 +++++++------
> 2 files changed, 23 insertions(+), 20 deletions(-)

I think it is a good catch.

Reviewed-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>

For the changes in firewire-core module:
Tested-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>

Unfortunately the activity for maintenance in Linux FireWire subsystem
is quite low. No actions in past half a year. If the patch blocks
further work to improve list implementation, I think it better to look
for the other path to merge.


Regards

Takashi Sakamoto