1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/build_bug.h>
3 #include <linux/errno.h>
4 #include <linux/errname.h>
5 #include <linux/kernel.h>
6 #include <linux/math.h>
9 * Ensure these tables do not accidentally become gigantic if some
10 * huge errno makes it in. On most architectures, the first table will
11 * only have about 140 entries, but mips and parisc have more sparsely
12 * allocated errnos (with EHWPOISON = 257 on parisc, and EDQUOT = 1133
13 * on mips), so this wastes a bit of space on those - though we
14 * special case the EDQUOT case.
16 #define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
17 static const char *names_0[] = {
24 E(EAGAIN), /* EWOULDBLOCK */
35 E(ECANCELED), /* ECANCELLED */
40 E(ECONNREFUSED), /* EREFUSED */
42 E(EDEADLK), /* EDEADLOCK */
43 #if EDEADLK != EDEADLOCK /* mips, sparc, powerpc */
147 #ifdef EREMOTERELEASE
175 #ifdef EREFUSED /* parisc */
176 static_assert(EREFUSED == ECONNREFUSED);
178 #ifdef ECANCELLED /* parisc */
179 static_assert(ECANCELLED == ECANCELED);
181 static_assert(EAGAIN == EWOULDBLOCK); /* everywhere */
183 #define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = "-" #err
184 static const char *names_512[] = {
189 E(ERESTART_RESTARTBLOCK),
207 static const char *__errname(unsigned err)
209 if (err < ARRAY_SIZE(names_0))
211 if (err >= 512 && err - 512 < ARRAY_SIZE(names_512))
212 return names_512[err - 512];
214 if (IS_ENABLED(CONFIG_MIPS) && err == EDQUOT) /* 1133 */
220 * errname(EIO) -> "EIO"
221 * errname(-EIO) -> "-EIO"
223 const char *errname(int err)
225 const char *name = __errname(abs(err));
229 return err > 0 ? name + 1 : name;