From 96e01a0efb268766622560f66597f30ce09e9801 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Fri, 18 Aug 2017 12:15:36 +0000 Subject: Test for device_lookup() returning NULL in gpioioctl() and gpioclose(). Coverity CIDs 1453046, 1453184. --- sys/dev/gpio/gpio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'sys') diff --git a/sys/dev/gpio/gpio.c b/sys/dev/gpio/gpio.c index 05fbd6ed419..0aa7ed5c69b 100644 --- a/sys/dev/gpio/gpio.c +++ b/sys/dev/gpio/gpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpio.c,v 1.14 2015/08/27 05:48:40 deraadt Exp $ */ +/* $OpenBSD: gpio.c,v 1.15 2017/08/18 12:15:35 jsg Exp $ */ /* * Copyright (c) 2008 Marc Balmer @@ -267,6 +267,9 @@ gpioclose(dev_t dev, int flag, int mode, struct proc *p) struct gpio_softc *sc; sc = (struct gpio_softc *)device_lookup(&gpio_cd, minor(dev)); + if (sc == NULL) + return (ENXIO); + sc->sc_opened = 0; return (0); @@ -299,6 +302,9 @@ gpioioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) int pin, value, flags, npins, found; sc = (struct gpio_softc *)device_lookup(&gpio_cd, minor(dev)); + if (sc == NULL) + return (ENXIO); + gc = sc->sc_gc; switch (cmd) { -- cgit v1.2.3