Skip to content

Commit

Permalink
sfc: Remove usage of list iterator for list_add() after the loop body
Browse files Browse the repository at this point in the history
In preparation to limit the scope of a list iterator to the list
traversal loop, use a dedicated pointer pointing to the location
where the element should be inserted [1].

Before, the code implicitly used the head when no element was found
when using &new->list. The new 'pos' variable is set to the list head
by default and overwritten if the list exits early, marking the
insertion point for list_add().

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
  • Loading branch information
Jakob-Koschel authored and intel-lab-lkp committed Apr 12, 2022
1 parent 98edac3 commit 37e6782
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/net/ethernet/sfc/rx_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,18 @@ efx_rx_packet_gro(struct efx_channel *channel, struct efx_rx_buffer *rx_buf,
*/
struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx)
{
struct list_head *head = &efx->rss_context.list;
struct list_head *head = *pos = &efx->rss_context.list;
struct efx_rss_context *ctx, *new;
u32 id = 1; /* Don't use zero, that refers to the master RSS context */

WARN_ON(!mutex_is_locked(&efx->rss_lock));

/* Search for first gap in the numbering */
list_for_each_entry(ctx, head, list) {
if (ctx->user_id != id)
if (ctx->user_id != id) {
pos = &ctx->list;
break;
}
id++;
/* Check for wrap. If this happens, we have nearly 2^32
* allocated RSS contexts, which seems unlikely.
Expand All @@ -585,7 +587,7 @@ struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx)

/* Insert the new entry into the gap */
new->user_id = id;
list_add_tail(&new->list, &ctx->list);
list_add_tail(&new->list, pos);
return new;
}

Expand Down

0 comments on commit 37e6782

Please sign in to comment.