Module Name: src Committed By: riastradh Date: Sun Dec 19 12:33:42 UTC 2021
Modified Files: src/sys/external/bsd/drm2/linux: linux_dma_resv.c Log Message: drm: Paranoia: handle fencep=null, fence!=null, and 0 shared. Not sure this is possible but I don't know the API well enough to prove it can't happen. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/external/bsd/drm2/linux/linux_dma_resv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/drm2/linux/linux_dma_resv.c diff -u src/sys/external/bsd/drm2/linux/linux_dma_resv.c:1.19 src/sys/external/bsd/drm2/linux/linux_dma_resv.c:1.20 --- src/sys/external/bsd/drm2/linux/linux_dma_resv.c:1.19 Sun Dec 19 12:33:34 2021 +++ src/sys/external/bsd/drm2/linux/linux_dma_resv.c Sun Dec 19 12:33:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_dma_resv.c,v 1.19 2021/12/19 12:33:34 riastradh Exp $ */ +/* $NetBSD: linux_dma_resv.c,v 1.20 2021/12/19 12:33:42 riastradh Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_dma_resv.c,v 1.19 2021/12/19 12:33:34 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_dma_resv.c,v 1.20 2021/12/19 12:33:42 riastradh Exp $"); #include <sys/param.h> #include <sys/poll.h> @@ -758,7 +758,7 @@ dma_resv_get_fences_rcu(const struct dma const struct dma_resv_list *list = NULL; struct dma_fence *fence = NULL; struct dma_fence **shared = NULL; - unsigned shared_alloc, shared_count, i; + unsigned shared_alloc = 0, shared_count, i; struct dma_resv_read_ticket ticket; top: KASSERT(fence == NULL); @@ -851,11 +851,19 @@ top: KASSERT(fence == NULL); /* Success! */ rcu_read_unlock(); + KASSERT(shared_count <= shared_alloc); + KASSERT(shared_alloc == 0 || shared_count < shared_alloc); + KASSERT(shared_alloc <= UINT_MAX); if (fencep) { *fencep = fence; } else if (fence) { - KASSERT(shared_count < UINT_MAX); - shared[shared_count++] = fence; + if (shared_count) { + shared[shared_count++] = fence; + } else { + shared = kmalloc(sizeof(shared[0]), GFP_KERNEL); + shared[0] = fence; + shared_count = 1; + } } *nsharedp = shared_count; *sharedp = shared;