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:   Wed, 21 Jul 2021 14:59:25 +0200
From:   Andre Naujoks <nautsch2@...il.com>
To:     Wolfgang Grandegger <wg@...ndegger.com>,
        Marc Kleine-Budde <mkl@...gutronix.de>,
        "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Stephane Grosjean <s.grosjean@...k-system.com>,
        Vincent Mailhol <mailhol.vincent@...adoo.fr>,
        "Gustavo A. R. Silva" <gustavoars@...nel.org>,
        Pavel Skripkin <paskripkin@...il.com>,
        Colin Ian King <colin.king@...onical.com>,
        Andre Naujoks <nautsch2@...il.com>, linux-can@...r.kernel.org,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v2] Expose Peak USB device id in sysfs via phys_port_name.

The Peak USB CAN adapters can be assigned a device id via the Peak
provided tools (pcan-settings). This id can currently not be set by the
upstream kernel drivers, but some devices expose this id already.

The id can be used for consistent naming of CAN interfaces regardless of
order of attachment or recognition on the system. The classical CAN Peak
USB adapters expose this id via bcdDevice (combined with another value)
on USB-level in the sysfs tree and this value is then available in
ID_REVISION from udev. This is not a feasible approach, when a single
USB device offers more than one CAN-interface, like e.g. the PCAN-USB
Pro FD devices.

This patch exposes those ids via the, up to now unused, netdevice sysfs
attribute phys_port_name as a simple decimal ASCII representation of the
id. phys_port_id was not used, since the default print functions from
net/core/net-sysfs.c output a hex-encoded binary value, which is
overkill for a one-byte device id, like this one.

Signed-off-by: Andre Naujoks <nautsch2@...il.com>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index e8f43ed90b72..f6cbb01a58cc 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -408,6 +408,21 @@ static netdev_tx_t peak_usb_ndo_start_xmit(struct sk_buff *skb,
 	return NETDEV_TX_OK;
 }
 
+static int peak_usb_ndo_get_phys_port_name(struct net_device *netdev,
+					   char *name, size_t len)
+{
+	const struct peak_usb_device *dev = netdev_priv(netdev);
+	int err;
+
+	err = snprintf(name, len, "%u", dev->device_number);
+
+	if (err >= len || err <= 0) {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 /*
  * start the CAN interface.
  * Rx and Tx urbs are allocated here. Rx urbs are submitted here.
@@ -769,6 +784,7 @@ static const struct net_device_ops peak_usb_netdev_ops = {
 	.ndo_stop = peak_usb_ndo_stop,
 	.ndo_start_xmit = peak_usb_ndo_start_xmit,
 	.ndo_change_mtu = can_change_mtu,
+	.ndo_get_phys_port_name = peak_usb_ndo_get_phys_port_name,
 };
 
 /*
-- 
2.32.0

Powered by blists - more mailing lists