From 9d92f090f4b05e49061151d81b5d20d20711a0fd Mon Sep 17 00:00:00 2001 From: thorpej Date: Fri, 29 Mar 2024 19:30:09 +0000 Subject: [PATCH] ugen and ugenif share the same /dev/ugenN.xx namespace in such a way that the device unit number does not necessarily match the /dev/ugenN.xx unit number (N). If you ONLY have ugen devices, it happens to work out and devpubd scripts can be extremely naive. If you ONLY have ugenif devices, it also happens to work out, but your devpubd scripts have to slightly more informed. If you have a mix of ugen AND ugenif devices, though, you're pretty much out of luck. So, this change adds a "ugen-unit" device property which devpubd scripts can query to determine which /dev/ugenN.xx nodes a given ugen or ugenif device is using. --- sys/dev/usb/ugen.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/dev/usb/ugen.c b/sys/dev/usb/ugen.c index 50e63ac6b188..c5b5f2550a72 100644 --- a/sys/dev/usb/ugen.c +++ b/sys/dev/usb/ugen.c @@ -1,4 +1,4 @@ -/* $NetBSD: ugen.c,v 1.176 2024/03/26 03:24:14 thorpej Exp $ */ +/* $NetBSD: ugen.c,v 1.177 2024/03/29 19:30:09 thorpej Exp $ */ /* * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.176 2024/03/26 03:24:14 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.177 2024/03/29 19:30:09 thorpej Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -238,12 +238,18 @@ ugenif_get_unit(struct ugen_softc *sc) KASSERT(sc0 == sc); KASSERT(rb_tree_find_node(&ugenif.tree, &i) == sc); mutex_exit(&ugenif.lock); + + prop_dictionary_set_uint(device_properties(sc->sc_dev), + "ugen-unit", sc->sc_unit); } static void ugenif_put_unit(struct ugen_softc *sc) { + prop_dictionary_remove(device_properties(sc->sc_dev), + "ugen-unit"); + mutex_enter(&ugenif.lock); KASSERT(rb_tree_find_node(&ugenif.tree, &sc->sc_unit) == sc); rb_tree_remove_node(&ugenif.tree, sc);