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-next>] [day] [month] [year] [list]
Date: Tue, 2 Jan 2024 15:59:49 +0530
From: Bhavya Kapoor <b-kapoor@...com>
To: <linux-kernel@...r.kernel.org>, <netdev@...r.kernel.org>
CC: <linux-can@...r.kernel.org>, <b-kapoor@...com>,
        <mailhol.vincent@...adoo.fr>, <rcsekar@...sung.com>,
        <pabeni@...hat.com>, <kuba@...nel.org>, <edumazet@...gle.com>,
        <davem@...emloft.net>, <mkl@...gutronix.de>, <wg@...ndegger.com>,
        <vigneshr@...com>, <u-kumar1@...com>
Subject: [PATCH] net: can: Add support for aliases in CAN

When multiple CAN's are present, then names that are getting assigned
changes after every boot even after providing alias in the device tree.
Thus, Add support for implementing CAN aliasing so that names or
alias for CAN will now be provided from device tree.

Signed-off-by: Bhavya Kapoor <b-kapoor@...com>
---
 drivers/net/can/dev/dev.c     | 15 ++++++++++++---
 drivers/net/can/m_can/m_can.c |  2 +-
 include/linux/can/dev.h       |  8 +++++---
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c
index 3a3be5cdfc1f..ed483c23ec79 100644
--- a/drivers/net/can/dev/dev.c
+++ b/drivers/net/can/dev/dev.c
@@ -247,12 +247,14 @@ void can_setup(struct net_device *dev)
 
 /* Allocate and setup space for the CAN network device */
 struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
-				    unsigned int txqs, unsigned int rxqs)
+					unsigned int txqs, unsigned int rxqs,
+					struct device *candev)
 {
 	struct can_ml_priv *can_ml;
 	struct net_device *dev;
 	struct can_priv *priv;
-	int size;
+	int size, aliasid;
+	char devname[6] = "can%d";
 
 	/* We put the driver's priv, the CAN mid layer priv and the
 	 * echo skb into the netdevice's priv. The memory layout for
@@ -273,7 +275,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
 		size = ALIGN(size, sizeof(struct sk_buff *)) +
 			echo_skb_max * sizeof(struct sk_buff *);
 
-	dev = alloc_netdev_mqs(size, "can%d", NET_NAME_UNKNOWN, can_setup,
+	if (candev) {
+		aliasid = of_alias_get_id(candev->of_node, "can");
+		if (aliasid >= 0)
+			snprintf(devname, sizeof(devname), "%s%d", "can", aliasid);
+	}
+	dev_dbg(candev, "Name of CAN assigned is : %s\n", devname);
+
+	dev = alloc_netdev_mqs(size, devname, NET_NAME_UNKNOWN, can_setup,
 			       txqs, rxqs);
 	if (!dev)
 		return NULL;
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 16ecc11c7f62..c91a5c7b3ae5 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -2029,7 +2029,7 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev,
 	tx_fifo_size = mram_config_vals[7];
 
 	/* allocate the m_can device */
-	net_dev = alloc_candev(sizeof_priv, tx_fifo_size);
+	net_dev = alloc_candev_with_dev(sizeof_priv, tx_fifo_size, dev);
 	if (!net_dev) {
 		dev_err(dev, "Failed to allocate CAN device");
 		goto out;
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 1b92aed49363..b59142c16e59 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -171,11 +171,13 @@ static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *s
 void can_setup(struct net_device *dev);
 
 struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
-				    unsigned int txqs, unsigned int rxqs);
+					unsigned int txqs, unsigned int rxqs, struct device *dev);
 #define alloc_candev(sizeof_priv, echo_skb_max) \
-	alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1)
+	alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1, NULL)
+#define alloc_candev_with_dev(sizeof_priv, echo_skb_max, dev) \
+	alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1, dev)
 #define alloc_candev_mq(sizeof_priv, echo_skb_max, count) \
-	alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count)
+	alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count, NULL)
 void free_candev(struct net_device *dev);
 
 /* a candev safe wrapper around netdev_priv */
-- 
2.40.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ