brcm2708: update linux 4.4 patches to latest version
[librecmc/librecmc.git] / target / linux / brcm2708 / patches-4.4 / 0275-drm-vc4-copy_to_user-returns-the-number-of-bytes-rem.patch
1 From 543efa41ce1be43b927ddbb6c999063f8f4f9caa Mon Sep 17 00:00:00 2001
2 From: Dan Carpenter <dan.carpenter@oracle.com>
3 Date: Thu, 17 Dec 2015 15:36:28 +0300
4 Subject: [PATCH 275/304] drm/vc4: copy_to_user() returns the number of bytes
5  remaining
6
7 The copy_to/from_user() functions return the number of bytes remaining
8 to be copied.  We want to return error codes here.
9
10 Also it's a bad idea to print an error message if a copy from user fails
11 because users can use that to spam /var/log/messages which is annoying
12 so I removed those.
13
14 Fixes: 214613656b51 ('drm/vc4: Add an interface for capturing the GPU state after a hang.')
15 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
16 Reviewed-by: Eric Anholt <eric@anholt.net>
17 (cherry picked from commit 65c4777de54a39b2722a4b1ff3306d044014d511)
18 ---
19  drivers/gpu/drm/vc4/vc4_gem.c | 37 ++++++++++++++++++-------------------
20  1 file changed, 18 insertions(+), 19 deletions(-)
21
22 --- a/drivers/gpu/drm/vc4/vc4_gem.c
23 +++ b/drivers/gpu/drm/vc4/vc4_gem.c
24 @@ -85,7 +85,7 @@ vc4_get_hang_state_ioctl(struct drm_devi
25         struct vc4_dev *vc4 = to_vc4_dev(dev);
26         unsigned long irqflags;
27         u32 i;
28 -       int ret;
29 +       int ret = 0;
30  
31         spin_lock_irqsave(&vc4->job_lock, irqflags);
32         kernel_state = vc4->hang_state;
33 @@ -133,9 +133,11 @@ vc4_get_hang_state_ioctl(struct drm_devi
34                 bo_state[i].size = vc4_bo->base.base.size;
35         }
36  
37 -       ret = copy_to_user((void __user *)(uintptr_t)get_state->bo,
38 -                          bo_state,
39 -                          state->bo_count * sizeof(*bo_state));
40 +       if (copy_to_user((void __user *)(uintptr_t)get_state->bo,
41 +                        bo_state,
42 +                        state->bo_count * sizeof(*bo_state)))
43 +               ret = -EFAULT;
44 +
45         kfree(bo_state);
46  
47  err_free:
48 @@ -563,27 +565,24 @@ vc4_get_bcl(struct drm_device *dev, stru
49         exec->shader_state = temp + exec_size;
50         exec->shader_state_size = args->shader_rec_count;
51  
52 -       ret = copy_from_user(bin,
53 -                            (void __user *)(uintptr_t)args->bin_cl,
54 -                            args->bin_cl_size);
55 -       if (ret) {
56 -               DRM_ERROR("Failed to copy in bin cl\n");
57 +       if (copy_from_user(bin,
58 +                          (void __user *)(uintptr_t)args->bin_cl,
59 +                          args->bin_cl_size)) {
60 +               ret = -EFAULT;
61                 goto fail;
62         }
63  
64 -       ret = copy_from_user(exec->shader_rec_u,
65 -                            (void __user *)(uintptr_t)args->shader_rec,
66 -                            args->shader_rec_size);
67 -       if (ret) {
68 -               DRM_ERROR("Failed to copy in shader recs\n");
69 +       if (copy_from_user(exec->shader_rec_u,
70 +                          (void __user *)(uintptr_t)args->shader_rec,
71 +                          args->shader_rec_size)) {
72 +               ret = -EFAULT;
73                 goto fail;
74         }
75  
76 -       ret = copy_from_user(exec->uniforms_u,
77 -                            (void __user *)(uintptr_t)args->uniforms,
78 -                            args->uniforms_size);
79 -       if (ret) {
80 -               DRM_ERROR("Failed to copy in uniforms cl\n");
81 +       if (copy_from_user(exec->uniforms_u,
82 +                          (void __user *)(uintptr_t)args->uniforms,
83 +                          args->uniforms_size)) {
84 +               ret = -EFAULT;
85                 goto fail;
86         }
87