Date: Sun, 10 May 2015 12:45:21 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282725 - head/sys/dev/usb/video Message-ID: <201505101245.t4ACjL3i010933@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Sun May 10 12:45:21 2015 New Revision: 282725 URL: https://svnweb.freebsd.org/changeset/base/282725 Log: Put recycle pointer in own memory area which is not mmap'able. Modified: head/sys/dev/usb/video/udl.c Modified: head/sys/dev/usb/video/udl.c ============================================================================== --- head/sys/dev/usb/video/udl.c Sun May 10 12:41:34 2015 (r282724) +++ head/sys/dev/usb/video/udl.c Sun May 10 12:45:21 2015 (r282725) @@ -203,12 +203,14 @@ udl_buffer_alloc(uint32_t size) } mtx_unlock(&udl_buffer_mtx); if (buf != NULL) { + uint8_t *ptr = ((uint8_t *)buf) - size; /* wipe and recycle buffer */ - memset(buf, 0, size); - return (buf); + memset(ptr, 0, size); + /* return buffer pointer */ + return (ptr); } /* allocate new buffer */ - return (malloc(size, M_USB_DL, M_WAITOK | M_ZERO)); + return (malloc(size + sizeof(*buf), M_USB_DL, M_WAITOK | M_ZERO)); } static void @@ -216,9 +218,11 @@ udl_buffer_free(void *_buf, uint32_t siz { struct udl_buffer *buf; - buf = (struct udl_buffer *)_buf; - if (buf == NULL) + /* check for NULL pointer */ + if (_buf == NULL) return; + /* compute pointer to recycle list */ + buf = (struct udl_buffer *)(((uint8_t *)_buf) + size); /* * Memory mapped buffers should never be freed.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505101245.t4ACjL3i010933>