diff options
author | 2018-04-18 12:05:31 +0000 | |
---|---|---|
committer | 2018-04-18 12:05:31 +0000 | |
commit | a2f13a566addb8308f6240d0bf4b42262d17e31a (patch) | |
tree | 405538a992d85ce25b276468c3c374cf79c24a10 | |
parent | Stop modifying vm page flags using mixed atomic and non-atomic (diff) | |
download | wireguard-openbsd-a2f13a566addb8308f6240d0bf4b42262d17e31a.tar.xz wireguard-openbsd-a2f13a566addb8308f6240d0bf4b42262d17e31a.zip |
handle failure better in release_firmware()/request_firmware()
Alloc the containing struct with M_ZERO so if loadfirmware() fails and
doesn't set the pointer we won't try to free an address based on
uninitialised memory.
Use M_DEVBUF not M_DRM when freeing the buffer allocated by
loadfirmware().
-rw-r--r-- | sys/dev/pci/drm/drm_linux.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/dev/pci/drm/drm_linux.h b/sys/dev/pci/drm/drm_linux.h index 89749ddb2c6..2da4b5cdec7 100644 --- a/sys/dev/pci/drm/drm_linux.h +++ b/sys/dev/pci/drm/drm_linux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.h,v 1.84 2018/02/19 08:59:52 mpi Exp $ */ +/* $OpenBSD: drm_linux.h,v 1.85 2018/04/18 12:05:31 jsg Exp $ */ /* * Copyright (c) 2013, 2014, 2015 Mark Kettenis * Copyright (c) 2017 Martin Pieuchot @@ -2304,7 +2304,8 @@ request_firmware(const struct firmware **fw, const char *name, struct device *device) { int r; - struct firmware *f = malloc(sizeof(struct firmware), M_DRM, M_WAITOK); + struct firmware *f = malloc(sizeof(struct firmware), M_DRM, + M_WAITOK | M_ZERO); *fw = f; r = loadfirmware(name, __DECONST(u_char **, &f->data), &f->size); if (r != 0) @@ -2318,7 +2319,8 @@ request_firmware(const struct firmware **fw, const char *name, static inline void release_firmware(const struct firmware *fw) { - free(__DECONST(u_char *, fw->data), M_DRM, fw->size); + if (fw) + free(__DECONST(u_char *, fw->data), M_DEVBUF, fw->size); free(__DECONST(struct firmware *, fw), M_DRM, sizeof(*fw)); } |