git: 21d5b592faa1 - main - dpaa: Account for MDIO device not being found

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Sat, 26 Nov 2022 16:01:55 UTC
The branch main has been updated by jhibbits:

URL: https://cgit.FreeBSD.org/src/commit/?id=21d5b592faa1cd71c201acfb2686b79e0bbba9f7

commit 21d5b592faa1cd71c201acfb2686b79e0bbba9f7
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2022-11-26 15:38:13 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2022-11-26 15:55:21 +0000

    dpaa: Account for MDIO device not being found
    
    It's possible the MDIO device hasn't been and attached, or is incorrect
    in the device tree so can't probe and attach.  In this case,
    ofw_bus_find_child_device_by_phandle() will fail, and return NULL.
    Return an error from find_mdio() here to prevent the MAC from attaching,
    rather than worry about a NULL pointer dereference later on when
    accessing the PHY.
---
 sys/dev/dpaa/if_dtsec_fdt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/dev/dpaa/if_dtsec_fdt.c b/sys/dev/dpaa/if_dtsec_fdt.c
index 67f34683b66a..1ab331caf0d1 100644
--- a/sys/dev/dpaa/if_dtsec_fdt.c
+++ b/sys/dev/dpaa/if_dtsec_fdt.c
@@ -125,6 +125,9 @@ find_mdio(phandle_t phy_node, device_t mac, device_t *mdio_dev)
 	bus = device_get_parent(mac);
 	*mdio_dev = ofw_bus_find_child_device_by_phandle(bus, phy_node);
 
+	if (*mdio_dev == NULL)
+		return (ENOENT);
+
 	return (0);
 }