From 04cf2f1ba68bdac074805d6c1ec9c3444ec5558a Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Fri, 31 May 2019 13:19:40 -0700 Subject: [PATCH] gpu: nvgpu: unit: add unit_assert helper Add unit_assert helper to check condition. In case of failure, the macro reports failed condition as well as line number, then runs bail out code. Jira NVGPU-3476 Change-Id: I9971e7fa0337661d46a06dfa05b67a98e3c46eee Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/2129675 GVS: Gerrit_Virtual_Submit Reviewed-by: Deepak Nibade Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/include/unit/io.h | 15 +++++++++++++++ userspace/units/fifo/tsg/nvgpu-tsg.c | 6 +----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/userspace/include/unit/io.h b/userspace/include/unit/io.h index 1fd0fa432..ffe22a41e 100644 --- a/userspace/include/unit/io.h +++ b/userspace/include/unit/io.h @@ -60,6 +60,21 @@ struct unit_module; #define unit_err(unit, msg, ...) \ __unit_info_color(unit, C_RED, msg, ##__VA_ARGS__) + +/* + * helper to check a condition, output and error if condition is false + * and execute bail_out_code +*/ +#define unit_assert(cond, bail_out_code) \ +do { \ + if (!(cond)) { \ + unit_err(m, "%s:%d (" #cond ") is false\n", \ + __func__, __LINE__); \ + bail_out_code; \ + } \ +} while (0) + + /* * Don't go overboard with these!!! */ diff --git a/userspace/units/fifo/tsg/nvgpu-tsg.c b/userspace/units/fifo/tsg/nvgpu-tsg.c index eaed682d9..9db08fccc 100644 --- a/userspace/units/fifo/tsg/nvgpu-tsg.c +++ b/userspace/units/fifo/tsg/nvgpu-tsg.c @@ -55,11 +55,7 @@ } while (0) #endif -struct test_tsg_args { - bool init_done; - struct nvgpu_tsg *tsg; - struct nvgpu_channel *ch; -}; +#define assert(cond) unit_assert(cond, goto done) struct test_tsg_args test_args = { .init_done = false,