Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Reorder to avoid null deref before null test



details:   https://anonhg.NetBSD.org/src/rev/acbb49566ade
branches:  trunk
changeset: 827035:acbb49566ade
user:      maya <maya%NetBSD.org@localhost>
date:      Mon Oct 09 23:24:22 2017 +0000

description:
Reorder to avoid null deref before null test

diffstat:

 sys/dev/pci/mpii.c |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (33 lines):

diff -r a75e33aa5f5e -r acbb49566ade sys/dev/pci/mpii.c
--- a/sys/dev/pci/mpii.c        Mon Oct 09 17:49:27 2017 +0000
+++ b/sys/dev/pci/mpii.c        Mon Oct 09 23:24:22 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mpii.c,v 1.9 2017/06/25 15:56:32 christos Exp $ */
+/* $NetBSD: mpii.c,v 1.10 2017/10/09 23:24:22 maya Exp $ */
 /*     OpenBSD: mpii.c,v 1.51 2012/04/11 13:29:14 naddy Exp    */
 /*
  * Copyright (c) 2010 Mike Belopuhov <mkb%crypt.org.ru@localhost>
@@ -20,7 +20,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpii.c,v 1.9 2017/06/25 15:56:32 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpii.c,v 1.10 2017/10/09 23:24:22 maya Exp $");
 
 #include "bio.h"
 
@@ -4108,10 +4108,12 @@
 static int
 mpii_insert_dev(struct mpii_softc *sc, struct mpii_device *dev)
 {
+
+       if (!dev || dev->slot < 0)
+               return (1);
+
        int slot = dev->slot;   /* initial hint */
 
-       if (!dev || slot < 0)
-               return (1);
        while (slot < sc->sc_max_devices && sc->sc_devs[slot] != NULL)
                slot++;
        if (slot >= sc->sc_max_devices)



Home | Main Index | Thread Index | Old Index