Hi Johannes, On Tue, 1 Jun 2021 at 10:05, Johannes Berg <johannes@xxxxxxxxxxxxxxxx> wrote: > > From: Johannes Berg <johannes.berg@xxxxxxxxx> > > Add support to create (and destroy) interfaces via a new > rtnetlink kind "wwan". The responsible driver has to use > the new wwan_register_ops() to make this possible. > > Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx> > --- > drivers/net/wwan/wwan_core.c | 219 ++++++++++++++++++++++++++++++++++- > include/linux/wwan.h | 36 ++++++ > include/uapi/linux/wwan.h | 17 +++ > 3 files changed, 267 insertions(+), 5 deletions(-) > create mode 100644 include/uapi/linux/wwan.h > > diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c > index cff04e532c1e..b1ad78f386bc 100644 > --- a/drivers/net/wwan/wwan_core.c > +++ b/drivers/net/wwan/wwan_core.c > @@ -13,6 +13,8 @@ > #include <linux/slab.h> > #include <linux/types.h> > #include <linux/wwan.h> > +#include <net/rtnetlink.h> > +#include <uapi/linux/wwan.h> > > #define WWAN_MAX_MINORS 256 /* 256 minors allowed with register_chrdev() */ > > @@ -524,24 +526,231 @@ static const struct file_operations wwan_port_fops = { > .llseek = noop_llseek, > }; > > +struct wwan_dev_reg { > + struct list_head list; > + struct device *dev; > + const struct wwan_ops *ops; > + void *ctxt; > +}; > + > +static DEFINE_MUTEX(wwan_mtx); > +static LIST_HEAD(wwan_devs); > + > +int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, > + void *ctxt) > +{ > + struct wwan_dev_reg *reg; > + int ret; > + > + if (WARN_ON(!parent || !ops)) > + return -EINVAL; > + > + mutex_lock(&wwan_mtx); > + list_for_each_entry(reg, &wwan_devs, list) { > + if (WARN_ON(reg->dev == parent)) { > + ret = -EBUSY; > + goto out; > + } > + } Thanks for this, overall it looks good to me, but just checking why you're not using the wwan_dev internally to create-or-pick wwan_dev (wwan_dev_create) and register ops to it, instead of having a global new wwan_devs list. > + > + reg = kzalloc(sizeof(*reg), GFP_KERNEL); > + if (!reg) { > + ret = -ENOMEM; > + goto out; > + } > + > + reg->dev = parent; > + reg->ops = ops; > + reg->ctxt = ctxt; > + list_add_tail(®->list, &wwan_devs); > + > + ret = 0; > + > +out: > + mutex_unlock(&wwan_mtx); > + return ret; > +} > +EXPORT_SYMBOL_GPL(wwan_register_ops); Regards, Loic