From 2f7891056916b2b6c182c47a4d9ce1a5e33cd307 Mon Sep 17 00:00:00 2001 From: mglocker Date: Wed, 23 Jul 2008 22:10:21 +0000 Subject: [PATCH] If /dev/video* is already used by an application, return EBUSY to other applications. Fixes a kernel panic. Reported by ian@ --- sys/dev/video.c | 15 +++++++++++---- sys/dev/videovar.h | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sys/dev/video.c b/sys/dev/video.c index 57d69a2847c..cfa33d97126 100644 --- a/sys/dev/video.c +++ b/sys/dev/video.c @@ -1,4 +1,4 @@ -/* $OpenBSD: video.c,v 1.17 2008/07/19 06:39:00 mglocker Exp $ */ +/* $OpenBSD: video.c,v 1.18 2008/07/23 22:10:21 mglocker Exp $ */ /* * Copyright (c) 2008 Robert Nagy * Copyright (c) 2008 Marcus Glocker @@ -97,6 +97,10 @@ videoopen(dev_t dev, int flags, int fmt, struct proc *p) sc->hw_if == NULL) return (ENXIO); + if (sc->sc_open & VIDEO_OPEN) + return (EBUSY); + sc->sc_open |= VIDEO_OPEN; + sc->sc_start_read = 0; if (sc->hw_if->open != NULL) @@ -110,13 +114,16 @@ int videoclose(dev_t dev, int flags, int fmt, struct proc *p) { struct video_softc *sc; + int r = 0; sc = video_cd.cd_devs[VIDEOUNIT(dev)]; if (sc->hw_if->close != NULL) - return (sc->hw_if->close(sc->hw_hdl)); - else - return (0); + r = sc->hw_if->close(sc->hw_hdl); + + sc->sc_open &= ~VIDEO_OPEN; + + return (r); } int diff --git a/sys/dev/videovar.h b/sys/dev/videovar.h index 8625a5181e4..678a6da1e35 100644 --- a/sys/dev/videovar.h +++ b/sys/dev/videovar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: videovar.h,v 1.5 2008/06/13 05:00:32 mglocker Exp $ */ +/* $OpenBSD: videovar.h,v 1.6 2008/07/23 22:10:21 mglocker Exp $ */ /* * Copyright (c) 2008 Robert Nagy * Copyright (c) 2008 Marcus Glocker @@ -25,6 +25,8 @@ struct video_softc { struct device *sc_dev; /* hardware device struct */ struct video_hw_if *hw_if; /* hardware interface */ char sc_dying; /* device detached */ +#define VIDEO_OPEN 0x01 + char sc_open; int sc_fsize; uint8_t *sc_fbuffer; -- 2.20.1