diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-08-29 20:51:47 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-08-29 20:51:47 +0000 |
commit | 8863901c4f4a353f58b08c5ce893fe39d1cc06a3 (patch) | |
tree | 2398a5fa623a0a416b9dcba0923f9f2f716296af /sys/dev | |
parent | bdf449ed645767778e6068a947db3319b61f83b0 (diff) |
video sub-drivers will not return EINVAL in size variable. (Well,
a broken USB driver could, then what happens?) 0 is the right error.
Also, keep track the size for free()
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/video.c | 12 | ||||
-rw-r--r-- | sys/dev/videovar.h | 3 |
2 files changed, 8 insertions, 7 deletions
diff --git a/sys/dev/video.c b/sys/dev/video.c index 85f54165358..5a4357fde59 100644 --- a/sys/dev/video.c +++ b/sys/dev/video.c @@ -1,4 +1,4 @@ -/* $OpenBSD: video.c,v 1.36 2015/07/17 23:29:14 jsg Exp $ */ +/* $OpenBSD: video.c,v 1.37 2015/08/29 20:51:46 deraadt Exp $ */ /* * Copyright (c) 2008 Robert Nagy <robert@openbsd.org> @@ -69,21 +69,21 @@ videoattach(struct device *parent, struct device *self, void *aux) { struct video_softc *sc = (void *)self; struct video_attach_args *sa = aux; - int video_buf_size = 0; printf("\n"); sc->hw_if = sa->hwif; sc->hw_hdl = sa->hdl; sc->sc_dev = parent; + sc->sc_fbufferlen = 0; if (sc->hw_if->get_bufsize) - video_buf_size = (sc->hw_if->get_bufsize)(sc->hw_hdl); - if (video_buf_size == EINVAL) { + sc->sc_fbufferlen = (sc->hw_if->get_bufsize)(sc->hw_hdl); + if (sc->sc_fbufferlen == 0) { printf("video: could not request frame buffer size\n"); return; } - sc->sc_fbuffer = malloc(video_buf_size, M_DEVBUF, M_NOWAIT); + sc->sc_fbuffer = malloc(sc->sc_fbufferlen, M_DEVBUF, M_NOWAIT); if (sc->sc_fbuffer == NULL) { printf("video: could not allocate frame buffer\n"); return; @@ -438,7 +438,7 @@ videodetach(struct device *self, int flags) int maj, mn; if (sc->sc_fbuffer != NULL) - free(sc->sc_fbuffer, M_DEVBUF, 0); + free(sc->sc_fbuffer, M_DEVBUF, sc->sc_fbufferlen); /* locate the major number */ for (maj = 0; maj < nchrdev; maj++) diff --git a/sys/dev/videovar.h b/sys/dev/videovar.h index 8426dfd81fd..c263631faf3 100644 --- a/sys/dev/videovar.h +++ b/sys/dev/videovar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: videovar.h,v 1.7 2010/07/14 21:24:33 jakemsr Exp $ */ +/* $OpenBSD: videovar.h,v 1.8 2015/08/29 20:51:46 deraadt Exp $ */ /* * Copyright (c) 2008 Robert Nagy <robert@openbsd.org> * Copyright (c) 2008 Marcus Glocker <mglocker@openbsd.org> @@ -30,6 +30,7 @@ struct video_softc { int sc_fsize; uint8_t *sc_fbuffer; + size_t sc_fbufferlen; int sc_vidmode; /* access mode */ #define VIDMODE_NONE 0 #define VIDMODE_MMAP 1 |