diff options
author | Scott Long <scottl@nvidia.com> | 2018-07-02 20:57:21 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-07-30 22:55:16 -0400 |
commit | d32692ae2427693daf85b3c7b4e24cd36471dec6 (patch) | |
tree | b1bb9c697c636847e12afd956b666241176cc1d4 /drivers/gpu/nvgpu/include | |
parent | d9956443820d64ac7f6e2fe7a9d10c1ac4956938 (diff) |
gpu: nvgpu: fix MISRA Rule 11.6 issue with _THIS_IP_
The use of the _THIS_IP_ macro in nvgpu introduces two separate
MISRA Rule 11.6 violations.
The first is when when the label address (which gcc generates as
a void *) is cast to an unsigned long and the second is when that
unsigned long is cast back to a void * in the timer and kmem code
that track the value.
Skipping the intermediate use of unsigned long eliminates these
violations. To do this, references to _THIS_IP_ are replaced
with a new (compliant) _NVGPU_GET_IP_ macro.
JIRA NVGPU-895 : MISRA Rule 11.6 violations
Change-Id: I5ea999d8e2b467257fa190b485fa971adcbd0a2b
Signed-off-by: Scott Long <scottl@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1774531
Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Adeel Raza <araza@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/kmem.h | 19 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h | 23 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h | 10 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/timers.h | 5 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/utils.h | 6 |
5 files changed, 31 insertions, 32 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/kmem.h index 91574ce0..852f6f8a 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/kmem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/kmem.h | |||
@@ -24,13 +24,7 @@ | |||
24 | #define __NVGPU_KMEM_H__ | 24 | #define __NVGPU_KMEM_H__ |
25 | 25 | ||
26 | #include <nvgpu/types.h> | 26 | #include <nvgpu/types.h> |
27 | 27 | #include <nvgpu/utils.h> | |
28 | /* | ||
29 | * Incase this isn't defined already. | ||
30 | */ | ||
31 | #ifndef _THIS_IP_ | ||
32 | #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) | ||
33 | #endif | ||
34 | 28 | ||
35 | struct gk20a; | 29 | struct gk20a; |
36 | 30 | ||
@@ -125,7 +119,7 @@ void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr); | |||
125 | * | 119 | * |
126 | * This function may sleep so cannot be used in IRQs. | 120 | * This function may sleep so cannot be used in IRQs. |
127 | */ | 121 | */ |
128 | #define nvgpu_kmalloc(g, size) __nvgpu_kmalloc(g, size, _THIS_IP_) | 122 | #define nvgpu_kmalloc(g, size) __nvgpu_kmalloc(g, size, _NVGPU_GET_IP_) |
129 | 123 | ||
130 | /** | 124 | /** |
131 | * nvgpu_kzalloc - Allocate from the kernel's allocator. | 125 | * nvgpu_kzalloc - Allocate from the kernel's allocator. |
@@ -136,7 +130,7 @@ void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr); | |||
136 | * Identical to nvgpu_kalloc() except the memory will be zeroed before being | 130 | * Identical to nvgpu_kalloc() except the memory will be zeroed before being |
137 | * returned. | 131 | * returned. |
138 | */ | 132 | */ |
139 | #define nvgpu_kzalloc(g, size) __nvgpu_kzalloc(g, size, _THIS_IP_) | 133 | #define nvgpu_kzalloc(g, size) __nvgpu_kzalloc(g, size, _NVGPU_GET_IP_) |
140 | 134 | ||
141 | /** | 135 | /** |
142 | * nvgpu_kcalloc - Allocate from the kernel's allocator. | 136 | * nvgpu_kcalloc - Allocate from the kernel's allocator. |
@@ -148,7 +142,8 @@ void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr); | |||
148 | * Identical to nvgpu_kalloc() except the size of the memory chunk returned is | 142 | * Identical to nvgpu_kalloc() except the size of the memory chunk returned is |
149 | * @n * @size. | 143 | * @n * @size. |
150 | */ | 144 | */ |
151 | #define nvgpu_kcalloc(g, n, size) __nvgpu_kcalloc(g, n, size, _THIS_IP_) | 145 | #define nvgpu_kcalloc(g, n, size) \ |
146 | __nvgpu_kcalloc(g, n, size, _NVGPU_GET_IP_) | ||
152 | 147 | ||
153 | /** | 148 | /** |
154 | * nvgpu_vmalloc - Allocate memory and return a map to it. | 149 | * nvgpu_vmalloc - Allocate memory and return a map to it. |
@@ -164,7 +159,7 @@ void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr); | |||
164 | * | 159 | * |
165 | * This function may sleep. | 160 | * This function may sleep. |
166 | */ | 161 | */ |
167 | #define nvgpu_vmalloc(g, size) __nvgpu_vmalloc(g, size, _THIS_IP_) | 162 | #define nvgpu_vmalloc(g, size) __nvgpu_vmalloc(g, size, _NVGPU_GET_IP_) |
168 | 163 | ||
169 | /** | 164 | /** |
170 | * nvgpu_vzalloc - Allocate memory and return a map to it. | 165 | * nvgpu_vzalloc - Allocate memory and return a map to it. |
@@ -174,7 +169,7 @@ void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr); | |||
174 | * | 169 | * |
175 | * Identical to nvgpu_vmalloc() except this will return zero'ed memory. | 170 | * Identical to nvgpu_vmalloc() except this will return zero'ed memory. |
176 | */ | 171 | */ |
177 | #define nvgpu_vzalloc(g, size) __nvgpu_vzalloc(g, size, _THIS_IP_) | 172 | #define nvgpu_vzalloc(g, size) __nvgpu_vzalloc(g, size, _NVGPU_GET_IP_) |
178 | 173 | ||
179 | /** | 174 | /** |
180 | * nvgpu_kfree - Frees an alloc from nvgpu_kmalloc, nvgpu_kzalloc, | 175 | * nvgpu_kfree - Frees an alloc from nvgpu_kmalloc, nvgpu_kzalloc, |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h index 611854f2..660aac9f 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/kmem.h | |||
@@ -21,14 +21,11 @@ struct gk20a; | |||
21 | struct device; | 21 | struct device; |
22 | 22 | ||
23 | #ifdef CONFIG_NVGPU_TRACK_MEM_USAGE | 23 | #ifdef CONFIG_NVGPU_TRACK_MEM_USAGE |
24 | void *__nvgpu_track_vmalloc(struct gk20a *g, unsigned long size, | 24 | void *__nvgpu_track_vmalloc(struct gk20a *g, unsigned long size, void *ip); |
25 | unsigned long ip); | 25 | void *__nvgpu_track_vzalloc(struct gk20a *g, unsigned long size, void *ip); |
26 | void *__nvgpu_track_vzalloc(struct gk20a *g, unsigned long size, | 26 | void *__nvgpu_track_kmalloc(struct gk20a *g, size_t size, void *ip); |
27 | unsigned long ip); | 27 | void *__nvgpu_track_kzalloc(struct gk20a *g, size_t size, void *ip); |
28 | void *__nvgpu_track_kmalloc(struct gk20a *g, size_t size, unsigned long ip); | 28 | void *__nvgpu_track_kcalloc(struct gk20a *g, size_t n, size_t size, void *ip); |
29 | void *__nvgpu_track_kzalloc(struct gk20a *g, size_t size, unsigned long ip); | ||
30 | void *__nvgpu_track_kcalloc(struct gk20a *g, size_t n, size_t size, | ||
31 | unsigned long ip); | ||
32 | void __nvgpu_track_vfree(struct gk20a *g, void *addr); | 29 | void __nvgpu_track_vfree(struct gk20a *g, void *addr); |
33 | void __nvgpu_track_kfree(struct gk20a *g, void *addr); | 30 | void __nvgpu_track_kfree(struct gk20a *g, void *addr); |
34 | #endif | 31 | #endif |
@@ -39,11 +36,11 @@ void __nvgpu_track_kfree(struct gk20a *g, void *addr); | |||
39 | * These are the Linux implementations of the various kmem functions defined by | 36 | * These are the Linux implementations of the various kmem functions defined by |
40 | * nvgpu. This should not be included directly - instead include <nvgpu/kmem.h>. | 37 | * nvgpu. This should not be included directly - instead include <nvgpu/kmem.h>. |
41 | */ | 38 | */ |
42 | void *__nvgpu_kmalloc(struct gk20a *g, size_t size, unsigned long ip); | 39 | void *__nvgpu_kmalloc(struct gk20a *g, size_t size, void *ip); |
43 | void *__nvgpu_kzalloc(struct gk20a *g, size_t size, unsigned long ip); | 40 | void *__nvgpu_kzalloc(struct gk20a *g, size_t size, void *ip); |
44 | void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, unsigned long ip); | 41 | void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, void *ip); |
45 | void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, unsigned long ip); | 42 | void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, void *ip); |
46 | void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, unsigned long ip); | 43 | void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, void *ip); |
47 | void __nvgpu_kfree(struct gk20a *g, void *addr); | 44 | void __nvgpu_kfree(struct gk20a *g, void *addr); |
48 | void __nvgpu_vfree(struct gk20a *g, void *addr); | 45 | void __nvgpu_vfree(struct gk20a *g, void *addr); |
49 | 46 | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h index 483ac3b3..efcdd3d5 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h | |||
@@ -25,11 +25,11 @@ | |||
25 | 25 | ||
26 | #include <nvgpu/types.h> | 26 | #include <nvgpu/types.h> |
27 | 27 | ||
28 | void *__nvgpu_kmalloc(struct gk20a *g, size_t size, unsigned long ip); | 28 | void *__nvgpu_kmalloc(struct gk20a *g, size_t size, void *ip); |
29 | void *__nvgpu_kzalloc(struct gk20a *g, size_t size, unsigned long ip); | 29 | void *__nvgpu_kzalloc(struct gk20a *g, size_t size, void *ip); |
30 | void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, unsigned long ip); | 30 | void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, void *ip); |
31 | void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, unsigned long ip); | 31 | void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, void *ip); |
32 | void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, unsigned long ip); | 32 | void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, void *ip); |
33 | void __nvgpu_kfree(struct gk20a *g, void *addr); | 33 | void __nvgpu_kfree(struct gk20a *g, void *addr); |
34 | void __nvgpu_vfree(struct gk20a *g, void *addr); | 34 | void __nvgpu_vfree(struct gk20a *g, void *addr); |
35 | 35 | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/timers.h b/drivers/gpu/nvgpu/include/nvgpu/timers.h index 83dd8d78..20becfdd 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/timers.h +++ b/drivers/gpu/nvgpu/include/nvgpu/timers.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #define __NVGPU_TIMERS_H__ | 24 | #define __NVGPU_TIMERS_H__ |
25 | 25 | ||
26 | #include <nvgpu/types.h> | 26 | #include <nvgpu/types.h> |
27 | #include <nvgpu/utils.h> | ||
27 | 28 | ||
28 | struct gk20a; | 29 | struct gk20a; |
29 | 30 | ||
@@ -85,10 +86,10 @@ int nvgpu_timeout_init(struct gk20a *g, struct nvgpu_timeout *timeout, | |||
85 | int nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout); | 86 | int nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout); |
86 | 87 | ||
87 | #define nvgpu_timeout_expired(__timeout) \ | 88 | #define nvgpu_timeout_expired(__timeout) \ |
88 | __nvgpu_timeout_expired_msg(__timeout, (void *)_THIS_IP_, "") | 89 | __nvgpu_timeout_expired_msg(__timeout, _NVGPU_GET_IP_, "") |
89 | 90 | ||
90 | #define nvgpu_timeout_expired_msg(__timeout, fmt, args...) \ | 91 | #define nvgpu_timeout_expired_msg(__timeout, fmt, args...) \ |
91 | __nvgpu_timeout_expired_msg(__timeout, (void *)_THIS_IP_, \ | 92 | __nvgpu_timeout_expired_msg(__timeout, _NVGPU_GET_IP_, \ |
92 | fmt, ##args) | 93 | fmt, ##args) |
93 | 94 | ||
94 | /* | 95 | /* |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/utils.h b/drivers/gpu/nvgpu/include/nvgpu/utils.h index 22102fa3..6184608a 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/utils.h +++ b/drivers/gpu/nvgpu/include/nvgpu/utils.h | |||
@@ -49,4 +49,10 @@ static inline u32 get_field(u32 reg, u32 mask) | |||
49 | { | 49 | { |
50 | return (reg & mask); | 50 | return (reg & mask); |
51 | } | 51 | } |
52 | |||
53 | /* | ||
54 | * MISRA Rule 11.6 compliant IP address generator. | ||
55 | */ | ||
56 | #define _NVGPU_GET_IP_ ({ __label__ __here; __here: &&__here; }) | ||
57 | |||
52 | #endif /* NVGPU_UTILS_H */ | 58 | #endif /* NVGPU_UTILS_H */ |