diff mbox series

[net-next,v3,14/18] sfc: Remove usage of list iterator for list_add() after the loop body

Message ID 20220412121557.3553555-15-jakobkoschel@gmail.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series Remove use of list iterator after loop body | expand

Commit Message

Jakob Koschel April 12, 2022, 12:15 p.m. UTC
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>
---
 drivers/net/ethernet/sfc/rx_common.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Jakub Kicinski April 12, 2022, 9:29 p.m. UTC | #1
On Tue, 12 Apr 2022 14:15:53 +0200 Jakob Koschel wrote:
> -	struct list_head *head = &efx->rss_context.list;
> +	struct list_head *head = *pos = &efx->rss_context.list;

ENOTBUILT, please wait with the reposting. Since you posted two
versions today I guess that's 2x 24h? :)
Jakob Koschel April 13, 2022, 8:18 a.m. UTC | #2
> On 12. Apr 2022, at 23:29, Jakub Kicinski <kuba@kernel.org> wrote:
> 
> On Tue, 12 Apr 2022 14:15:53 +0200 Jakob Koschel wrote:
>> -	struct list_head *head = &efx->rss_context.list;
>> +	struct list_head *head = *pos = &efx->rss_context.list;
> 
> ENOTBUILT, please wait with the reposting. Since you posted two
> versions today I guess that's 2x 24h? :)

oh gosh, seems like I indeed forgot to build this commit.
Sorry about all the mess :( Also I'll wait with reposting (not
going to make the same mistake twice ;)).

I messed up three times yesterday, was really not on a high.
I'll be more careful in the future to not the the same kind of
mistakes again :/
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/rx_common.c b/drivers/net/ethernet/sfc/rx_common.c
index 1b22c7be0088..80894a35ea79 100644
--- a/drivers/net/ethernet/sfc/rx_common.c
+++ b/drivers/net/ethernet/sfc/rx_common.c
@@ -555,7 +555,7 @@  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 */
 
@@ -563,8 +563,10 @@  struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx)
 
 	/* 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.
@@ -582,7 +584,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;
 }