public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] MIPS: ip22-gio: fix leaks and replace static root
@ 2026-04-24 10:28 Johan Hovold
  2026-04-24 10:28 ` [PATCH 1/5] MIPS: ip22-gio: fix kfree() of static object Johan Hovold
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-24 10:28 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Johan Hovold

This series fixes some issues found through inspection when looking into
replacing the statically allocated gio bus root device.

Johan


Johan Hovold (5):
  MIPS: ip22-gio: fix kfree() of static object
  MIPS: ip22-gio: fix gio device memory leak
  MIPS: ip22-gio: fix device reference leak in probe
  MIPS: ip22-gio: switch to dynamic root device
  MIPS: ip22-gio: do not export device release function

 arch/mips/include/asm/gio_device.h |  6 ------
 arch/mips/sgi-ip22/ip22-gio.c      | 34 ++++++++++--------------------
 2 files changed, 11 insertions(+), 29 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] MIPS: ip22-gio: fix kfree() of static object
  2026-04-24 10:28 [PATCH 0/5] MIPS: ip22-gio: fix leaks and replace static root Johan Hovold
@ 2026-04-24 10:28 ` Johan Hovold
  2026-04-24 10:28 ` [PATCH 2/5] MIPS: ip22-gio: fix gio device memory leak Johan Hovold
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-24 10:28 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: linux-mips, linux-kernel, Johan Hovold, stable, Levente Kurusa

The gio bus root device is a statically allocated object which must not
be freed by kfree() on failure to register the device or bus.

Fixes: 82242d28ff8b ("MIPS: IP22: Add missing put_device call")
Cc: stable@vger.kernel.org	# 3.17
Cc: Levente Kurusa <levex@linux.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 arch/mips/sgi-ip22/ip22-gio.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c
index 9eec8842ffb7..a574441fa44b 100644
--- a/arch/mips/sgi-ip22/ip22-gio.c
+++ b/arch/mips/sgi-ip22/ip22-gio.c
@@ -30,7 +30,6 @@ static struct {
 
 static void gio_bus_release(struct device *dev)
 {
-	kfree(dev);
 }
 
 static struct device gio_bus = {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] MIPS: ip22-gio: fix gio device memory leak
  2026-04-24 10:28 [PATCH 0/5] MIPS: ip22-gio: fix leaks and replace static root Johan Hovold
  2026-04-24 10:28 ` [PATCH 1/5] MIPS: ip22-gio: fix kfree() of static object Johan Hovold
@ 2026-04-24 10:28 ` Johan Hovold
  2026-04-24 10:28 ` [PATCH 3/5] MIPS: ip22-gio: fix device reference leak in probe Johan Hovold
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-24 10:28 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Johan Hovold, stable

The gio device release callback was never wired up so gio devices are
not freed when the last reference is dropped.

Fixes: e84de0c61905 ("MIPS: GIO bus support for SGI IP22/28")
Cc: stable@vger.kernel.org	# 3.3
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 arch/mips/sgi-ip22/ip22-gio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c
index a574441fa44b..2f5c6c6f8254 100644
--- a/arch/mips/sgi-ip22/ip22-gio.c
+++ b/arch/mips/sgi-ip22/ip22-gio.c
@@ -100,6 +100,8 @@ int gio_device_register(struct gio_device *giodev)
 {
 	giodev->dev.bus = &gio_bus_type;
 	giodev->dev.parent = &gio_bus;
+	giodev->dev.release = gio_release_dev;
+
 	return device_register(&giodev->dev);
 }
 EXPORT_SYMBOL_GPL(gio_device_register);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] MIPS: ip22-gio: fix device reference leak in probe
  2026-04-24 10:28 [PATCH 0/5] MIPS: ip22-gio: fix leaks and replace static root Johan Hovold
  2026-04-24 10:28 ` [PATCH 1/5] MIPS: ip22-gio: fix kfree() of static object Johan Hovold
  2026-04-24 10:28 ` [PATCH 2/5] MIPS: ip22-gio: fix gio device memory leak Johan Hovold
@ 2026-04-24 10:28 ` Johan Hovold
  2026-04-24 10:28 ` [PATCH 4/5] MIPS: ip22-gio: switch to dynamic root device Johan Hovold
  2026-04-24 10:28 ` [PATCH 5/5] MIPS: ip22-gio: do not export device release function Johan Hovold
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-24 10:28 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Johan Hovold, stable

The gio probe function needlessly takes a device reference which is
never released and therefore prevents unbound gio devices from being
freed.

Fixes: e84de0c61905 ("MIPS: GIO bus support for SGI IP22/28")
Cc: stable@vger.kernel.org	# 3.3
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 arch/mips/sgi-ip22/ip22-gio.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c
index 2f5c6c6f8254..7b7572d11250 100644
--- a/arch/mips/sgi-ip22/ip22-gio.c
+++ b/arch/mips/sgi-ip22/ip22-gio.c
@@ -133,13 +133,9 @@ static int gio_device_probe(struct device *dev)
 	if (!drv->probe)
 		return error;
 
-	gio_dev_get(gio_dev);
-
 	match = gio_match_device(drv->id_table, gio_dev);
 	if (match)
 		error = drv->probe(gio_dev, match);
-	if (error)
-		gio_dev_put(gio_dev);
 
 	return error;
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] MIPS: ip22-gio: switch to dynamic root device
  2026-04-24 10:28 [PATCH 0/5] MIPS: ip22-gio: fix leaks and replace static root Johan Hovold
                   ` (2 preceding siblings ...)
  2026-04-24 10:28 ` [PATCH 3/5] MIPS: ip22-gio: fix device reference leak in probe Johan Hovold
@ 2026-04-24 10:28 ` Johan Hovold
  2026-04-24 10:28 ` [PATCH 5/5] MIPS: ip22-gio: do not export device release function Johan Hovold
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-24 10:28 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Johan Hovold

Driver core expects devices to be dynamically allocated and will, for
example, complain loudly when no release function has been provided.

Use root_device_register() to allocate and register the root device
instead of open coding using a static device.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 arch/mips/sgi-ip22/ip22-gio.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c
index 7b7572d11250..d29067430b44 100644
--- a/arch/mips/sgi-ip22/ip22-gio.c
+++ b/arch/mips/sgi-ip22/ip22-gio.c
@@ -28,14 +28,7 @@ static struct {
 	{ .name = "SGI GR2/GR3", .id = 0x7f },
 };
 
-static void gio_bus_release(struct device *dev)
-{
-}
-
-static struct device gio_bus = {
-	.init_name = "gio",
-	.release = &gio_bus_release,
-};
+static struct device *gio_bus;
 
 /**
  * gio_match_device - Tell if an of_device structure has a matching
@@ -99,7 +92,7 @@ EXPORT_SYMBOL_GPL(gio_release_dev);
 int gio_device_register(struct gio_device *giodev)
 {
 	giodev->dev.bus = &gio_bus_type;
-	giodev->dev.parent = &gio_bus;
+	giodev->dev.parent = gio_bus;
 	giodev->dev.release = gio_release_dev;
 
 	return device_register(&giodev->dev);
@@ -397,11 +390,9 @@ static int __init ip22_gio_init(void)
 	unsigned int pbdma __maybe_unused;
 	int ret;
 
-	ret = device_register(&gio_bus);
-	if (ret) {
-		put_device(&gio_bus);
-		return ret;
-	}
+	gio_bus = root_device_register("gio");
+	if (IS_ERR(gio_bus))
+		return PTR_ERR(gio_bus);
 
 	ret = bus_register(&gio_bus_type);
 	if (!ret) {
@@ -420,8 +411,9 @@ static int __init ip22_gio_init(void)
 			ip22_check_gio(1, GIO_SLOT_EXP0_BASE, SGI_GIOEXP0_IRQ);
 			ip22_check_gio(2, GIO_SLOT_EXP1_BASE, SGI_GIOEXP1_IRQ);
 		}
-	} else
-		device_unregister(&gio_bus);
+	} else {
+		root_device_unregister(gio_bus);
+	}
 
 	return ret;
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] MIPS: ip22-gio: do not export device release function
  2026-04-24 10:28 [PATCH 0/5] MIPS: ip22-gio: fix leaks and replace static root Johan Hovold
                   ` (3 preceding siblings ...)
  2026-04-24 10:28 ` [PATCH 4/5] MIPS: ip22-gio: switch to dynamic root device Johan Hovold
@ 2026-04-24 10:28 ` Johan Hovold
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-24 10:28 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Johan Hovold

There is no need to export the gio device release function as the
devices are reference counted.

Drop the export along with the unused inline wrapper.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 arch/mips/include/asm/gio_device.h | 6 ------
 arch/mips/sgi-ip22/ip22-gio.c      | 3 +--
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/mips/include/asm/gio_device.h b/arch/mips/include/asm/gio_device.h
index 159087f5386e..f9c102f038d6 100644
--- a/arch/mips/include/asm/gio_device.h
+++ b/arch/mips/include/asm/gio_device.h
@@ -37,12 +37,6 @@ extern void gio_dev_put(struct gio_device *);
 
 extern int gio_device_register(struct gio_device *);
 extern void gio_device_unregister(struct gio_device *);
-extern void gio_release_dev(struct device *);
-
-static inline void gio_device_free(struct gio_device *dev)
-{
-	gio_release_dev(&dev->dev);
-}
 
 extern int gio_register_driver(struct gio_driver *);
 extern void gio_unregister_driver(struct gio_driver *);
diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c
index d29067430b44..54e17c8693e2 100644
--- a/arch/mips/sgi-ip22/ip22-gio.c
+++ b/arch/mips/sgi-ip22/ip22-gio.c
@@ -80,14 +80,13 @@ EXPORT_SYMBOL_GPL(gio_dev_put);
  * Will be called only by the device core when all users of this gio device are
  * done.
  */
-void gio_release_dev(struct device *dev)
+static void gio_release_dev(struct device *dev)
 {
 	struct gio_device *giodev;
 
 	giodev = to_gio_device(dev);
 	kfree(giodev);
 }
-EXPORT_SYMBOL_GPL(gio_release_dev);
 
 int gio_device_register(struct gio_device *giodev)
 {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-24 10:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-24 10:28 [PATCH 0/5] MIPS: ip22-gio: fix leaks and replace static root Johan Hovold
2026-04-24 10:28 ` [PATCH 1/5] MIPS: ip22-gio: fix kfree() of static object Johan Hovold
2026-04-24 10:28 ` [PATCH 2/5] MIPS: ip22-gio: fix gio device memory leak Johan Hovold
2026-04-24 10:28 ` [PATCH 3/5] MIPS: ip22-gio: fix device reference leak in probe Johan Hovold
2026-04-24 10:28 ` [PATCH 4/5] MIPS: ip22-gio: switch to dynamic root device Johan Hovold
2026-04-24 10:28 ` [PATCH 5/5] MIPS: ip22-gio: do not export device release function Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox