From ef1be3b04221c520aca0f6f839d1d4dc339912e1 Mon Sep 17 00:00:00 2001 From: Christian Brueffer Date: Thu, 22 Oct 2009 06:51:29 +0000 Subject: [PATCH] Check pointer for NULL before dereferencing it, not after. PR: 138387, 138388 Submitted by: Patroklos Argyroudis MFC after: 1 week --- sys/dev/ppbus/lpt.c | 7 +++++-- sys/dev/ppbus/pcfclock.c | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/dev/ppbus/lpt.c b/sys/dev/ppbus/lpt.c index 56b437884017..18d46ae39d5c 100644 --- a/sys/dev/ppbus/lpt.c +++ b/sys/dev/ppbus/lpt.c @@ -486,12 +486,15 @@ lptopen(struct cdev *dev, int flags, int fmt, struct thread *td) { int trys, err; struct lpt_data *sc = dev->si_drv1; - device_t lptdev = sc->sc_dev; - device_t ppbus = device_get_parent(lptdev); + device_t lptdev; + device_t ppbus; if (!sc) return (ENXIO); + lptdev = sc->sc_dev; + ppbus = device_get_parent(lptdev); + ppb_lock(ppbus); if (sc->sc_state) { lprintf(("%s: still open %x\n", device_get_nameunit(lptdev), diff --git a/sys/dev/ppbus/pcfclock.c b/sys/dev/ppbus/pcfclock.c index e59a8919e03f..65612a21de4c 100644 --- a/sys/dev/ppbus/pcfclock.c +++ b/sys/dev/ppbus/pcfclock.c @@ -150,12 +150,14 @@ static int pcfclock_open(struct cdev *dev, int flag, int fms, struct thread *td) { struct pcfclock_data *sc = dev->si_drv1; - device_t pcfclockdev = sc->dev; - device_t ppbus = device_get_parent(pcfclockdev); + device_t pcfclockdev; + device_t ppbus; int res; if (!sc) return (ENXIO); + pcfclockdev = sc->dev; + ppbus = device_get_parent(pcfclockdev); ppb_lock(ppbus); res = ppb_request_bus(ppbus, pcfclockdev,