Skip to contentSkip to conversation

staging: r8188eu: replace rtw_netdev_priv define with inline function

PATCH Superseded Ivan Safonov 2 participants 2 messages Aug 1, 2020 Staging

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: r8188eu: replace rtw_netdev_priv define with inline function

The function guarantees type checking of arguments and return value.

Result of rtw_netdev_priv macro can be assigned to pointer with incompatible type without warning. The function allow compiler to perform this check.

---
Changes in v2:
- add blank line after function definition;
- improve commit message.

---
 drivers/staging/rtl8188eu/include/osdep_service.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/staging/rtl8188eu/include/osdep_service.h +5 -2
index 31d897f1d21f..6ca79b5fb638 100644
@@ -71,8 +71,11 @@ struct rtw_netdev_priv_indicator {
 };
 struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv);
 
-#define rtw_netdev_priv(netdev)					\
-	(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
+static inline struct adapter *rtw_netdev_priv(struct net_device *dev)
+{
+	return (((struct rtw_netdev_priv_indicator *)netdev_priv(dev))->priv);
+}
+
 void rtw_free_netdev(struct net_device *netdev);
 
 #define FUNC_NDEV_FMT "%s(%s)"
Signature · 1 line
2.26.2
#1 lore raw
Quoted 5 lines · Ivan Safonov

The function guarantees type checking of arguments and return value.

Result of rtw_netdev_priv macro can be assigned to pointer with incompatible type without warning. The function allow compiler to perform this check.

[]

drivers/staging/rtl8188eu/include/osdep_service.h

Quoted 1 line
drivers/staging/rtl8188eu/include/osdep_service.h +0 -0

[]

drivers/staging/rtl8188eu/include/osdep_service.h struct rtw_netdev_priv_indicator { · line 77

Quoted 10 lines
drivers/staging/rtl8188eu/include/osdep_service.h +4 -2
@@ -71,8 +71,11 @@ struct rtw_netdev_priv_indicator {
 };
 struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv);
 
-#define rtw_netdev_priv(netdev)					\
-	(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
+static inline struct adapter *rtw_netdev_priv(struct net_device *dev)
+{
+	return (((struct rtw_netdev_priv_indicator *)netdev_priv(dev))->priv);
+}

To be similar to existing uses, this variable name should be netdev not dev. There are also unnecessary parentheses.

drivers/staging/rtl8188eu/include/osdep_service.h struct rtw_netdev_priv_indicator { · line 79

Quoted 1 line
drivers/staging/rtl8188eu/include/osdep_service.h +0 -0
 void rtw_free_netdev(struct net_device *netdev);

Better to use netdev like this one.

---
static inline struct adapter *rtw_netdev_priv(struct net_device *netdev)

{
	return ((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv;
}