summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/rbtree.c
diff options
context:
space:
mode:
authorSrirangan <smadhavan@nvidia.com>2018-08-20 05:13:41 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-08-23 00:55:49 -0400
commit3fbaee7099039eee84343027dd1ce20679c0c113 (patch)
tree0de4934723f58cad9cdcdb642927ffce0cfac6d8 /drivers/gpu/nvgpu/common/rbtree.c
parent52305f0514d29e7fb2cb5e2154188e09faa3fe94 (diff)
gpu: nvgpu: common: Fix MISRA 15.6 violations
MISRA Rule-15.6 requires that all if-else blocks be enclosed in braces, including single statement blocks. Fix errors due to single statement if blocks without braces, introducing the braces. JIRA NVGPU-671 Change-Id: I4d9933c51a297a725f48cbb15520a70494d74aeb Signed-off-by: Srirangan <smadhavan@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1800833 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/rbtree.c')
-rw-r--r--drivers/gpu/nvgpu/common/rbtree.c70
1 files changed, 44 insertions, 26 deletions
diff --git a/drivers/gpu/nvgpu/common/rbtree.c b/drivers/gpu/nvgpu/common/rbtree.c
index 86bab688..a0e97ee9 100644
--- a/drivers/gpu/nvgpu/common/rbtree.c
+++ b/drivers/gpu/nvgpu/common/rbtree.c
@@ -32,16 +32,18 @@ static void rotate_left(struct nvgpu_rbtree_node **root,
32 32
33 /* establish x->right link */ 33 /* establish x->right link */
34 x->right = y->left; 34 x->right = y->left;
35 if (y->left) 35 if (y->left) {
36 y->left->parent = x; 36 y->left->parent = x;
37 }
37 38
38 /* establish y->parent link */ 39 /* establish y->parent link */
39 y->parent = x->parent; 40 y->parent = x->parent;
40 if (x->parent) { 41 if (x->parent) {
41 if (x == x->parent->left) 42 if (x == x->parent->left) {
42 x->parent->left = y; 43 x->parent->left = y;
43 else 44 } else {
44 x->parent->right = y; 45 x->parent->right = y;
46 }
45 } else { 47 } else {
46 *root = y; 48 *root = y;
47 } 49 }
@@ -61,16 +63,18 @@ static void rotate_right(struct nvgpu_rbtree_node **root,
61 63
62 /* establish x->left link */ 64 /* establish x->left link */
63 x->left = y->right; 65 x->left = y->right;
64 if (y->right) 66 if (y->right) {
65 y->right->parent = x; 67 y->right->parent = x;
68 }
66 69
67 /* establish y->parent link */ 70 /* establish y->parent link */
68 y->parent = x->parent; 71 y->parent = x->parent;
69 if (x->parent) { 72 if (x->parent) {
70 if (x == x->parent->right) 73 if (x == x->parent->right) {
71 x->parent->right = y; 74 x->parent->right = y;
72 else 75 } else {
73 x->parent->left = y; 76 x->parent->left = y;
77 }
74 } else { 78 } else {
75 *root = y; 79 *root = y;
76 } 80 }
@@ -149,12 +153,13 @@ void nvgpu_rbtree_insert(struct nvgpu_rbtree_node *new_node,
149 153
150 while (curr) { 154 while (curr) {
151 parent = curr; 155 parent = curr;
152 if (new_node->key_start < curr->key_start) 156 if (new_node->key_start < curr->key_start) {
153 curr = curr->left; 157 curr = curr->left;
154 else if (new_node->key_start > curr->key_start) 158 } else if (new_node->key_start > curr->key_start) {
155 curr = curr->right; 159 curr = curr->right;
156 else 160 } else {
157 return; /* duplicate entry */ 161 return; /* duplicate entry */
162 }
158 } 163 }
159 164
160 /* the caller allocated the node already, just fix the links */ 165 /* the caller allocated the node already, just fix the links */
@@ -165,10 +170,11 @@ void nvgpu_rbtree_insert(struct nvgpu_rbtree_node *new_node,
165 170
166 /* insert node in tree */ 171 /* insert node in tree */
167 if (parent) { 172 if (parent) {
168 if (new_node->key_start < parent->key_start) 173 if (new_node->key_start < parent->key_start) {
169 parent->left = new_node; 174 parent->left = new_node;
170 else 175 } else {
171 parent->right = new_node; 176 parent->right = new_node;
177 }
172 } else { 178 } else {
173 *root = new_node; 179 *root = new_node;
174 } 180 }
@@ -203,8 +209,9 @@ static void _delete_fixup(struct nvgpu_rbtree_node **root,
203 209
204 if (!w || ((!w->left || !w->left->is_red) 210 if (!w || ((!w->left || !w->left->is_red)
205 && (!w->right || !w->right->is_red))) { 211 && (!w->right || !w->right->is_red))) {
206 if (w) 212 if (w) {
207 w->is_red = true; 213 w->is_red = true;
214 }
208 x = parent_of_x; 215 x = parent_of_x;
209 } else { 216 } else {
210 if (!w->right || !w->right->is_red) { 217 if (!w->right || !w->right->is_red) {
@@ -231,8 +238,9 @@ static void _delete_fixup(struct nvgpu_rbtree_node **root,
231 238
232 if (!w || ((!w->right || !w->right->is_red) 239 if (!w || ((!w->right || !w->right->is_red)
233 && (!w->left || !w->left->is_red))) { 240 && (!w->left || !w->left->is_red))) {
234 if (w) 241 if (w) {
235 w->is_red = true; 242 w->is_red = true;
243 }
236 x = parent_of_x; 244 x = parent_of_x;
237 } else { 245 } else {
238 if (!w->left || !w->left->is_red) { 246 if (!w->left || !w->left->is_red) {
@@ -251,8 +259,9 @@ static void _delete_fixup(struct nvgpu_rbtree_node **root,
251 parent_of_x = x->parent; 259 parent_of_x = x->parent;
252 } 260 }
253 261
254 if (x) 262 if (x) {
255 x->is_red = false; 263 x->is_red = false;
264 }
256} 265}
257 266
258void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node, 267void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
@@ -279,21 +288,24 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
279 } 288 }
280 289
281 /* x is y's only child */ 290 /* x is y's only child */
282 if (y->left) 291 if (y->left) {
283 x = y->left; 292 x = y->left;
284 else 293 } else {
285 x = y->right; 294 x = y->right;
295 }
286 296
287 /* remove y from the parent chain */ 297 /* remove y from the parent chain */
288 parent_of_x = y->parent; 298 parent_of_x = y->parent;
289 if (x) 299 if (x) {
290 x->parent = parent_of_x; 300 x->parent = parent_of_x;
301 }
291 302
292 if (y->parent) { 303 if (y->parent) {
293 if (y == y->parent->left) 304 if (y == y->parent->left) {
294 y->parent->left = x; 305 y->parent->left = x;
295 else 306 } else {
296 y->parent->right = x; 307 y->parent->right = x;
308 }
297 } else { 309 } else {
298 *root = x; 310 *root = x;
299 } 311 }
@@ -305,10 +317,11 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
305 */ 317 */
306 y->parent = z->parent; 318 y->parent = z->parent;
307 if (z->parent) { 319 if (z->parent) {
308 if (z == z->parent->left) 320 if (z == z->parent->left) {
309 z->parent->left = y; 321 z->parent->left = y;
310 else 322 } else {
311 z->parent->right = y; 323 z->parent->right = y;
324 }
312 } else { 325 } else {
313 *root = y; 326 *root = y;
314 } 327 }
@@ -316,19 +329,23 @@ void nvgpu_rbtree_unlink(struct nvgpu_rbtree_node *node,
316 y->is_red = z->is_red; 329 y->is_red = z->is_red;
317 330
318 y->left = z->left; 331 y->left = z->left;
319 if (z->left) 332 if (z->left) {
320 z->left->parent = y; 333 z->left->parent = y;
334 }
321 335
322 y->right = z->right; 336 y->right = z->right;
323 if (z->right) 337 if (z->right) {
324 z->right->parent = y; 338 z->right->parent = y;
339 }
325 340
326 if (parent_of_x == z) 341 if (parent_of_x == z) {
327 parent_of_x = y; 342 parent_of_x = y;
343 }
328 } 344 }
329 345
330 if (y_was_black) 346 if (y_was_black) {
331 _delete_fixup(root, parent_of_x, x); 347 _delete_fixup(root, parent_of_x, x);
348 }
332} 349}
333 350
334void nvgpu_rbtree_search(u64 key_start, struct nvgpu_rbtree_node **node, 351void nvgpu_rbtree_search(u64 key_start, struct nvgpu_rbtree_node **node,
@@ -427,8 +444,9 @@ void nvgpu_rbtree_enum_next(struct nvgpu_rbtree_node **node,
427 } else { 444 } else {
428 /* go up until we find the right inorder node */ 445 /* go up until we find the right inorder node */
429 for (curr = curr->parent; curr; curr = curr->parent) { 446 for (curr = curr->parent; curr; curr = curr->parent) {
430 if (curr->key_start > (*node)->key_start) 447 if (curr->key_start > (*node)->key_start) {
431 break; 448 break;
449 }
432 } 450 }
433 } 451 }
434 } 452 }