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-5-95ce5a1e18fe@bootlin.com>
Date: Fri, 03 May 2024 16:20:50 +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 05/11] mfd: Add cell device name

Current device name is picked from pdev->name, coming from cell->name.
pdev->name is sometimes used to match driver so cannot be changed.
Add cell->devname field to let MFDs configure their sub-devices names
using newly introduced platform_device_add_with_name().

This comes in handy when MFDs instantiate the same platform driver.
First solution is to use auto IDs:

	// MFD device A generates sub-device named "foo.0.auto"
	struct mfd_cell cell = { .name = "foo" };
	mfd_add_devices(dev, PLATFORM_DEVID_AUTO, &cell, 1, ...);

	// MFD device B generates sub-device named "foo.1.auto"
	struct mfd_cell cell = { .name = "foo" };
	mfd_add_devices(dev, PLATFORM_DEVID_AUTO, &cell, 1, ...);

An alternative is to manually pick IDs using cell->id:

	// MFD device A generates sub-device named "foo.0"
	struct mfd_cell cell = { .name = "foo", .id = 0 };
	mfd_add_devices(dev, 0, &cell, 1, ...);

	// MFD device B generates sub-device named "foo.1"
	struct mfd_cell cell = { .name = "foo", .id = 1 };
	mfd_add_devices(dev, 0, &cell, 1, ...);

Devices still have obscure names. With changes, two MFD devices can do:

	// MFD device A generates sub-device named "foo-a"
	struct mfd_cell cell = { .name = "foo", .devname = "foo-a" };
	mfd_add_devices(dev, PLATFORM_DEVID_NONE, &cell, 1, ...);

	// MFD device B generates sub-device named "foo-b"
	struct mfd_cell cell = { .name = "foo", .devname = "foo-b" };
	mfd_add_devices(dev, PLATFORM_DEVID_NONE, &cell, 1, ...);

Device names are explicit and facilitate identification.
Benefit increases with more instances.

No shorthand MFD_CELL_*() macro is created to exploit this field.

Signed-off-by: Théo Lebrun <theo.lebrun@...tlin.com>
---
 drivers/mfd/mfd-core.c   |  2 +-
 include/linux/mfd/core.h | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 6ad5c93027af..bdfbe860295a 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -271,7 +271,7 @@ static int mfd_add_device(struct device *parent, int id,
 	if (ret)
 		goto fail_res_conflict;
 
-	ret = platform_device_add(pdev);
+	ret = platform_device_add_with_name(pdev, cell->devname);
 	if (ret)
 		goto fail_res_conflict;
 
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index e8bcad641d8c..a2040372ca91 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -14,7 +14,8 @@
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
 
-#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \
+#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     _of_reg, _use_of_reg, _match, _devname)		\
 	{								\
 		.name = (_name),					\
 		.resources = (_res),					\
@@ -26,25 +27,26 @@
 		.use_of_reg = (_use_of_reg),				\
 		.acpi_match = (_match),					\
 		.id = (_id),						\
+		.devname = (_devname),					\
 	}
 
 #define MFD_CELL_OF_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL, NULL)
 
 #define MFD_CELL_OF(_name, _res, _pdata, _pdsize, _id, _compat) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL, NULL)
 
 #define MFD_CELL_ACPI(_name, _res, _pdata, _pdsize, _id, _match) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match, NULL)
 
 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL, NULL)
 
 #define MFD_CELL_RES(_name, _res) \
-	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL)
+	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL, NULL)
 
 #define MFD_CELL_NAME(_name) \
-	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL)
+	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL, NULL)
 
 #define MFD_DEP_LEVEL_NORMAL 0
 #define MFD_DEP_LEVEL_HIGH 1
@@ -118,6 +120,9 @@ struct mfd_cell {
 	 */
 	int			num_parent_supplies;
 	const char * const	*parent_supplies;
+
+	/* Optional struct device name. */
+	const char		*devname;
 };
 
 /*

-- 
2.45.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ