History

devlink: expose get/put functions

Allow those who hold implicit reference on a devlink instance to try to take a full ref on it. This will be used from netdev code which has an implicit ref because of driver call ordering. Note that after recent changes devlink_unregister() may happen before netdev unregister, but devlink_free() should still happen after, so we are safe to try, but we can't just refcount_inc() and assume it's not zero.

Jakub Kicinski committed 5 years ago

Commit 46db1b71 parent 095cfcf2 files · +17 −3Browse files

Unified · Split

2 files
  1. include/net/devlink.h +12 −0
  2. net/core/devlink.c +5 −3
include/net/devlink.h+12−0
@@ -1726,6 +1726,9 @@ devlink_trap_policers_unregister(struct devlink *devlink, · 1725 unmodified lines
1726 1726
1727#if IS_ENABLED(CONFIG_NET_DEVLINK)1727#if IS_ENABLED(CONFIG_NET_DEVLINK)
1728 1728
1729struct devlink *__must_check devlink_try_get(struct devlink *devlink);
1730void devlink_put(struct devlink *devlink);
1731
1729void devlink_compat_running_version(struct net_device *dev,1732void devlink_compat_running_version(struct net_device *dev,
1730 char *buf, size_t len);1733 char *buf, size_t len);
1731int devlink_compat_flash_update(struct net_device *dev, const char *file_name);1734int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
@@ -1736,6 +1739,15 @@ int devlink_compat_switch_id_get(struct net_device *dev, · 4 unmodified lines
1736 1739
1737#else1740#else
1738 1741
1742static inline struct devlink *devlink_try_get(struct devlink *devlink)
1743{
1744 return NULL;
1745}
1746
1747static inline void devlink_put(struct devlink *devlink)
1748{
1749}
1750
1739static inline void1751static inline void
1740devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)1752devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1741{1753{
net/core/devlink.c+5−3
@@ -182,15 +182,17 @@ struct net *devlink_net(const struct devlink *devlink) · 181 unmodified lines
182}182}
183EXPORT_SYMBOL_GPL(devlink_net);183EXPORT_SYMBOL_GPL(devlink_net);
184 184
185static void devlink_put(struct devlink *devlink)185void devlink_put(struct devlink *devlink)
186{186{
187 if (refcount_dec_and_test(&devlink->refcount))187 if (refcount_dec_and_test(&devlink->refcount))
188 complete(&devlink->comp);188 complete(&devlink->comp);
189}189}
190 190
191static bool __must_check devlink_try_get(struct devlink *devlink)191struct devlink *__must_check devlink_try_get(struct devlink *devlink)
192{192{
193 return refcount_inc_not_zero(&devlink->refcount);193 if (refcount_inc_not_zero(&devlink->refcount))
194 return devlink;
195 return NULL;
194}196}
195 197
196static struct devlink *devlink_get_from_attrs(struct net *net,198static struct devlink *devlink_get_from_attrs(struct net *net,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t