log: Add return-checking macros for 0 being success

The existing log_ret() and log_msg_ret() macros consider an error to be
less than zero. But some function may return a positive number to indicate
a different kind of failure. Add macros to check for that also.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2021-01-20 20:10:54 -07:00 committed by Tom Rini
parent 9ad7a6c25c
commit 7bd06587de
2 changed files with 34 additions and 1 deletions

View file

@ -316,10 +316,30 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
__ret); \
__ret; \
})
/*
* Similar to the above, but any non-zero value is consider an error, not just
* values less than 0.
*/
#define log_retz(_ret) ({ \
int __ret = (_ret); \
if (__ret) \
log(LOG_CATEGORY, LOGL_ERR, "returning err=%d\n", __ret); \
__ret; \
})
#define log_msg_retz(_msg, _ret) ({ \
int __ret = (_ret); \
if (__ret) \
log(LOG_CATEGORY, LOGL_ERR, "%s: returning err=%d\n", _msg, \
__ret); \
__ret; \
})
#else
/* Non-logging versions of the above which just return the error code */
#define log_ret(_ret) (_ret)
#define log_msg_ret(_msg, _ret) ((void)(_msg), _ret)
#define log_retz(_ret) (_ret)
#define log_msg_retz(_msg, _ret) ((void)(_msg), _ret)
#endif
/** * enum log_rec_flags - Flags for a log record */