summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/usb/uvideo.c8
-rw-r--r--sys/dev/video.c22
-rw-r--r--sys/dev/video_if.h3
3 files changed, 20 insertions, 13 deletions
diff --git a/sys/dev/usb/uvideo.c b/sys/dev/usb/uvideo.c
index a82f0578e98..0fa8ef73151 100644
--- a/sys/dev/usb/uvideo.c
+++ b/sys/dev/usb/uvideo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvideo.c,v 1.21 2008/05/27 18:19:37 mglocker Exp $ */
+/* $OpenBSD: uvideo.c,v 1.22 2008/05/30 06:37:38 mglocker Exp $ */
/*
* Copyright (c) 2008 Robert Nagy <robert@openbsd.org>
@@ -919,6 +919,12 @@ uvideo_vs_alloc_sample(struct uvideo_softc *sc)
fb->buf_size = UGETDW(sc->sc_desc_probe.dwMaxVideoFrameSize);
+ /* don't overflow the upper layer sample buffer */
+ if (VIDEO_BUF_SIZE < fb->buf_size) {
+ printf("%s: sofware video buffer is too small!\n", DEVNAME(sc));
+ return (USBD_NOMEM);
+ }
+
fb->buf = malloc(fb->buf_size, M_DEVBUF, M_NOWAIT);
if (fb->buf == NULL) {
printf("%s: can't allocate sample buffer!\n", DEVNAME(sc));
diff --git a/sys/dev/video.c b/sys/dev/video.c
index 646f0e99511..4131a767f7d 100644
--- a/sys/dev/video.c
+++ b/sys/dev/video.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: video.c,v 1.4 2008/05/26 17:51:18 mglocker Exp $ */
+/* $OpenBSD: video.c,v 1.5 2008/05/30 06:37:38 mglocker Exp $ */
/*
* Copyright (c) 2008 Robert Nagy <robert@openbsd.org>
*
@@ -66,6 +66,12 @@ videoattach(struct device *parent, struct device *self, void *aux)
sc->hw_if = sa->hwif;
sc->hw_hdl = sa->hdl;
sc->sc_dev = parent;
+
+ sc->sc_fbuffer = malloc(VIDEO_BUF_SIZE, M_DEVBUF, M_NOWAIT);
+ if (sc->sc_fbuffer == NULL) {
+ printf("video: could not allocate frame buffer\n");
+ return;
+ }
}
int
@@ -80,12 +86,6 @@ videoopen(dev_t dev, int flags, int fmt, struct proc *p)
sc->hw_if == NULL)
return (ENXIO);
- sc->sc_fsize = 0;
- /* XXX find proper size */
- sc->sc_fbuffer = malloc(32000, M_DEVBUF, M_NOWAIT);
- if (sc->sc_fbuffer == NULL)
- return (ENOMEM);
-
if (sc->hw_if->open != NULL)
return (sc->hw_if->open(sc->hw_hdl, flags, &sc->sc_fsize,
sc->sc_fbuffer, video_intr, sc));
@@ -100,9 +100,6 @@ videoclose(dev_t dev, int flags, int fmt, struct proc *p)
sc = video_cd.cd_devs[VIDEOUNIT(dev)];
- if (sc->sc_fbuffer != NULL)
- free(sc->sc_fbuffer, M_DEVBUF);
-
if (sc->hw_if->close != NULL)
return (sc->hw_if->close(sc->hw_hdl));
else
@@ -266,9 +263,12 @@ videoprint(void *aux, const char *pnp)
int
videodetach(struct device *self, int flags)
{
- /*struct video_softc *sc = (struct video_softc *)self;*/
+ struct video_softc *sc = (struct video_softc *)self;
int maj, mn;
+ if (sc->sc_fbuffer != NULL)
+ free(sc->sc_fbuffer, M_DEVBUF);
+
/* locate the major number */
for (maj = 0; maj < nchrdev; maj++)
if (cdevsw[maj].d_open == videoopen)
diff --git a/sys/dev/video_if.h b/sys/dev/video_if.h
index 4003eb5e4f5..eb672e75302 100644
--- a/sys/dev/video_if.h
+++ b/sys/dev/video_if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: video_if.h,v 1.4 2008/05/26 17:51:18 mglocker Exp $ */
+/* $OpenBSD: video_if.h,v 1.5 2008/05/30 06:37:38 mglocker Exp $ */
/*
* Copyright (c) 2008 Robert Nagy <robert@openbsd.org>
*
@@ -23,6 +23,7 @@
*/
#define VIDEOUNIT(x) (minor(x))
+#define VIDEO_BUF_SIZE 65536
struct video_hw_if {
/* open hardware */