0d3b4520d319233eb1b04f87d569cafb0dbd31bf
[openwrt/staging/noltari.git] /
1 From 5537bac0e5c8f3634c5595c21c7d63f0c0263e0e Mon Sep 17 00:00:00 2001
2 From: Boris Brezillon <boris.brezillon@free-electrons.com>
3 Date: Wed, 22 Nov 2017 21:39:28 +0100
4 Subject: [PATCH 175/454] drm/vc4: Fix false positive WARN() backtrace on
5 refcount_inc() usage
6
7 With CONFIG_REFCOUNT_FULL enabled, refcount_inc() complains when it's
8 passed a refcount object that has its counter set to 0. In this driver,
9 this is a valid use case since we want to increment ->usecnt only when
10 the BO object starts to be used by real HW components and this is
11 definitely not the case when the BO is created.
12
13 Fix the problem by using refcount_inc_not_zero() instead of
14 refcount_inc() and fallback to refcount_set(1) when
15 refcount_inc_not_zero() returns false. Note that this 2-steps operation
16 is not racy here because the whole section is protected by a mutex
17 which guarantees that the counter does not change between the
18 refcount_inc_not_zero() and refcount_set() calls.
19
20 Fixes: b9f19259b84d ("drm/vc4: Add the DRM_IOCTL_VC4_GEM_MADVISE ioctl")
21 Reported-by: Stefan Wahren <stefan.wahren@i2se.com>
22 Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
23 Acked-by: Eric Anholt <eric@anholt.net>
24 Link: https://patchwork.freedesktop.org/patch/msgid/20171122203928.28135-1-boris.brezillon@free-electrons.com
25 (cherry picked from commit 5bfd40139d55790cbc8e56ad1ce4f974f1fa186d)
26 ---
27 drivers/gpu/drm/vc4/vc4_bo.c | 3 ++-
28 1 file changed, 2 insertions(+), 1 deletion(-)
29
30 --- a/drivers/gpu/drm/vc4/vc4_bo.c
31 +++ b/drivers/gpu/drm/vc4/vc4_bo.c
32 @@ -639,7 +639,8 @@ int vc4_bo_inc_usecnt(struct vc4_bo *bo)
33 mutex_lock(&bo->madv_lock);
34 switch (bo->madv) {
35 case VC4_MADV_WILLNEED:
36 - refcount_inc(&bo->usecnt);
37 + if (!refcount_inc_not_zero(&bo->usecnt))
38 + refcount_set(&bo->usecnt, 1);
39 ret = 0;
40 break;
41 case VC4_MADV_DONTNEED: