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.
Showing the changes to include (1 of 2 files). Show all
Unified · Split
| @@ -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 | ||
| 1729 | struct devlink *__must_check devlink_try_get(struct devlink *devlink); | ||
| 1730 | void devlink_put(struct devlink *devlink); | ||
| 1731 | |||
| 1729 | void devlink_compat_running_version(struct net_device *dev, | 1732 | void devlink_compat_running_version(struct net_device *dev, |
| 1730 | char *buf, size_t len); | 1733 | char *buf, size_t len); |
| 1731 | int devlink_compat_flash_update(struct net_device *dev, const char *file_name); | 1734 | int 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 | #else | 1740 | #else |
| 1738 | 1741 | ||
| 1742 | static inline struct devlink *devlink_try_get(struct devlink *devlink) | ||
| 1743 | { | ||
| 1744 | return NULL; | ||
| 1745 | } | ||
| 1746 | |||
| 1747 | static inline void devlink_put(struct devlink *devlink) | ||
| 1748 | { | ||
| 1749 | } | ||
| 1750 | |||
| 1739 | static inline void | 1751 | static inline void |
| 1740 | devlink_compat_running_version(struct net_device *dev, char *buf, size_t len) | 1752 | devlink_compat_running_version(struct net_device *dev, char *buf, size_t len) |
| 1741 | { | 1753 | { |