don't deref pointer before test it is safe
authorjsg <jsg@openbsd.org>
Mon, 14 Feb 2022 23:20:46 +0000 (23:20 +0000)
committerjsg <jsg@openbsd.org>
Mon, 14 Feb 2022 23:20:46 +0000 (23:20 +0000)
ok miod@

sys/arch/hppa/dev/mongoose.c
sys/arch/macppc/dev/openpic.c

index d4836da..4e3794f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mongoose.c,v 1.21 2010/05/24 15:04:53 deraadt Exp $   */
+/*     $OpenBSD: mongoose.c,v 1.22 2022/02/14 23:20:46 jsg Exp $       */
 
 /*
  * Copyright (c) 1998-2003 Michael Shalayeff
@@ -196,12 +196,13 @@ mg_intr_disestablish(void *v, void *cookie)
 {
        struct hppa_isa_iv *iv = cookie;
        struct mongoose_softc *sc = v;
-       int irq = iv - sc->sc_iv;
+       int irq;
        volatile u_int8_t *imr;
 
        if (!sc || !cookie)
                return;
 
+       irq = iv - sc->sc_iv;
        if (irq < 8)
                imr = &sc->sc_ctrl->imr0;
        else
index 6d22e44..4074784 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: openpic.c,v 1.87 2021/03/11 11:16:58 jsg Exp $        */
+/*     $OpenBSD: openpic.c,v 1.88 2022/02/14 23:20:46 jsg Exp $        */
 
 /*-
  * Copyright (c) 2008 Dale Rahn <drahn@openbsd.org>
@@ -480,13 +480,14 @@ openpic_intr_disestablish(void *lcp, void *arg)
 {
        struct intrhand *ih = arg;
        int irq = ih->ih_irq;
-       struct intrq *iq = &openpic_handler[irq];
+       struct intrq *iq;
        int s;
 
        if (!LEGAL_IRQ(irq)) {
                printf("%s: bogus irq %d", __func__, irq);
                return;
        }
+       iq = &openpic_handler[irq];
 
        /*
         * Remove the handler from the chain.