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]
Message-Id: <20240519181039.23147-1-egyszeregy@freemail.hu>
Date: Sun, 19 May 2024 20:10:39 +0200
From: egyszeregy@...email.hu
To: broonie@...nel.org,
	linux-spi@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: Benjamin Szőke <egyszeregy@...email.hu>
Subject: [PATCH] spidev: Introduce "linux,spidev-name" property for device tree of spidev.

From: Benjamin Szőke <egyszeregy@...email.hu>

Optionally, spidev may have a "linux,spidev-name" property.
This is a string which is defining a custom suffix name for spi device in
/dev/spidev-<name> format. It helps to improve software portability between
various SoCs and reduce complexities of hardware related codes in SWs.

Signed-off-by: Benjamin Szőke <egyszeregy@...email.hu>
---
 drivers/spi/spidev.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 95fb5f1c91c1..e0071522fc6d 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -767,6 +767,8 @@ MODULE_DEVICE_TABLE(acpi, spidev_acpi_ids);
 
 static int spidev_probe(struct spi_device *spi)
 {
+	int ret;
+	const char *name;
 	int (*match)(struct device *dev);
 	struct spidev_data	*spidev;
 	int			status;
@@ -800,9 +802,20 @@ static int spidev_probe(struct spi_device *spi)
 		struct device *dev;
 
 		spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
-		dev = device_create(&spidev_class, &spi->dev, spidev->devt,
-				    spidev, "spidev%d.%d",
-				    spi->controller->bus_num, spi_get_chipselect(spi, 0));
+
+		/*
+		 * If "linux,spidev-name" is specified in device tree, use /dev/spidev-<name>
+		 * in Linux userspace, otherwise use /dev/spidev<bus_num>.<cs_num>.
+		 */
+		ret = device_property_read_string(&spi->dev, "linux,spidev-name", &name);
+		if (ret < 0)
+			dev = device_create(spidev_class, &spi->dev, spidev->devt,
+					    spidev, "spidev%d.%d",
+					    spi->controller->bus_num, spi_get_chipselect(spi, 0));
+		else
+			dev = device_create(spidev_class, &spi->dev, spidev->devt,
+					    spidev, "spidev-%s", name);
+
 		status = PTR_ERR_OR_ZERO(dev);
 	} else {
 		dev_dbg(&spi->dev, "no minor number available!\n");
-- 
2.39.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ