Message ID | 1533663131-16313-4-git-send-email-ben.whitten@gmail.com |
---|---|
State | Not Applicable, archived |
Delegated to: | David Miller |
Headers | show |
Series | Conversing sx1301 to regmap and regfield | expand |
Am 07.08.2018 um 19:32 schrieb Ben Whitten: > From: Ben Whitten <ben.whitten@lairdtech.com> > > Follow the devm model so that we can avoid lengthy unwind code. > > Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com> > --- > drivers/net/lora/dev.c | 20 ++++++++++++++++++++ > include/linux/lora/dev.h | 1 + > 2 files changed, 21 insertions(+) > > diff --git a/drivers/net/lora/dev.c b/drivers/net/lora/dev.c > index 8c01106..69a8b52 100644 > --- a/drivers/net/lora/dev.c > +++ b/drivers/net/lora/dev.c > @@ -84,6 +84,26 @@ void free_loradev(struct net_device *dev) > } > EXPORT_SYMBOL_GPL(free_loradev); > > +static void devm_lora_unregister(struct device *dev, void *res) > +{ > + free_loradev(*(struct net_device **)res); Suggest to use a variable. > +} > + > +int devm_lora_register_netdev(struct device *dev, struct net_device *net) Nice idea, but why a separate registration function? Suggest to instead introduce devm_alloc_loradev(). If you then reorder those two patches to the front of the series, I'll queue them immediately. Thanks, Andreas
diff --git a/drivers/net/lora/dev.c b/drivers/net/lora/dev.c index 8c01106..69a8b52 100644 --- a/drivers/net/lora/dev.c +++ b/drivers/net/lora/dev.c @@ -84,6 +84,26 @@ void free_loradev(struct net_device *dev) } EXPORT_SYMBOL_GPL(free_loradev); +static void devm_lora_unregister(struct device *dev, void *res) +{ + free_loradev(*(struct net_device **)res); +} + +int devm_lora_register_netdev(struct device *dev, struct net_device *net) +{ + struct net_device **ptr; + + ptr = devres_alloc(devm_lora_unregister, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + *ptr = net; + devres_add(dev, ptr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_lora_register_netdev); + static struct rtnl_link_ops lora_link_ops __read_mostly = { .kind = "lora", .setup = lora_setup, diff --git a/include/linux/lora/dev.h b/include/linux/lora/dev.h index 153f9b2..3f871c6 100644 --- a/include/linux/lora/dev.h +++ b/include/linux/lora/dev.h @@ -32,6 +32,7 @@ static inline int lora_strtoeui(const char *str, lora_eui *val) struct net_device *alloc_loradev(int sizeof_priv); void free_loradev(struct net_device *dev); +int devm_lora_register_netdev(struct device *dev, struct net_device *net); int register_loradev(struct net_device *dev); void unregister_loradev(struct net_device *dev); int open_loradev(struct net_device *dev);