From: jca Date: Sun, 14 Aug 2022 21:10:08 +0000 (+0000) Subject: Unbreak, don't assume we always hold the NET_LOCK X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=caaad5e703613714bab53473d4f634bfd7dbf163;p=openbsd Unbreak, don't assume we always hold the NET_LOCK After net/if.c:rev 1.661 ifioctl() doesn't take the net lock any more around SIOCGIFMEDIA and SIOCSIFMEDIA, which broke cad_ioctl(). The same was already true about SIOCGIFSFFPAGE. Only release/reacquire the net lock if warranted. Input mvs@, ok miod@ mvs@ bluhm@ --- diff --git a/sys/dev/fdt/if_cad.c b/sys/dev/fdt/if_cad.c index dfeec94896c..dfc2735a648 100644 --- a/sys/dev/fdt/if_cad.c +++ b/sys/dev/fdt/if_cad.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_cad.c,v 1.11 2022/03/08 16:13:08 visa Exp $ */ +/* $OpenBSD: if_cad.c,v 1.12 2022/08/14 21:10:08 jca Exp $ */ /* * Copyright (c) 2021-2022 Visa Hankala @@ -550,12 +550,22 @@ cad_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { struct cad_softc *sc = ifp->if_softc; struct ifreq *ifr = (struct ifreq *)data; - int error = 0; + int error = 0, netlock_held = 1; int s; - NET_UNLOCK(); + switch (cmd) { + case SIOCGIFMEDIA: + case SIOCSIFMEDIA: + case SIOCGIFSFFPAGE: + netlock_held = 0; + break; + } + + if (netlock_held) + NET_UNLOCK(); rw_enter_write(&sc->sc_cfg_lock); - NET_LOCK(); + if (netlock_held) + NET_LOCK(); s = splnet(); switch (cmd) {