devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Add a couple of string-related functions
@ 2015-07-16 11:10 Thierry Reding
       [not found] ` <1437045021-4549-1-git-send-email-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Thierry Reding @ 2015-07-16 11:10 UTC (permalink / raw)
  To: David Gibson, Jon Loeliger
  Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, Simon Glass,
	Masahiro Yamada

From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

These three patches add a couple of string functions that have proven
useful in U-Boot's copy of libfdt, so they are likely to be useful for
other users as well.

Patch 1 adds a function to count the number of strings in a property's
value. This also adds a new DTS sample along with a small test program
to validate the implemented functions.

Patch 2 adds a function to retrieve the index of a given string in any
given property's value. This adds code to the test program introduced in
the previous patch to exercise the new functionality.

Patch 3 adds a function to retrieve a string by index from a property's
value along with a shortcut for index 0. This extends the test program
introduced in patch 1 to validate the new functionality.

Changes in v2:
- Safely handle non-NUL-terminated values. Uses strnlen() instead of
  strlen() to restrict accesses to the property value.
- Return FDT_ERR_BADVALUE if a non-NUL-terminated value is detected.
  Note that for performance reasons this doesn't always work. Cell or
  byte properties can look very much like NUL-terminated strings. The
  fdt_find_string() and fdt_get_string_index() functions can return a
  valid index or string, respectively, because they don't look at the
  complete value to determine validity. This could of course be fixed
  but the cases in which this succeeds the user did ask for trouble,
  so I didn't think it worth the extra effort.
- Improve documentation and tests.

Thierry

Thierry Reding (3):
  fdt: Add a function to count strings
  fdt: Add a function to get the index of a string
  fdt: Add functions to retrieve strings

 libfdt/fdt_ro.c      |  92 ++++++++++++++++++++++++++++++
 libfdt/libfdt.h      |  82 ++++++++++++++++++++++++++-
 tests/.gitignore     |   1 +
 tests/Makefile.tests |   1 +
 tests/run_tests.sh   |   3 +
 tests/strings.c      | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/strings.dts    |  12 ++++
 7 files changed, 344 insertions(+), 1 deletion(-)
 create mode 100644 tests/strings.c
 create mode 100644 tests/strings.dts

-- 
2.4.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-09-29  9:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-16 11:10 [PATCH v2 0/3] Add a couple of string-related functions Thierry Reding
     [not found] ` <1437045021-4549-1-git-send-email-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-07-16 11:10   ` [PATCH v2 1/3] fdt: Add a function to count strings Thierry Reding
     [not found]     ` <1437045021-4549-2-git-send-email-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-29  5:53       ` David Gibson
     [not found]         ` <20150929055313.GP19428-1s0os16eZneny3qCrzbmXA@public.gmane.org>
2015-09-29  8:32           ` Thierry Reding
2015-07-16 11:10   ` [PATCH v2 2/3] fdt: Add a function to get the index of a string Thierry Reding
     [not found]     ` <1437045021-4549-3-git-send-email-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-29  5:54       ` David Gibson
     [not found]         ` <20150929055446.GQ19428-1s0os16eZneny3qCrzbmXA@public.gmane.org>
2015-09-29  8:32           ` Thierry Reding
2015-07-16 11:10   ` [PATCH v2 3/3] fdt: Add functions to retrieve strings Thierry Reding
     [not found]     ` <1437045021-4549-4-git-send-email-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-29  6:00       ` David Gibson
     [not found]         ` <20150929060041.GR19428-1s0os16eZneny3qCrzbmXA@public.gmane.org>
2015-09-29  9:10           ` Thierry Reding
2015-09-29  5:50   ` [PATCH v2 0/3] Add a couple of string-related functions David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).