diff mbox series

[net-next,v2] net: ifdefy the wireless pointers in struct net_device

Message ID 20220518181807.2030747-1-kuba@kernel.org (mailing list archive)
State Superseded
Headers show
Series [net-next,v2] net: ifdefy the wireless pointers in struct net_device | expand

Commit Message

Jakub Kicinski May 18, 2022, 6:18 p.m. UTC
Most protocol-specific pointers in struct net_device are under
a respective ifdef. Wireless is the notable exception. Since
there's a sizable number of custom-built kernels for datacenter
workloads which don't build wireless it seems reasonable to
ifdefy those pointers as well.

While at it move IPv4 and IPv6 pointers up, those are special
for obvious reasons.

Acked-by: Stefan Schmidt <stefan@datenfreihafen.org> # ieee802154
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v1: https://lore.kernel.org/all/20220516215638.1787257-1-kuba@kernel.org/
v2: - CONFIG_WIRELESS -> CONFIG_CFG80211 (this needs a bit of
      untangling in sysfs)
    - keep cfg80211_unregister_netdevice in the header

CC: johannes@sipsolutions.net
CC: alex.aring@gmail.com
CC: stefan@datenfreihafen.org
CC: mareklindner@neomailbox.ch
CC: sw@simonwunderlich.de
CC: a@unstable.cc
CC: sven@narfation.org
CC: linux-wireless@vger.kernel.org
CC: linux-wpan@vger.kernel.org
---
 include/linux/netdevice.h       |  8 ++++++--
 include/net/cfg80211.h          |  2 ++
 include/net/cfg802154.h         |  2 ++
 net/batman-adv/hard-interface.c |  2 ++
 net/core/net-sysfs.c            | 21 ++++++++++++++-------
 5 files changed, 26 insertions(+), 9 deletions(-)

Comments

Johannes Berg May 18, 2022, 6:59 p.m. UTC | #1
On Wed, 2022-05-18 at 11:18 -0700, Jakub Kicinski wrote:
> Most protocol-specific pointers in struct net_device are under
> a respective ifdef. Wireless is the notable exception. Since
> there's a sizable number of custom-built kernels for datacenter
> workloads which don't build wireless it seems reasonable to
> ifdefy those pointers as well.
> 
> While at it move IPv4 and IPv6 pointers up, those are special
> for obvious reasons.
> 

Not sure if the "ifdefy" in the subject is intentional, reads a bit odd
to me :) but anyway looks good

Acked-by: Johannes Berg <johannes@sipsolutions.net>


Do you want me to follow up with trying to union the pointer into
ml_priv?

I prefer to union it rather than use ml_priv because we'll not want to
use the getter everywhere when we already know, only on the boundaries.

johannes
Jakub Kicinski May 18, 2022, 7:29 p.m. UTC | #2
On Wed, 18 May 2022 20:59:21 +0200 Johannes Berg wrote:
> Acked-by: Johannes Berg <johannes@sipsolutions.net>

Thanks!

> Do you want me to follow up with trying to union the pointer into
> ml_priv?
> 
> I prefer to union it rather than use ml_priv because we'll not want to
> use the getter everywhere when we already know, only on the boundaries.

Your call. Replacing all the direct references with a helper call could
indeed be onerous.
kernel test robot May 18, 2022, 8:31 p.m. UTC | #3
Hi Jakub,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/net-ifdefy-the-wireless-pointers-in-struct-net_device/20220519-022305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git a3641ca416a3da7cbeae5bcf1fc26ba9797a1438
config: um-i386_defconfig (https://download.01.org/0day-ci/archive/20220519/202205190456.MohbzV8M-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/c6413242ee18dfc005d7ed7ccc4db9cf7883b872
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jakub-Kicinski/net-ifdefy-the-wireless-pointers-in-struct-net_device/20220519-022305
        git checkout c6413242ee18dfc005d7ed7ccc4db9cf7883b872
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=um SUBARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   net/core/net-sysfs.c: In function 'netdev_register_kobject':
>> net/core/net-sysfs.c:2013:30: error: 'wireless_group' undeclared (first use in this function); did you mean 'wireless_dev'?
    2013 |                 *groups++ = &wireless_group;
         |                              ^~~~~~~~~~~~~~
         |                              wireless_dev
   net/core/net-sysfs.c:2013:30: note: each undeclared identifier is reported only once for each function it appears in


vim +2013 net/core/net-sysfs.c

^1da177e4c3f41 Linus Torvalds     2005-04-16  1990  
^1da177e4c3f41 Linus Torvalds     2005-04-16  1991  /* Create sysfs entries for network device. */
6b53dafe23fd1f WANG Cong          2014-07-23  1992  int netdev_register_kobject(struct net_device *ndev)
^1da177e4c3f41 Linus Torvalds     2005-04-16  1993  {
6648c65e7ea72c stephen hemminger  2017-08-18  1994  	struct device *dev = &ndev->dev;
6b53dafe23fd1f WANG Cong          2014-07-23  1995  	const struct attribute_group **groups = ndev->sysfs_groups;
0a9627f2649a02 Tom Herbert        2010-03-16  1996  	int error = 0;
^1da177e4c3f41 Linus Torvalds     2005-04-16  1997  
a1b3f594dc5faa Eric W. Biederman  2010-05-04  1998  	device_initialize(dev);
43cb76d91ee85f Greg Kroah-Hartman 2002-04-09  1999  	dev->class = &net_class;
6b53dafe23fd1f WANG Cong          2014-07-23  2000  	dev->platform_data = ndev;
43cb76d91ee85f Greg Kroah-Hartman 2002-04-09  2001  	dev->groups = groups;
^1da177e4c3f41 Linus Torvalds     2005-04-16  2002  
6b53dafe23fd1f WANG Cong          2014-07-23  2003  	dev_set_name(dev, "%s", ndev->name);
^1da177e4c3f41 Linus Torvalds     2005-04-16  2004  
8b41d1887db718 Eric W. Biederman  2007-09-26  2005  #ifdef CONFIG_SYSFS
0c509a6c9393b2 Eric W. Biederman  2009-10-29  2006  	/* Allow for a device specific group */
0c509a6c9393b2 Eric W. Biederman  2009-10-29  2007  	if (*groups)
0c509a6c9393b2 Eric W. Biederman  2009-10-29  2008  		groups++;
^1da177e4c3f41 Linus Torvalds     2005-04-16  2009  
0c509a6c9393b2 Eric W. Biederman  2009-10-29  2010  	*groups++ = &netstat_group;
38c1a01cf10c6e Johannes Berg      2012-11-16  2011  
c6413242ee18df Jakub Kicinski     2022-05-18  2012  	if (wireless_group_needed(ndev))
38c1a01cf10c6e Johannes Berg      2012-11-16 @2013  		*groups++ = &wireless_group;
8b41d1887db718 Eric W. Biederman  2007-09-26  2014  #endif /* CONFIG_SYSFS */
^1da177e4c3f41 Linus Torvalds     2005-04-16  2015  
0a9627f2649a02 Tom Herbert        2010-03-16  2016  	error = device_add(dev);
0a9627f2649a02 Tom Herbert        2010-03-16  2017  	if (error)
8ed633b9baf9ec Wang Hai           2019-04-12  2018  		return error;
0a9627f2649a02 Tom Herbert        2010-03-16  2019  
6b53dafe23fd1f WANG Cong          2014-07-23  2020  	error = register_queue_kobjects(ndev);
8ed633b9baf9ec Wang Hai           2019-04-12  2021  	if (error) {
8ed633b9baf9ec Wang Hai           2019-04-12  2022  		device_del(dev);
8ed633b9baf9ec Wang Hai           2019-04-12  2023  		return error;
8ed633b9baf9ec Wang Hai           2019-04-12  2024  	}
0a9627f2649a02 Tom Herbert        2010-03-16  2025  
9802c8e22f6efd Ming Lei           2013-02-22  2026  	pm_runtime_set_memalloc_noio(dev, true);
9802c8e22f6efd Ming Lei           2013-02-22  2027  
0a9627f2649a02 Tom Herbert        2010-03-16  2028  	return error;
^1da177e4c3f41 Linus Torvalds     2005-04-16  2029  }
^1da177e4c3f41 Linus Torvalds     2005-04-16  2030
Sven Eckelmann May 19, 2022, 6:53 a.m. UTC | #4
On Wednesday, 18 May 2022 20:18:07 CEST Jakub Kicinski wrote:
> diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
> index 83fb51b6e299..b8f8da7ee3de 100644
> --- a/net/batman-adv/hard-interface.c
> +++ b/net/batman-adv/hard-interface.c
> @@ -307,9 +307,11 @@ static bool batadv_is_cfg80211_netdev(struct net_device *net_device)
>         if (!net_device)
>                 return false;
>  
> +#if IS_ENABLED(CONFIG_CFG80211)
>         /* cfg80211 drivers have to set ieee80211_ptr */
>         if (net_device->ieee80211_ptr)
>                 return true;
> +#endif
>  
>         return false;
>  }

Acked-by: Sven Eckelmann <sven@narfation.org>
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index cbaf312e365b..3ff4a654f1f0 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2119,6 +2119,8 @@  struct net_device {
 
 	/* Protocol-specific pointers */
 
+	struct in_device __rcu	*ip_ptr;
+	struct inet6_dev __rcu	*ip6_ptr;
 #if IS_ENABLED(CONFIG_VLAN_8021Q)
 	struct vlan_info __rcu	*vlan_info;
 #endif
@@ -2131,16 +2133,18 @@  struct net_device {
 #if IS_ENABLED(CONFIG_ATALK)
 	void 			*atalk_ptr;
 #endif
-	struct in_device __rcu	*ip_ptr;
 #if IS_ENABLED(CONFIG_DECNET)
 	struct dn_dev __rcu     *dn_ptr;
 #endif
-	struct inet6_dev __rcu	*ip6_ptr;
 #if IS_ENABLED(CONFIG_AX25)
 	void			*ax25_ptr;
 #endif
+#if IS_ENABLED(CONFIG_CFG80211)
 	struct wireless_dev	*ieee80211_ptr;
+#endif
+#if IS_ENABLED(CONFIG_IEEE802154) || IS_ENABLED(CONFIG_6LOWPAN)
 	struct wpan_dev		*ieee802154_ptr;
+#endif
 #if IS_ENABLED(CONFIG_MPLS_ROUTING)
 	struct mpls_dev __rcu	*mpls_ptr;
 #endif
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 68713388b617..d523b1e49d1e 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -8006,7 +8006,9 @@  int cfg80211_register_netdevice(struct net_device *dev);
  */
 static inline void cfg80211_unregister_netdevice(struct net_device *dev)
 {
+#if IS_ENABLED(CONFIG_CFG80211)
 	cfg80211_unregister_wdev(dev->ieee80211_ptr);
+#endif
 }
 
 /**
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 85f9e8417688..d8d8719315fd 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -373,6 +373,7 @@  struct wpan_dev {
 
 #define to_phy(_dev)	container_of(_dev, struct wpan_phy, dev)
 
+#if IS_ENABLED(CONFIG_IEEE802154) || IS_ENABLED(CONFIG_6LOWPAN)
 static inline int
 wpan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
 		     const struct ieee802154_addr *daddr,
@@ -383,6 +384,7 @@  wpan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
 
 	return wpan_dev->header_ops->create(skb, dev, daddr, saddr, len);
 }
+#endif
 
 struct wpan_phy *
 wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 83fb51b6e299..b8f8da7ee3de 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -307,9 +307,11 @@  static bool batadv_is_cfg80211_netdev(struct net_device *net_device)
 	if (!net_device)
 		return false;
 
+#if IS_ENABLED(CONFIG_CFG80211)
 	/* cfg80211 drivers have to set ieee80211_ptr */
 	if (net_device->ieee80211_ptr)
 		return true;
+#endif
 
 	return false;
 }
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 4980c3a50475..99d737b1c720 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -757,6 +757,19 @@  static const struct attribute_group wireless_group = {
 };
 #endif
 
+static bool wireless_group_needed(struct net_device *ndev)
+{
+#if IS_ENABLED(CONFIG_CFG80211)
+	if (ndev->ieee80211_ptr)
+		return true;
+#endif
+#if IS_ENABLED(CONFIG_WIRELESS_EXT)
+	if (ndev->wireless_handlers)
+		return true;
+#endif
+	return false;
+}
+
 #else /* CONFIG_SYSFS */
 #define net_class_groups	NULL
 #endif /* CONFIG_SYSFS */
@@ -1996,14 +2009,8 @@  int netdev_register_kobject(struct net_device *ndev)
 
 	*groups++ = &netstat_group;
 
-#if IS_ENABLED(CONFIG_WIRELESS_EXT) || IS_ENABLED(CONFIG_CFG80211)
-	if (ndev->ieee80211_ptr)
-		*groups++ = &wireless_group;
-#if IS_ENABLED(CONFIG_WIRELESS_EXT)
-	else if (ndev->wireless_handlers)
+	if (wireless_group_needed(ndev))
 		*groups++ = &wireless_group;
-#endif
-#endif
 #endif /* CONFIG_SYSFS */
 
 	error = device_add(dev);