netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: David Wei <dw@davidwei.uk>
Cc: Jakub Kicinski <kuba@kernel.org>,
	Sabrina Dubroca <sd@queasysnail.net>,
	netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH net-next v5 1/5] netdevsim: maintain a list of probed netdevsims
Date: Tue, 2 Jan 2024 12:04:17 +0100	[thread overview]
Message-ID: <ZZPtsfyHfDyuqfxM@nanopsycho> (raw)
In-Reply-To: <20231228014633.3256862-2-dw@davidwei.uk>

Thu, Dec 28, 2023 at 02:46:29AM CET, dw@davidwei.uk wrote:
>In this patch I added a linked list nsim_dev_list of probed nsim_devs,
>added during nsim_drv_probe() and removed during nsim_drv_remove(). A
>mutex nsim_dev_list_lock protects the list.
>
>Signed-off-by: David Wei <dw@davidwei.uk>
>---
> drivers/net/netdevsim/dev.c       | 19 +++++++++++++++++++
> drivers/net/netdevsim/netdevsim.h |  1 +
> 2 files changed, 20 insertions(+)
>
>diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
>index b4d3b9cde8bd..8d477aa99f94 100644
>--- a/drivers/net/netdevsim/dev.c
>+++ b/drivers/net/netdevsim/dev.c
>@@ -35,6 +35,9 @@
> 
> #include "netdevsim.h"
> 
>+static LIST_HEAD(nsim_dev_list);
>+static DEFINE_MUTEX(nsim_dev_list_lock);
>+
> static unsigned int
> nsim_dev_port_index(enum nsim_dev_port_type type, unsigned int port_index)
> {
>@@ -1607,6 +1610,11 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev)
> 
> 	nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_LEGACY;
> 	devl_unlock(devlink);
>+
>+	mutex_lock(&nsim_dev_list_lock);
>+	list_add(&nsim_dev->list, &nsim_dev_list);
>+	mutex_unlock(&nsim_dev_list_lock);
>+
> 	return 0;
> 
> err_hwstats_exit:
>@@ -1668,8 +1676,19 @@ void nsim_drv_remove(struct nsim_bus_dev *nsim_bus_dev)
> {
> 	struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
> 	struct devlink *devlink = priv_to_devlink(nsim_dev);
>+	struct nsim_dev *pos, *tmp;
>+
>+	mutex_lock(&nsim_dev_list_lock);
>+	list_for_each_entry_safe(pos, tmp, &nsim_dev_list, list) {
>+		if (pos == nsim_dev) {
>+			list_del(&nsim_dev->list);
>+			break;
>+		}
>+	}
>+	mutex_unlock(&nsim_dev_list_lock);

This is just:
	mutex_lock(&nsim_dev_list_lock);
	list_del(&nsim_dev->list);
	mutex_unlock(&nsim_dev_list_lock);

The loop is not good for anything.



> 
> 	devl_lock(devlink);
>+

Remove this leftover line addition.


> 	nsim_dev_reload_destroy(nsim_dev);
> 
> 	nsim_bpf_dev_exit(nsim_dev);
>diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
>index 028c825b86db..babb61d7790b 100644
>--- a/drivers/net/netdevsim/netdevsim.h
>+++ b/drivers/net/netdevsim/netdevsim.h
>@@ -277,6 +277,7 @@ struct nsim_vf_config {
> 
> struct nsim_dev {
> 	struct nsim_bus_dev *nsim_bus_dev;
>+	struct list_head list;
> 	struct nsim_fib_data *fib_data;
> 	struct nsim_trap_data *trap_data;
> 	struct dentry *ddir;
>-- 
>2.39.3
>

  reply	other threads:[~2024-01-02 11:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28  1:46 [PATCH net-next v5 0/5] netdevsim: link and forward skbs between ports David Wei
2023-12-28  1:46 ` [PATCH net-next v5 1/5] netdevsim: maintain a list of probed netdevsims David Wei
2024-01-02 11:04   ` Jiri Pirko [this message]
2024-01-03 21:48     ` David Wei
2023-12-28  1:46 ` [PATCH net-next v5 2/5] netdevsim: allow two netdevsim ports to be connected David Wei
2024-01-02 11:11   ` Jiri Pirko
2024-01-03 21:56     ` David Wei
2024-01-04  9:30       ` Jiri Pirko
2024-01-04  1:39   ` Jakub Kicinski
2024-01-09 16:57     ` David Wei
2024-01-10  1:53       ` Jakub Kicinski
2023-12-28  1:46 ` [PATCH net-next v5 3/5] netdevsim: forward skbs from one connected port to another David Wei
2024-01-02 11:13   ` Jiri Pirko
2024-01-03 22:36     ` David Wei
2024-01-04  9:31       ` Jiri Pirko
2024-01-09 16:58         ` David Wei
2024-01-02 11:20   ` Eric Dumazet
2024-01-03 21:57     ` David Wei
2023-12-28  1:46 ` [PATCH net-next v5 4/5] netdevsim: add selftest for forwarding skb between connected ports David Wei
2023-12-28  1:46 ` [PATCH net-next v5 5/5] netdevsim: add Makefile for selftests David Wei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZZPtsfyHfDyuqfxM@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=davem@davemloft.net \
    --cc=dw@davidwei.uk \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).