From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Subject: [PATCH v3 0/3] Add a couple of string-related functions Date: Tue, 29 Sep 2015 11:09:05 +0200 Message-ID: <1443517748-27819-1-git-send-email-thierry.reding@gmail.com> Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=wgEoNeMXoqBB4UbHfVaxGu1NSo9W9k2oQDLYLqMMhlo=; b=mS4ZIj4UPsQ/cCZcCNxlNm5FXryGZG/Hgx+L7obKmr3fSJoweAqCzJtHjuYroo7JmR 1EQmnVQRsLwE/zgQD7rYey3VuKxciR+7Tp9VXVR3YqA1ip1JJrIjGFQ+nwGzrUrgiI6Q 1/qBhg+GR5ryDALzjdRdwGio0845p64h7geJkGR6jSjcMAxGhHJPm+TFBY07RldTKfAN fd0SWSFRxodMni9VWmCIzMwUHwaql+u+fmc57G1GQ2oXBjHhK4WnQkmYj8DyfmnEGPTI HQZ4g2TcXCCIbHRk40PKJ6FlgIUlnQleZexkZo5aJXkfXkqse/8UAv2ykz6zqIGNGayp R4JA== Sender: devicetree-compiler-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: David Gibson , Jon Loeliger Cc: Simon Glass , Masahiro Yamada , devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org From: Thierry Reding 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. This extends the test program introduced in patch 1 to validate the new functionality. Changes in v3: - Rename functions and rework prototypes to be more in line with the existing API. - Remove shortcut for fdt_stringlist_get() with index 0 to discourage users from taking shortcuts when parsing lists of strings. 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 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 | 100 +++++++++++++++++++++++++++++++++ libfdt/libfdt.h | 69 ++++++++++++++++++++++- tests/.gitignore | 1 + tests/Makefile.tests | 1 + tests/run_tests.sh | 3 + tests/strings.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/strings.dts | 12 ++++ 7 files changed, 339 insertions(+), 1 deletion(-) create mode 100644 tests/strings.c create mode 100644 tests/strings.dts -- 2.5.0