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: <20240503-mbly-olb-v2-4-95ce5a1e18fe@bootlin.com>
Date: Fri, 03 May 2024 16:20:49 +0200
From: Théo Lebrun <theo.lebrun@...tlin.com>
To: Rob Herring <robh@...nel.org>, 
 Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>, 
 Conor Dooley <conor+dt@...nel.org>, 
 Michael Turquette <mturquette@...libre.com>, 
 Stephen Boyd <sboyd@...nel.org>, Philipp Zabel <p.zabel@...gutronix.de>, 
 Linus Walleij <linus.walleij@...aro.org>, 
 Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
 "Rafael J. Wysocki" <rafael@...nel.org>, Lee Jones <lee@...nel.org>, 
 Thomas Bogendoerfer <tsbogend@...ha.franken.de>
Cc: linux-mips@...r.kernel.org, devicetree@...r.kernel.org, 
 linux-kernel@...r.kernel.org, linux-clk@...r.kernel.org, 
 linux-gpio@...r.kernel.org, 
 Vladimir Kondratiev <vladimir.kondratiev@...ileye.com>, 
 Gregory CLEMENT <gregory.clement@...tlin.com>, 
 Thomas Petazzoni <thomas.petazzoni@...tlin.com>, 
 Tawfik Bayouk <tawfik.bayouk@...ileye.com>, 
 Théo Lebrun <theo.lebrun@...tlin.com>
Subject: [PATCH v2 04/11] driver core: platform: Introduce
 platform_device_add_with_name()

Public function platform_device_add() does three things:
 - Name device using pdev->name and pdev->id;
 - Insert resources into resource tree;
 - device_add().

This implies device name must be based upon pdev->name. Add
platform_device_add_with_name() to allow caller to pick device name.
pdev->name cannot be picked freely: it might be used to match platform
driver id_table or name. This applies to MFD cells for example.

In header file, avoid breakage by aliasing platform_device_add(pdev) to
platform_device_add_with_name(pdev, NULL).

Signed-off-by: Théo Lebrun <theo.lebrun@...tlin.com>
---
 drivers/base/platform.c         | 17 +++++++++++------
 include/linux/platform_device.h | 12 +++++++++++-
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 10c577963418..dce282cb2e50 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -648,13 +648,15 @@ int platform_device_add_data(struct platform_device *pdev, const void *data,
 EXPORT_SYMBOL_GPL(platform_device_add_data);
 
 /**
- * platform_device_add - add a platform device to device hierarchy
+ * platform_device_add_with_name - add a platform device to device hierarchy
  * @pdev: platform device we're adding
+ * @devname: optional device name to assign, fallback to platform device name
  *
  * This is part 2 of platform_device_register(), though may be called
  * separately _iff_ pdev was allocated by platform_device_alloc().
  */
-int platform_device_add(struct platform_device *pdev)
+int platform_device_add_with_name(struct platform_device *pdev,
+				  const char *devname)
 {
 	struct device *dev = &pdev->dev;
 	u32 i;
@@ -665,12 +667,15 @@ int platform_device_add(struct platform_device *pdev)
 
 	dev->bus = &platform_bus_type;
 
+	if (!devname)
+		devname = pdev->name;
+
 	switch (pdev->id) {
 	default:
-		dev_set_name(dev, "%s.%d", pdev->name,  pdev->id);
+		dev_set_name(dev, "%s.%d", devname,  pdev->id);
 		break;
 	case PLATFORM_DEVID_NONE:
-		dev_set_name(dev, "%s", pdev->name);
+		dev_set_name(dev, "%s", devname);
 		break;
 	case PLATFORM_DEVID_AUTO:
 		/*
@@ -683,7 +688,7 @@ int platform_device_add(struct platform_device *pdev)
 			return ret;
 		pdev->id = ret;
 		pdev->id_auto = true;
-		dev_set_name(dev, "%s.%d.auto", pdev->name, pdev->id);
+		dev_set_name(dev, "%s.%d.auto", devname, pdev->id);
 		break;
 	}
 
@@ -733,7 +738,7 @@ int platform_device_add(struct platform_device *pdev)
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(platform_device_add);
+EXPORT_SYMBOL_GPL(platform_device_add_with_name);
 
 /**
  * platform_device_del - remove a platform-level device
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 7a41c72c1959..bc1463c83f69 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -229,10 +229,20 @@ extern int platform_device_add_resources(struct platform_device *pdev,
 					 unsigned int num);
 extern int platform_device_add_data(struct platform_device *pdev,
 				    const void *data, size_t size);
-extern int platform_device_add(struct platform_device *pdev);
+extern int platform_device_add_with_name(struct platform_device *pdev,
+					 const char *devname);
 extern void platform_device_del(struct platform_device *pdev);
 extern void platform_device_put(struct platform_device *pdev);
 
+/**
+ * platform_device_add - add a platform device to device hierarchy
+ * @pdev: platform device we're adding
+ */
+static inline int platform_device_add(struct platform_device *pdev)
+{
+	return platform_device_add_with_name(pdev, NULL);
+}
+
 struct platform_driver {
 	int (*probe)(struct platform_device *);
 

-- 
2.45.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ