mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
log: Add a way to log error-return values
When functions return an error it propagates up the stack to the point where it is reported. Often the error code provides enough information about the root cause of the error that this is obvious what went wrong. However in some cases the error may be hard to trace. For example if a driver uses several devices to perform an operation, it may not be obvious which one failed. Add a log_ret() macro to help with this. This can be used to wrap any error-return value. The logging system will then output a log record when the original error is generated, making it easy to trace the call stack of the error. This macro can significantly impact code size, so its use is controlled by a Kconfig option, which is enabled for sandbox. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
8cb7c04248
commit
3707c6ee0d
4 changed files with 33 additions and 0 deletions
|
@ -159,6 +159,17 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
|
|||
({ if (!(x) && _DEBUG) \
|
||||
__assert_fail(#x, __FILE__, __LINE__, __func__); })
|
||||
|
||||
#ifdef CONFIG_LOG_ERROR_RETURN
|
||||
#define log_ret(_ret) ({ \
|
||||
int __ret = (_ret); \
|
||||
if (__ret < 0) \
|
||||
log(LOG_CATEGORY, LOGL_ERR, "returning err=%d\n", __ret); \
|
||||
__ret; \
|
||||
})
|
||||
#else
|
||||
#define log_ret(_ret) (_ret)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* struct log_rec - a single log record
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue