Skip to content

Commit 0546a29

Browse files
drm/i915/cmdparser: Use explicit goto for error paths
In the next patch we will be adding a second valid termination condition which will require a small amount of refactoring to share logic with the BB_END case. Refactor all error conditions to jump to a dedicated exit path, with 'break' reserved only for a successful parse. Cc: Tony Luck <[email protected]> Cc: Dave Airlie <[email protected]> Cc: Takashi Iwai <[email protected]> Cc: Tyler Hicks <[email protected]> Signed-off-by: Jon Bloomfield <[email protected]> Reviewed-by: Chris Wilson <[email protected]>
1 parent 0f2f397 commit 0546a29

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/gpu/drm/i915/i915_cmd_parser.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,21 +1338,15 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
13381338
do {
13391339
u32 length;
13401340

1341-
if (*cmd == MI_BATCH_BUFFER_END) {
1342-
if (needs_clflush_after) {
1343-
void *ptr = page_mask_bits(shadow_batch_obj->mm.mapping);
1344-
drm_clflush_virt_range(ptr,
1345-
(void *)(cmd + 1) - ptr);
1346-
}
1341+
if (*cmd == MI_BATCH_BUFFER_END)
13471342
break;
1348-
}
13491343

13501344
desc = find_cmd(engine, *cmd, desc, &default_desc);
13511345
if (!desc) {
13521346
DRM_DEBUG_DRIVER("CMD: Unrecognized command: 0x%08X\n",
13531347
*cmd);
13541348
ret = -EINVAL;
1355-
break;
1349+
goto err;
13561350
}
13571351

13581352
/*
@@ -1362,7 +1356,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
13621356
*/
13631357
if (desc->cmd.value == MI_BATCH_BUFFER_START) {
13641358
ret = -EACCES;
1365-
break;
1359+
goto err;
13661360
}
13671361

13681362
if (desc->flags & CMD_DESC_FIXED)
@@ -1376,22 +1370,29 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
13761370
length,
13771371
batch_end - cmd);
13781372
ret = -EINVAL;
1379-
break;
1373+
goto err;
13801374
}
13811375

13821376
if (!check_cmd(engine, desc, cmd, length)) {
13831377
ret = -EACCES;
1384-
break;
1378+
goto err;
13851379
}
13861380

13871381
cmd += length;
13881382
if (cmd >= batch_end) {
13891383
DRM_DEBUG_DRIVER("CMD: Got to the end of the buffer w/o a BBE cmd!\n");
13901384
ret = -EINVAL;
1391-
break;
1385+
goto err;
13921386
}
13931387
} while (1);
13941388

1389+
if (needs_clflush_after) {
1390+
void *ptr = page_mask_bits(shadow_batch_obj->mm.mapping);
1391+
1392+
drm_clflush_virt_range(ptr, (void *)(cmd + 1) - ptr);
1393+
}
1394+
1395+
err:
13951396
i915_gem_object_unpin_map(shadow_batch_obj);
13961397
return ret;
13971398
}

0 commit comments

Comments
 (0)