diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-04-18 12:05:32 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-04-18 12:05:32 +0000 |
commit | 6862b05c0d9851243d727fa0edfa95a0781e29d5 (patch) | |
tree | a45dad26519abf4db4b9d48f7c0c702c56acfa59 /sys/dev/pci/drm | |
parent | cf44a1e630aa06f1485c7612221d487cc6e41898 (diff) |
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().
Diffstat (limited to 'sys/dev/pci/drm')
-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)); } |