git: 79dfe2b76189 - main - ow: Use a bus_child_deleted method to free ivars for children

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 01 Nov 2024 14:13:01 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=79dfe2b761891eb3ab1b6a769d4f6adc97335350

commit 79dfe2b761891eb3ab1b6a769d4f6adc97335350
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-11-01 14:08:52 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-11-01 14:08:52 +0000

    ow: Use a bus_child_deleted method to free ivars for children
    
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D47364
---
 sys/dev/ow/ow.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sys/dev/ow/ow.c b/sys/dev/ow/ow.c
index 9901e51c289d..6157c9df2939 100644
--- a/sys/dev/ow/ow.c
+++ b/sys/dev/ow/ow.c
@@ -330,6 +330,12 @@ ow_add_child(device_t dev, romid_t romid)
 	return (0);
 }
 
+static void
+ow_child_deleted(device_t dev, device_t child)
+{
+	free(device_get_ivars(child), M_OW);
+}
+
 static device_t
 ow_child_by_romid(device_t dev, romid_t romid)
 {
@@ -560,7 +566,6 @@ ow_detach(device_t ndev)
 {
 	device_t *children, child;
 	int nkid, i;
-	struct ow_devinfo *di;
 	struct ow_softc *sc;
 
 	sc = device_get_softc(ndev);
@@ -577,8 +582,6 @@ ow_detach(device_t ndev)
 		return ENOMEM;
 	for (i = 0; i < nkid; i++) {
 		child = children[i];
-		di = device_get_ivars(child);
-		free(di, M_OW);
 		device_delete_child(ndev, child);
 	}
 	free(children, M_TEMP);
@@ -703,6 +706,7 @@ static device_method_t ow_methods[] = {
 	DEVMETHOD(device_detach,	ow_detach),
 
 	/* Bus interface */
+	DEVMETHOD(bus_child_deleted,	ow_child_deleted),
 	DEVMETHOD(bus_child_pnpinfo,	ow_child_pnpinfo),
 	DEVMETHOD(bus_read_ivar,	ow_read_ivar),
 	DEVMETHOD(bus_write_ivar,	ow_write_ivar),