fdt_strerror.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
  2. /*
  3. * libfdt - Flat Device Tree manipulation
  4. * Copyright (C) 2006 David Gibson, IBM Corporation.
  5. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6. */
  7. #include "libfdt_env.h"
  8. #include <fdt.h>
  9. #include <libfdt.h>
  10. #include "libfdt_internal.h"
  11. struct fdt_errtabent {
  12. const char *str;
  13. };
  14. #define FDT_ERRTABENT(val) \
  15. [(val)] = { .str = #val, }
  16. static struct fdt_errtabent fdt_errtable[] = {
  17. FDT_ERRTABENT(FDT_ERR_NOTFOUND),
  18. FDT_ERRTABENT(FDT_ERR_EXISTS),
  19. FDT_ERRTABENT(FDT_ERR_NOSPACE),
  20. FDT_ERRTABENT(FDT_ERR_BADOFFSET),
  21. FDT_ERRTABENT(FDT_ERR_BADPATH),
  22. FDT_ERRTABENT(FDT_ERR_BADPHANDLE),
  23. FDT_ERRTABENT(FDT_ERR_BADSTATE),
  24. FDT_ERRTABENT(FDT_ERR_TRUNCATED),
  25. FDT_ERRTABENT(FDT_ERR_BADMAGIC),
  26. FDT_ERRTABENT(FDT_ERR_BADVERSION),
  27. FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),
  28. FDT_ERRTABENT(FDT_ERR_BADLAYOUT),
  29. FDT_ERRTABENT(FDT_ERR_INTERNAL),
  30. FDT_ERRTABENT(FDT_ERR_BADNCELLS),
  31. FDT_ERRTABENT(FDT_ERR_BADVALUE),
  32. FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
  33. FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
  34. FDT_ERRTABENT(FDT_ERR_BADFLAGS),
  35. FDT_ERRTABENT(FDT_ERR_ALIGNMENT),
  36. };
  37. #define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0])))
  38. const char *fdt_strerror(int errval)
  39. {
  40. if (errval > 0)
  41. return "<valid offset/length>";
  42. else if (errval == 0)
  43. return "<no error>";
  44. else if (-errval < FDT_ERRTABSIZE) {
  45. const char *s = fdt_errtable[-errval].str;
  46. if (s)
  47. return s;
  48. }
  49. return "<unknown error>";
  50. }