lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 12 Jan 2015 13:57:40 -0800
From:	Florian Fainelli <f.fainelli@...il.com>
To:	netdev@...r.kernel.org
Cc:	davem@...emloft.net, buytenh@...tstofly.org,
	Florian Fainelli <f.fainelli@...il.com>
Subject: [PATCH net-next 2/8] net: dsa: make module builds work

Building any DSA driver as a module will work from a compilation/linking
perspective, but the resulting modules produced are not functional.

Any DSA driver references register_switch_driver and
unregister_switch_driver which are provided by net/dsa/dsa.c, so loading
any of these modules prior to dsa_core.ko being loaded will faill.

Unfortunately, loading dsa_core.ko will make us call dsa_switch_probe()
which will find no DSA switch driver and return an error so we are stuck
there because there is no switch driver available. So this is getting us
nowhere.

This patch introduces a separate module, named dsa_lib which contains
register_switch_driver, unregister_switch_driver and dsa_switch_probe
(to avoid exposing the list and mutex used for walking switch drivers),
such that the following can be done:

- load dsa_lib
- load the dsa switch driver, e.g: mv88e6060, bcm_sf2
- load the dsa_core module

Signed-off-by: Florian Fainelli <f.fainelli@...il.com>
---
 net/dsa/Makefile   |  2 ++
 net/dsa/dsa.c      | 49 ---------------------------------------
 net/dsa/dsa_lib.c  | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/dsa/dsa_priv.h |  4 ++++
 4 files changed, 74 insertions(+), 49 deletions(-)
 create mode 100644 net/dsa/dsa_lib.c

diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index da06ed1df620..17827194754d 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -2,6 +2,8 @@
 obj-$(CONFIG_NET_DSA) += dsa_core.o
 dsa_core-y += dsa.o slave.o
 
+obj-$(CONFIG_NET_DSA) += dsa_lib.o
+
 # tagging formats
 dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
 dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 37317149f918..de77c83cfd9a 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -26,55 +26,6 @@
 char dsa_driver_version[] = "0.1";
 
 
-/* switch driver registration ***********************************************/
-static DEFINE_MUTEX(dsa_switch_drivers_mutex);
-static LIST_HEAD(dsa_switch_drivers);
-
-void register_switch_driver(struct dsa_switch_driver *drv)
-{
-	mutex_lock(&dsa_switch_drivers_mutex);
-	list_add_tail(&drv->list, &dsa_switch_drivers);
-	mutex_unlock(&dsa_switch_drivers_mutex);
-}
-EXPORT_SYMBOL_GPL(register_switch_driver);
-
-void unregister_switch_driver(struct dsa_switch_driver *drv)
-{
-	mutex_lock(&dsa_switch_drivers_mutex);
-	list_del_init(&drv->list);
-	mutex_unlock(&dsa_switch_drivers_mutex);
-}
-EXPORT_SYMBOL_GPL(unregister_switch_driver);
-
-static struct dsa_switch_driver *
-dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name)
-{
-	struct dsa_switch_driver *ret;
-	struct list_head *list;
-	char *name;
-
-	ret = NULL;
-	name = NULL;
-
-	mutex_lock(&dsa_switch_drivers_mutex);
-	list_for_each(list, &dsa_switch_drivers) {
-		struct dsa_switch_driver *drv;
-
-		drv = list_entry(list, struct dsa_switch_driver, list);
-
-		name = drv->probe(host_dev, sw_addr);
-		if (name != NULL) {
-			ret = drv;
-			break;
-		}
-	}
-	mutex_unlock(&dsa_switch_drivers_mutex);
-
-	*_name = name;
-
-	return ret;
-}
-
 /* hwmon support ************************************************************/
 
 #ifdef CONFIG_NET_DSA_HWMON
diff --git a/net/dsa/dsa_lib.c b/net/dsa/dsa_lib.c
new file mode 100644
index 000000000000..2c496203c797
--- /dev/null
+++ b/net/dsa/dsa_lib.c
@@ -0,0 +1,68 @@
+/*
+ * net/dsa/dsa_lib.c - Hardware switch handling
+ * Copyright (c) 2008-2009 Marvell Semiconductor
+ * Copyright (c) 2015 Florian Fainelli <florian@...nwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <net/dsa.h>
+#include "dsa_priv.h"
+
+/* switch driver registration ***********************************************/
+static DEFINE_MUTEX(dsa_switch_drivers_mutex);
+static LIST_HEAD(dsa_switch_drivers);
+
+void register_switch_driver(struct dsa_switch_driver *drv)
+{
+	mutex_lock(&dsa_switch_drivers_mutex);
+	list_add_tail(&drv->list, &dsa_switch_drivers);
+	mutex_unlock(&dsa_switch_drivers_mutex);
+}
+EXPORT_SYMBOL_GPL(register_switch_driver);
+
+void unregister_switch_driver(struct dsa_switch_driver *drv)
+{
+	mutex_lock(&dsa_switch_drivers_mutex);
+	list_del_init(&drv->list);
+	mutex_unlock(&dsa_switch_drivers_mutex);
+}
+EXPORT_SYMBOL_GPL(unregister_switch_driver);
+
+struct dsa_switch_driver *
+dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name)
+{
+	struct dsa_switch_driver *ret;
+	struct list_head *list;
+	char *name;
+
+	ret = NULL;
+	name = NULL;
+
+	mutex_lock(&dsa_switch_drivers_mutex);
+	list_for_each(list, &dsa_switch_drivers) {
+		struct dsa_switch_driver *drv;
+
+		drv = list_entry(list, struct dsa_switch_driver, list);
+
+		name = drv->probe(host_dev, sw_addr);
+		if (name != NULL) {
+			ret = drv;
+			break;
+		}
+	}
+	mutex_unlock(&dsa_switch_drivers_mutex);
+
+	*_name = name;
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dsa_switch_probe);
+
+MODULE_LICENSE("GPL");
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index e560ae53996c..1397b2894c1f 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -51,6 +51,10 @@ struct dsa_slave_priv {
 /* dsa.c */
 extern char dsa_driver_version[];
 
+/* dsa_lib.c */
+struct dsa_switch_driver *
+dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name);
+
 /* slave.c */
 extern const struct dsa_device_ops notag_netdev_ops;
 void dsa_slave_mii_bus_init(struct dsa_switch *ds);
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ