diff mbox series

[1/2] driver core: platform: turn pdev->id_auto into pdev->flags

Message ID 20250218-pdev-uaf-v1-1-5ea1a0d3aba0@bootlin.com (mailing list archive)
State New
Headers show
Series driver core: platform: avoid use-after-free on device name | expand

Commit Message

Théo Lebrun Feb. 18, 2025, 11 a.m. UTC
struct platform_device->id_auto is the only boolean stored inside the
structure. Remove it and add an u8 flags field. The goal is to allow
more flags (without using more memory).

Cc: <stable@vger.kernel.org>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
 drivers/base/platform.c         | 6 +++---
 include/linux/platform_device.h | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 6f2a33722c5203ac196a6e36e153648d0fe6c6d4..e2284482c7ba7c12fe2ab3c715e7d1daa3f65021 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -682,7 +682,7 @@  int platform_device_add(struct platform_device *pdev)
 		if (ret < 0)
 			return ret;
 		pdev->id = ret;
-		pdev->id_auto = true;
+		pdev->flags |= PLATFORM_DEVICE_FLAG_ID_AUTO;
 		dev_set_name(dev, "%s.%d.auto", pdev->name, pdev->id);
 		break;
 	}
@@ -720,7 +720,7 @@  int platform_device_add(struct platform_device *pdev)
 	return 0;
 
  failed:
-	if (pdev->id_auto) {
+	if (pdev->flags & PLATFORM_DEVICE_FLAG_ID_AUTO) {
 		ida_free(&platform_devid_ida, pdev->id);
 		pdev->id = PLATFORM_DEVID_AUTO;
 	}
@@ -750,7 +750,7 @@  void platform_device_del(struct platform_device *pdev)
 	if (!IS_ERR_OR_NULL(pdev)) {
 		device_del(&pdev->dev);
 
-		if (pdev->id_auto) {
+		if (pdev->flags & PLATFORM_DEVICE_FLAG_ID_AUTO) {
 			ida_free(&platform_devid_ida, pdev->id);
 			pdev->id = PLATFORM_DEVID_AUTO;
 		}
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 074754c23d330c9a099e20eecfeb6cbd5025e04f..d842b21ba3791f974fa62f52bd160ef5820261c1 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -23,7 +23,8 @@  struct platform_device_id;
 struct platform_device {
 	const char	*name;
 	int		id;
-	bool		id_auto;
+	u8		flags;
+#define PLATFORM_DEVICE_FLAG_ID_AUTO	BIT(0)
 	struct device	dev;
 	u64		platform_dma_mask;
 	struct device_dma_parameters dma_parms;