summaryrefslogtreecommitdiff
path: root/include/linux/errname.h
blob: dd39fe7120bb367706384cccccb6409d87fa6113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_ERRNAME_H
#define _LINUX_ERRNAME_H

#include <linux/stddef.h>

#ifdef CONFIG_SYMBOLIC_ERRNAME

const char *errname(int err);

#include <linux/codetag.h>

struct codetag_error_code {
	const char		*str;
	int			err;
};

/**
 * ERR - return an error code that records the error site
 *
 * E.g., instead of
 *   return -ENOMEM;
 * Use
 *   return -ERR(ENOMEM);
 *
 * Then, when a caller prints out the error with errname(), the error string
 * will include the file and line number.
 */
#define ERR(_err)							\
({									\
	static struct codetag_error_code				\
	__used								\
	__section("error_code_tags")					\
	__aligned(8) e = {						\
		.str	= #_err " at " __FILE__ ":" __stringify(__LINE__),\
		.err	= _err,						\
	};								\
									\
	e.err;								\
})

int error_class(int err);
bool error_matches(int err, int class);

#else

static inline int error_class(int err)
{
	return err;
}

static inline bool error_matches(int err, int class)
{
	return err == class;
}

#define ERR(_err)	_err

static inline const char *errname(int err)
{
	return NULL;
}

#endif

#endif /* _LINUX_ERRNAME_H */