backport: handle change in netdevice destructor usage
PATCH v2 1/1 backport: handle change in netdevice destructor usage
This patch deals with changes made in struct net_device by commit cf124db566e6 ("net: Fix inconsistent teardown and release of private netdev state.").
---
Hi Johannes,
It took a while for me to be happy with this version. More so because I found that brcmfmac has a double-free bug if register_netdevice() fails so I needed to solve that puzzle. Below is the changelog.
Regards,
Arend
V2:
- changed netdev_set_priv_destructor() to macro.
- revised semantic patch covering drivers only needing free_netdev().
- used some tricks suggested by Julia in semantic patch.
- added more version checks against 4.13.
--- backport/backport-include/linux/netdevice.h | 9 ++++ patches/0079-netdev-destructor.cocci | 84 +++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 patches/0079-netdev-destructor.cocci
backport/backport-include/linux/netdevice.h +9 -0
@@ -320,4 +320,13 @@ static inline void netif_trans_update(struct net_device *dev) }#endif +#if LINUX_VERSION_IS_LESS (4 ,13 ,0 ) +#define netdev_set_priv_destructor (_dev, _destructor) \ + (_dev)->destructor = __ ## _destructor +#else + (_dev)->needs_free_netdev = true; +if (_destructor != free_netdev) + (_dev)->priv_destructor = _destructor; +#endif +#endif /* __BACKPORT_NETDEVICE_H */
patches/0079-netdev-destructor.cocci new file +84 -0
84 lines not on this page · raw message
Signature · 4 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe backports" in
Quoted 40 lines · Arend van Spriel
This patch deals with changes made in struct
net_deviceby commitcf124db566e6("net: Fix inconsistent teardown and release of private netdev state.").Signed-off-by Arend van Spriel <[email protected]>---
Hi Johannes,It took a while for me to be happy with this version. More so because I
found that brcmfmac has a double-free bug ifregister_netdevice()fails
so I needed to solve that puzzle. Below is the changelog.Regards,
ArendV2:
- changednetdev_set_priv_destructor()to macro.
- revised semantic patch covering drivers only needingfree_netdev().
- used some tricks suggested by Julia in semantic patch.
- added more version checks against 4.13.
---
backport/backport-include/linux/netdevice.h | 9 ++++ patches/0079-netdev-destructor.cocci | 84
+++++++++++++++++++++++++++++2 files changed, 93 insertions(+)create mode 100644
patches/0079-netdev-destructor.coccibackport/backport-include/linux/netdevice.h +0
-0@@ -320,4 +320,13 @@ static inline void netif_trans_update(struct net_device *dev) } #endif
backport/backport-include/linux/netdevice.h static inline void netif_trans_update(struct net_device *dev) · line 326
Quoted 4 lines
backport/backport-include/linux/netdevice.h +4
-0+#if LINUX_VERSION_IS_LESS (4 ,13 ,0 ) +#define netdev_set_priv_destructor (_dev, _destructor) \ + (_dev)->destructor = __ ## _destructor +#else
Won't this cause annoying warnings, that __##_destructor is an unused function, when compiling for higher kernels?
johannes
--
To unsubscribe from this list: send the line "unsubscribe backports" in
Perhaps that can be fixed as such:
patches/0079-netdev-destructor.cocci line 17
Quoted 3 lines
+@r2 depends on r1@
patches/0079-netdev-destructor.cocci new file +2
-0+identifier r1.D, r1.C; +fresh identifier E = "__" ## D;
attribute __maybe_unused;
Quoted 4 lines
+@@
+
++#ifLINUX_VERSION_IS_LESS(4,13,0)
++static voidE(struct net_device *ndev)
__maybe_unused
johannes
--
To unsubscribe from this list: send the line "unsubscribe backports" in
Quoted 8 lines · Johannes Berg
Perhaps that can be fixed as such:
patches/0079-netdev-destructor.cocci line 17
Quoted 3 lines
+@r2 depends on r1@
patches/0079-netdev-destructor.cocci new file +2
-0+identifier r1.D, r1.C; +fresh identifier E = "__" ## D;attribute
__maybe_unused;
Quoted 6 lines
Quoted 4 lines
+@@
+
++#ifLINUX_VERSION_IS_LESS(4,13,0)
++static voidE(struct net_device *ndev)
__maybe_unused
Ok. I clearly made a mistake in #else of the macro:
+#if LINUX_VERSION_IS_LESS(4,13,0)
+#define netdev_set_priv_destructor(_dev, _destructor) \
+ (_dev)->destructor = __ ## _destructor
+#else
+ (_dev)->needs_free_netdev = true;
+ if (_destructor != free_netdev)
+ (_dev)->priv_destructor = _destructor;
+#endif
So I will fix that, but I do not quite understand your comment. Expanding the macro in spatch output for net/mac80211/iface.c:
+#if LINUX_VERSION_IS_LESS(4,13,0)
+static void __ieee80211_if_free(struct net_device *ndev) +{
+ ieee80211_if_free(ndev);
+ free_netdev(ndev);
+}
+#endif
+
static void ieee80211_if_setup(struct net_device *dev) {
ether_setup(dev);
dev->priv_flags &= ~IFF_TX_SKB_SHARING; dev->netdev_ops = &ieee80211_dataif_ops;
- dev->needs_free_netdev = true;
- dev->priv_destructor = ieee80211_if_free;
+#if LINUX_VERSION_IS_LESS(4,13,0)
+ dev->destructor = __ieee80211_if_free
+#else
+ dev->needs_free_netdev = true;
+ if (ieee80211_if_free != free_netdev)
+ dev->priv_destructor = ieee80211_if_free;
+#endif
}
So __ieee80211_if_free is only defined for lower kernels and it is only used for lower kernels. Adding the __ieee80211_if_free depends on r1 in the semantic patch.
So I will send a V3 fixing the macro in netdevice.h, but I don't think we need the maybe_unused attribute.
Regards,
Arend
--
To unsubscribe from this list: send the line "unsubscribe backports" in
Quoted 6 lines · Arend van Spriel
Quoted 3 lines
Quoted 3 lines
++#if
LINUX_VERSION_IS_LESS(4,13,0)
++static voidE(struct net_device *ndev)So I will send a V3 fixing the macro in
netdevice.h, but I don't think we need themaybe_unusedattribute.
Ummm, yeah, I totally missed the #if above :)
Maybe it's time to get some sleep...
johannes
--
To unsubscribe from this list: send the line "unsubscribe backports" in
Quoted 11 lines · Johannes Berg
Quoted 6 lines · Arend van Spriel
Quoted 3 lines
Quoted 3 lines
++#if
LINUX_VERSION_IS_LESS(4,13,0)
++static voidE(struct net_device *ndev)So I will send a V3 fixing the macro in
netdevice.h, but I don't think we need themaybe_unusedattribute.Ummm, yeah, I totally missed the #if above :)
Maybe it's time to get some sleep...
Dito. That V3 will have to wait until tomorrow.
Gr. AvS
--
To unsubscribe from this list: send the line "unsubscribe backports" in