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]
Message-ID: <20240315184908.500352-3-ayushdevel1325@gmail.com>
Date: Sat, 16 Mar 2024 00:19:00 +0530
From: Ayush Singh <ayushdevel1325@...il.com>
To: linux-kernel@...r.kernel.org
Cc: Ayush Singh <ayushdevel1325@...il.com>,
	jkridner@...gleboard.org,
	robertcnelson@...gleboard.org,
	Vaishnav M A <vaishnav@...gleboard.org>,
	Rob Herring <robh@...nel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
	Conor Dooley <conor+dt@...nel.org>,
	Nishanth Menon <nm@...com>,
	Vignesh Raghavendra <vigneshr@...com>,
	Tero Kristo <kristo@...nel.org>,
	Derek Kiernan <derek.kiernan@....com>,
	Dragan Cvetic <dragan.cvetic@....com>,
	Arnd Bergmann <arnd@...db.de>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Liam Girdwood <lgirdwood@...il.com>,
	Mark Brown <broonie@...nel.org>,
	Jiri Slaby <jirislaby@...nel.org>,
	Johan Hovold <johan@...nel.org>,
	Alex Elder <elder@...nel.org>,
	devicetree@...r.kernel.org,
	linux-arm-kernel@...ts.infradead.org,
	linux-spi@...r.kernel.org,
	linux-serial@...r.kernel.org,
	greybus-dev@...ts.linaro.org
Subject: [PATCH v3 2/8] w1: Add w1_find_master_device

Add helper to find w1_master from w1_bus_master, which is present in
drvdata of platform device.

Signed-off-by: Vaishnav M A <vaishnav@...gleboard.org>
Signed-off-by: Ayush Singh <ayushdevel1325@...il.com>
---
 drivers/w1/w1.c     |  6 +++---
 drivers/w1/w1_int.c | 27 +++++++++++++++++++++++++++
 include/linux/w1.h  |  1 +
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index afb1cc4606c5..ce8a3f93f2ef 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -673,9 +673,9 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
 	sl->dev.of_node = of_find_matching_node(sl->master->dev.of_node,
 						sl->family->of_match_table);
 
-	dev_set_name(&sl->dev, "%02x-%012llx",
-		 (unsigned int) sl->reg_num.family,
-		 (unsigned long long) sl->reg_num.id);
+	dev_set_name(&sl->dev, "%s-%02x-%012llx", sl->master->name,
+		     (unsigned int)sl->reg_num.family,
+		     (unsigned long long)sl->reg_num.id);
 	snprintf(&sl->name[0], sizeof(sl->name),
 		 "%02x-%012llx",
 		 (unsigned int) sl->reg_num.family,
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 3a71c5eb2f83..2bfef8e67687 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -242,3 +242,30 @@ void w1_remove_master_device(struct w1_bus_master *bm)
 	__w1_remove_master_device(found);
 }
 EXPORT_SYMBOL(w1_remove_master_device);
+
+/**
+ * w1_find_master_device() - find a master device
+ * @bm:	master bus device to search
+ */
+struct w1_master *w1_find_master_device(struct w1_bus_master *bm)
+{
+	struct w1_master *dev, *found = NULL;
+
+	list_for_each_entry(dev, &w1_masters, w1_master_entry) {
+		if (!dev->initialized)
+			continue;
+
+		if (dev->bus_master->data == bm->data) {
+			found = dev;
+			break;
+		}
+	}
+
+	if (!found) {
+		pr_err("device doesn't exist.\n");
+		return ERR_PTR(-ENODEV);
+	}
+
+	return found;
+}
+EXPORT_SYMBOL(w1_find_master_device);
diff --git a/include/linux/w1.h b/include/linux/w1.h
index 9a2a0ef39018..24269d0dd5d1 100644
--- a/include/linux/w1.h
+++ b/include/linux/w1.h
@@ -242,6 +242,7 @@ struct w1_master {
 
 int w1_add_master_device(struct w1_bus_master *master);
 void w1_remove_master_device(struct w1_bus_master *master);
+struct w1_master *w1_find_master_device(struct w1_bus_master *master);
 
 /**
  * struct w1_family_ops - operations for a family type
-- 
2.44.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ