From: Jakub Kicinski <kuba@kernel.org>
To: David Wei <dw@davidwei.uk>
Cc: Jiri Pirko <jiri@resnulli.us>,
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 v2 1/3] netdevsim: allow two netdevsim ports to be connected
Date: Tue, 12 Dec 2023 12:24:41 -0800 [thread overview]
Message-ID: <20231212122441.7c936a28@kernel.org> (raw)
In-Reply-To: <20231210010448.816126-2-dw@davidwei.uk>
On Sat, 9 Dec 2023 17:04:46 -0800 David Wei wrote:
> diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
> index bcbc1e19edde..3e4378e9dbee 100644
> --- a/drivers/net/netdevsim/bus.c
> +++ b/drivers/net/netdevsim/bus.c
> @@ -364,3 +364,13 @@ void nsim_bus_exit(void)
> driver_unregister(&nsim_driver);
> bus_unregister(&nsim_bus);
> }
> +
> +struct nsim_bus_dev *nsim_bus_dev_get(unsigned int id)
nit: s/get/find/ get sometimes implied taking a reference
> +{
> + struct nsim_bus_dev *nsim_bus_dev;
new line here, please checkpatch --strict
> + list_for_each_entry(nsim_bus_dev, &nsim_bus_dev_list, list) {
> + if (nsim_bus_dev->dev.id == id)
> + return nsim_bus_dev;
You must assume some lock is being held so that you can walk the list
and return a meaningful value? :) Please figure out what caller has to
hold and add an appropriate lockdep assert here.
> + }
> + return NULL;
> +}
> +static ssize_t nsim_dev_peer_read(struct file *file, char __user *data,
> + size_t count, loff_t *ppos)
> +{
> + struct nsim_dev_port *nsim_dev_port;
> + struct netdevsim *peer;
> + unsigned int id, port;
> + char buf[23];
> + ssize_t len;
> +
> + nsim_dev_port = file->private_data;
> + rcu_read_lock();
> + peer = rcu_dereference(nsim_dev_port->ns->peer);
> + if (!peer) {
> + len = scnprintf(buf, sizeof(buf), "\n");
Why not return 0?
> + goto out;
> + }
> +
> + id = peer->nsim_bus_dev->dev.id;
> + port = peer->nsim_dev_port->port_index;
> + len = scnprintf(buf, sizeof(buf), "%u %u\n", id, port);
> +
> +out:
> + rcu_read_unlock();
> + return simple_read_from_buffer(data, count, ppos, buf, len);
> +}
> @@ -417,3 +418,5 @@ struct nsim_bus_dev {
>
> int nsim_bus_init(void);
> void nsim_bus_exit(void);
> +
> +struct nsim_bus_dev *nsim_bus_dev_get(unsigned int id);
nit: let this go before the module init/exit funcs, 3 lines up
next prev parent reply other threads:[~2023-12-12 20:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-10 1:04 [PATCH net-next v2 0/3] netdevsim: link and forward skbs between ports David Wei
2023-12-10 1:04 ` [PATCH net-next v2 1/3] netdevsim: allow two netdevsim ports to be connected David Wei
2023-12-12 20:24 ` Jakub Kicinski [this message]
2023-12-13 0:37 ` David Wei
2023-12-10 1:04 ` [PATCH net-next v2 2/3] netdevsim: forward skbs from one connected port to another David Wei
2023-12-10 1:04 ` [PATCH net-next v2 3/3] netdevsim: add selftest for forwarding skb between connected ports David Wei
2023-12-12 20:29 ` Jakub Kicinski
2023-12-13 0:38 ` 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=20231212122441.7c936a28@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--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).