diff --git a/drivers/gpu/nvgpu/include/nvgpu/bug.h b/drivers/gpu/nvgpu/include/nvgpu/bug.h index 3d139b757..c458af58a 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/bug.h +++ b/drivers/gpu/nvgpu/include/nvgpu/bug.h @@ -30,4 +30,33 @@ #include #endif +/* + * Define an assert macro that code within nvgpu can use. + * + * The goal of this macro is for debugging but what that means varies from OS + * to OS. On Linux wee don't want to BUG() for general driver misbehaving. BUG() + * is a very heavy handed tool - in fact there's probably no where within the + * nvgpu core code where it makes sense to use a BUG() when running under Linux. + * + * However, on QNX (and POSIX) BUG() will just kill the current process. This + * means we can use it for handling bugs in nvgpu. + * + * As a result this macro varies depending on platform. + */ +#if defined(__KERNEL__) +#define nvgpu_assert(cond) WARN_ON(!(cond)) +#elif defined(__NVGPU_POSIX__) +/* + * A static inline for POSIX so that we can hide the branch in BUG_ON() from the + * branch analysis for users of this function. When this assert fails the + * function will not return. + */ +static inline void nvgpu_assert(bool cond) +{ + BUG_ON(!cond); +} +#else +#define nvgpu_assert(cond) BUG_ON(!(cond)) +#endif + #endif /* NVGPU_BUG_H */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h index b17447568..0dcb37a33 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h @@ -26,10 +26,6 @@ #include #include -/* - * TODO: make these actually useful! - */ - #define BUG() __bug("") #define BUG_ON(cond) \ do { \