of: change overlay apply input data from unflattened
Subsystems (2)
v3 cover of: change overlay apply input data from unflattened
From: Frank Rowand <frank.rowand-7U/[email protected]>
Move duplicating and unflattening of an overlay flattened devicetree (FDT) into the overlay application code. To accomplish this, of_overlay_apply() is replaced by of_overlay_fdt_apply().
The copy of the FDT (aka "duplicate FDT") now belongs to devicetree code, which is thus responsible for freeing the duplicate FDT. The caller of of_overlay_fdt_apply() remains responsible for freeing the original FDT.
The unflattened devicetree now belongs to devicetree code, which is thus responsible for freeing the unflattened devicetree.
These ownership changes prevent early freeing of the duplicated FDT or the unflattened devicetree, which could result in use after free errors.
These changes led to migrating some unittest overlay data into their own devicetree source files, and then converting most of them to use sugar syntax instead of hand coding fragments.
Changes from v2:
- improve error messages in patch 4/4, as suggested by Geert
Changes from v1:
- rebase on v4.16-rc1
- update documentation
- split out error message to a separate patch
Frank Rowand (4):
of: change overlay apply input data from unflattened to FDT
of: Documentation: of_overlay_apply() replaced by
of_overlay_fdt_apply()
of: convert unittest overlay devicetree source to sugar syntax
of: improve reporting invalid overlay target path
Documentation/devicetree/overlay-notes.txt | 4 +- drivers/of/of_private.h | 1 + drivers/of/overlay.c | 129 ++++++++-- drivers/of/resolver.c | 6 - drivers/of/unittest-data/Makefile | 28 ++- drivers/of/unittest-data/overlay.dts | 101 ++++---- drivers/of/unittest-data/overlay_0.dts | 14 ++ drivers/of/unittest-data/overlay_1.dts | 14 ++ drivers/of/unittest-data/overlay_10.dts | 27 +++ drivers/of/unittest-data/overlay_11.dts | 28 +++ drivers/of/unittest-data/overlay_12.dts | 14 ++ drivers/of/unittest-data/overlay_13.dts | 14 ++ drivers/of/unittest-data/overlay_15.dts | 30 +++ drivers/of/unittest-data/overlay_2.dts | 9 + drivers/of/unittest-data/overlay_3.dts | 9 + drivers/of/unittest-data/overlay_4.dts | 18 ++ drivers/of/unittest-data/overlay_5.dts | 9 + drivers/of/unittest-data/overlay_6.dts | 10 + drivers/of/unittest-data/overlay_7.dts | 10 + drivers/of/unittest-data/overlay_8.dts | 10 + drivers/of/unittest-data/overlay_9.dts | 10 + drivers/of/unittest-data/overlay_bad_phandle.dts | 23 +- drivers/of/unittest-data/overlay_bad_symbol.dts | 25 +- drivers/of/unittest-data/tests-overlay.dtsi | 217 +---------------- drivers/of/unittest.c | 294 +++++++++++------------ include/linux/of.h | 7 - 26 files changed, 574 insertions(+), 487 deletions(-) create mode 100644 drivers/of/unittest-data/overlay_0.dts create mode 100644 drivers/of/unittest-data/overlay_1.dts create mode 100644 drivers/of/unittest-data/overlay_10.dts create mode 100644 drivers/of/unittest-data/overlay_11.dts create mode 100644 drivers/of/unittest-data/overlay_12.dts create mode 100644 drivers/of/unittest-data/overlay_13.dts create mode 100644 drivers/of/unittest-data/overlay_15.dts create mode 100644 drivers/of/unittest-data/overlay_2.dts create mode 100644 drivers/of/unittest-data/overlay_3.dts create mode 100644 drivers/of/unittest-data/overlay_4.dts create mode 100644 drivers/of/unittest-data/overlay_5.dts create mode 100644 drivers/of/unittest-data/overlay_6.dts create mode 100644 drivers/of/unittest-data/overlay_7.dts create mode 100644 drivers/of/unittest-data/overlay_8.dts create mode 100644 drivers/of/unittest-data/overlay_9.dts
Signature · 6 lines
Frank Rowand <frank.rowand-7U/[email protected]> -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 1/4 of: change overlay apply input data from unflattened to FDT
From: Frank Rowand <[email protected]>
Move duplicating and unflattening of an overlay flattened devicetree (FDT) into the overlay application code. To accomplish this, of_overlay_apply() is replaced by of_overlay_fdt_apply().
The copy of the FDT (aka "duplicate FDT") now belongs to devicetree code, which is thus responsible for freeing the duplicate FDT. The caller of of_overlay_fdt_apply() remains responsible for freeing the original FDT.
The unflattened devicetree now belongs to devicetree code, which is thus responsible for freeing the unflattened devicetree.
These ownership changes prevent early freeing of the duplicated FDT or the unflattened devicetree, which could result in use after free errors.
of_overlay_fdt_apply() is a private function for the anticipated overlay loader.
Update unittest.c to use of_overlay_fdt_apply() instead of of_overlay_apply().
Move overlay fragments from artificial locations in drivers/of/unittest-data/tests-overlay.dtsi into one devicetree source file per overlay. This led to changes in drivers/of/unitest-data/Makefile and drivers/of/unitest.c.
- Add overlay directives to the overlay devicetree source files so that dtc will compile them as true overlays into one FDT data chunk per overlay.
- Set CFLAGS for drivers/of/unittest-data/testcases.dts so that symbols will be generated for overlay resolution of overlays that are no longer artificially contained in testcases.dts
- Unflatten and apply each unittest overlay FDT using
of_overlay_fdt_apply().
- Enable the of_resolve_phandles() check for whether the unflattened overlay is detached. This check was previously disabled because the overlays from tests-overlay.dtsi were not unflattened into detached trees.
- Other changes to unittest.c infrastructure to manage multiple test FDTs built into the kernel image (access by name instead of arbitrary number).
- of_unittest_overlay_high_level(): previously unused code to add properties from the overlay_base devicetree to the live tree was triggered by the restructuring of tests-overlay.dtsi and thus testcases.dts. This exposed two bugs: (1) the need to dup a property before adding it, and (2) property 'name' is auto-generated in the unflatten code and thus will be a duplicate in the __symbols__ node - do not treat this duplicate as an error.
---
There are checkpatch warnings. I have reviewed them and feel they can be ignored. They are "line over 80 characters" for either pre-existing long lines, or lines in devicetree source files.
drivers/of/of_private.h | 1 + drivers/of/overlay.c | 107 +++++++++- drivers/of/resolver.c | 6 - drivers/of/unittest-data/Makefile | 28 ++- drivers/of/unittest-data/overlay_0.dts | 14 ++ drivers/of/unittest-data/overlay_1.dts | 14 ++ drivers/of/unittest-data/overlay_10.dts | 34 ++++ drivers/of/unittest-data/overlay_11.dts | 34 ++++ drivers/of/unittest-data/overlay_12.dts | 14 ++ drivers/of/unittest-data/overlay_13.dts | 14 ++ drivers/of/unittest-data/overlay_15.dts | 35 ++++ drivers/of/unittest-data/overlay_2.dts | 14 ++ drivers/of/unittest-data/overlay_3.dts | 14 ++ drivers/of/unittest-data/overlay_4.dts | 23 +++ drivers/of/unittest-data/overlay_5.dts | 14 ++ drivers/of/unittest-data/overlay_6.dts | 15 ++ drivers/of/unittest-data/overlay_7.dts | 15 ++ drivers/of/unittest-data/overlay_8.dts | 15 ++ drivers/of/unittest-data/overlay_9.dts | 15 ++ drivers/of/unittest-data/tests-overlay.dtsi | 213 -------------------- drivers/of/unittest.c | 294 ++++++++++++++-------------- include/linux/of.h | 7 - 22 files changed, 551 insertions(+), 389 deletions(-) create mode 100644 drivers/of/unittest-data/overlay_0.dts create mode 100644 drivers/of/unittest-data/overlay_1.dts create mode 100644 drivers/of/unittest-data/overlay_10.dts create mode 100644 drivers/of/unittest-data/overlay_11.dts create mode 100644 drivers/of/unittest-data/overlay_12.dts create mode 100644 drivers/of/unittest-data/overlay_13.dts create mode 100644 drivers/of/unittest-data/overlay_15.dts create mode 100644 drivers/of/unittest-data/overlay_2.dts create mode 100644 drivers/of/unittest-data/overlay_3.dts create mode 100644 drivers/of/unittest-data/overlay_4.dts create mode 100644 drivers/of/unittest-data/overlay_5.dts create mode 100644 drivers/of/unittest-data/overlay_6.dts create mode 100644 drivers/of/unittest-data/overlay_7.dts create mode 100644 drivers/of/unittest-data/overlay_8.dts create mode 100644 drivers/of/unittest-data/overlay_9.dts
drivers/of/of_private.h +1 -0
@@ -77,6 +77,7 @@ static inline void __of_detach_node_sysfs(struct device_node *np) {}#endif #if defined(CONFIG_OF_OVERLAY ) +int of_overlay_fdt_apply (void *overlay_fdt,int *ovcs_id);void of_overlay_mutex_lock (void );void of_overlay_mutex_unlock (void );#else
drivers/of/overlay.c +98 -9
204 lines not on this page · raw message
drivers/of/resolver.c +0 -6
@@ -269,17 +269,11 @@ int of_resolve_phandles(struct device_node *overlay) goto out; } -#if 0 - Temporarily disable check so that old style overlay unittests - do not fail when of_resolve_phandles() is moved into - of_overlay_apply(). -if (!of_node_check_flag (overlay,OF_DETACHED )) {pr_err ("overlay not detached\n" ); err = -EINVAL ; goto out; } -#endif phandle_delta =live_tree_max_phandle () +1 ;adjust_overlay_phandles (overlay, phandle_delta);
drivers/of/unittest-data/Makefile +23 -5
@@ -1,8 +1,22 @@ # SPDX-License-Identifier: GPL-2.0 -DTC_FLAGS_testcases := -Wno-interrupts_property obj-y += testcases.dtb.o obj-$(CONFIG_OF_OVERLAY) += overlay.dtb.o \ + overlay_0.dtb.o \ + overlay_1.dtb.o \ + overlay_2.dtb.o \ + overlay_3.dtb.o \ + overlay_4.dtb.o \ + overlay_5.dtb.o \ + overlay_6.dtb.o \ + overlay_7.dtb.o \ + overlay_8.dtb.o \ + overlay_9.dtb.o \ + overlay_10.dtb.o \ + overlay_11.dtb.o \ + overlay_12.dtb.o \ + overlay_13.dtb.o \ + overlay_15.dtb.o \ overlay_bad_phandle.dtb.o \ overlay_bad_symbol.dtb.o \ overlay_base.dtb.o
@@ -10,10 +24,14 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtb.o \ targets += $(foreach suffix, dtb dtb.S, $(patsubst %.dtb.o,%.$(suffix),$(obj-y))) # enable creation of __symbols__ node -DTC_FLAGS_overlay := -@ -DTC_FLAGS_overlay_bad_phandle := -@ -DTC_FLAGS_overlay_bad_symbol := -@ -DTC_FLAGS_overlay_base := -@ +DTC_FLAGS_overlay += -@ +DTC_FLAGS_overlay_bad_phandle += -@ +DTC_FLAGS_overlay_bad_symbol += -@ +DTC_FLAGS_overlay_base += -@ +DTC_FLAGS_testcases += -@ + +# suppress warnings about intentional errors +DTC_FLAGS_testcases += -Wno-interrupts_property .PRECIOUS: \ $(obj)/%.dtb.S \
drivers/of/unittest-data/overlay_0.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_0 - enable using absolute target path */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest0"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_1.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_1 - disable using absolute target path */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest1"; + __overlay__ { + status = "disabled"; + }; + }; +};
drivers/of/unittest-data/overlay_10.dts new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_10 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus"; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-unittest10 { + compatible = "unittest"; + status = "okay"; + reg = <10>; + + #address-cells = <1>; + #size-cells = <0>; + + test-unittest101 { + compatible = "unittest"; + status = "okay"; + reg = <1>; + }; + + }; + }; + }; +};
drivers/of/unittest-data/overlay_11.dts new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_11 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus"; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-unittest11 { + compatible = "unittest"; + status = "okay"; + reg = <11>; + + #address-cells = <1>; + #size-cells = <0>; + + test-unittest111 { + compatible = "unittest"; + status = "okay"; + reg = <1>; + }; + + }; + }; + }; +};
drivers/of/unittest-data/overlay_12.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_12 - enable using absolute target path (i2c) */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_13.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_13 - disable using absolute target path (i2c) */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13"; + __overlay__ { + status = "disabled"; + }; + }; +};
drivers/of/unittest-data/overlay_15.dts new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_15 - mux overlay */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/i2c-test-bus"; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + test-unittest15 { + reg = <11>; + compatible = "unittest-i2c-mux"; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + i2c@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + + test-mux-dev { + reg = <32>; + compatible = "unittest-i2c-dev"; + status = "okay"; + }; + }; + }; + }; + }; +};
drivers/of/unittest-data/overlay_2.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_2 - enable using label */ + + fragment@0 { + target = <&unittest2>; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_3.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_3 - disable using label */ + + fragment@0 { + target = <&unittest3>; + __overlay__ { + status = "disabled"; + }; + }; +};
drivers/of/unittest-data/overlay_4.dts new file +23 -0
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_4 - test insertion of a full node */ + + fragment@0 { + target = <&unittestbus>; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-unittest4 { + compatible = "unittest"; + status = "okay"; + reg = <4>; + }; + }; + }; +};
drivers/of/unittest-data/overlay_5.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_5 - test overlay apply revert */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest5"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_6.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_6 */ + /* overlays 6, 7 application and removal in sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest6"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_7.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_7 */ + /* overlays 6, 7 application and removal in sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest7"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_8.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_8 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_9.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_9 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; + __overlay__ { + property-foo = "bar"; + }; + }; +};
drivers/of/unittest-data/tests-overlay.dtsi +0 -213
218 lines not on this page · raw message
drivers/of/unittest.c +145 -149
575 lines not on this page · raw message
include/linux/of.h +0 -7
@@ -1359,8 +1359,6 @@ struct of_overlay_notify_data {#ifdef CONFIG_OF_OVERLAY -/* ID based overlays; the API for external users */ -int of_overlay_apply (struct device_node *tree,int *ovcs_id);int of_overlay_remove (int *ovcs_id);int of_overlay_remove_all (void );
@@ -1369,11 +1367,6 @@ struct of_overlay_notify_data {#else -static inline int of_overlay_apply (struct device_node *tree,int *ovcs_id) -{ -return -ENOTSUPP ; -} -static inline int of_overlay_remove (int *ovcs_id) {return -ENOTSUPP ;
Signature · 1 line
Frank Rowand <[email protected]>
kbuild test robot
build botRe: [PATCH v3 1/4] of: change overlay apply input data from unflattened to FDT
I love your patch! Yet something to improve:
Hi Frank,
I love your patch! Yet something to improve:
[auto build test ERROR on robh/for-next]
[also build test ERROR on v4.16-rc1 next-20180216]
[cannot apply to glikely/devicetree/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/frowand-list-gmail-com/of-change-overlay-apply-input-data-from-unflattened/20180218-095108 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: i386-randconfig-x018-201807 (attached as .config) compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
drivers/of/overlay.c: In function 'of_overlay_fdt_apply':
>> drivers/of/overlay.c:832:2: error: implicit declaration of function 'of_fdt_unflatten_tree' [-Werror=implicit-function-declaration]
of_fdt_unflatten_tree(new_fdt, NULL, &overlay_root);
^~~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/of_fdt_unflatten_tree +832 drivers/of/overlay.c
806
807 int of_overlay_fdt_apply(void *overlay_fdt, int *ovcs_id)
808 {
809 const void *new_fdt;
810 int ret;
811 u32 size;
812 struct device_node *overlay_root;
813
814 *ovcs_id = 0;
815 ret = 0;
816
817 if (fdt_check_header(overlay_fdt)) {
818 pr_err("Invalid overlay_fdt header\n");
819 return -EINVAL;
820 }
821
822 size = fdt_totalsize(overlay_fdt);
823
824 /*
825 * Must create permanent copy of FDT because of_fdt_unflatten_tree()
826 * will create pointers to the passed in FDT in the unflattened tree.
827 */
828 new_fdt = kmemdup(overlay_fdt, size, GFP_KERNEL);
829 if (!new_fdt)
830 return -ENOMEM;
831
> 832 of_fdt_unflatten_tree(new_fdt, NULL, &overlay_root);
833 if (!overlay_root) {
834 pr_err("unable to unflatten overlay_fdt\n");
835 ret = -EINVAL;
836 goto out_free_new_fdt;
837 }
838
839 ret = of_overlay_apply(new_fdt, overlay_root, ovcs_id);
840 if (ret < 0) {
841 /*
842 * new_fdt and overlay_root now belong to the overlay
843 * changeset.
844 * overlay changeset code is responsible for freeing them.
845 */
846 goto out;
847 }
848
849 return 0;
850
851
852 out_free_new_fdt:
853 kfree(new_fdt);
854
855 out:
856 return ret;
857 }
858 EXPORT_SYMBOL_GPL(of_overlay_fdt_apply);
859
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v3 2/4 of: Documentation: of_overlay_apply() replaced by of_overlay_fdt_apply()
In reply to [email protected]From: Frank Rowand <frank.rowand-7U/[email protected]>
--- Documentation/devicetree/overlay-notes.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/overlay-notes.txt +2 -2
@@ -87,8 +87,8 @@ Overlay in-kernel API The API is quite easy to use. -1. Call of_overlay_apply() to create and apply an overlay changeset. The return -value is an error or a cookie identifying this overlay. +1. Call of_overlay_fdt_apply() to create and apply an overlay changeset. The +return value is an error or a cookie identifying this overlay. 2. Call of_overlay_remove() to remove and cleanup the overlay changeset previously created via the call to of_overlay_apply(). Removal of an overlay
Signature · 6 lines
Frank Rowand <frank.rowand-7U/[email protected]> -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 3/4 of: convert unittest overlay devicetree source to sugar syntax
In reply to [email protected]From: Frank Rowand <[email protected]>
The unittest-data overlays have been pulled into proper overlay devicetree source files without changing their format. The next step is to convert them to use sugar syntax instead of hand coding overlay fragments structure.
A few of the overlays can not be converted because they test absolute target paths in the overlay fragment. dtc does not generate this type of target:
overlay_0.dts
overlay_1.dts
overlay_12.dts
overlay_13.dts
Two pre-existing unittest overlay devicetree source files are also converted:
overlay_bad_phandle.dts
overlay_bad_symbol.dts
---
There are checkpatch warnings. I have reviewed them and feel they can be ignored. They are pre-existing warnings of un-documented bindings of made up (fake) compatibles in devicetree source for test overlays.
drivers/of/unittest-data/overlay.dts | 101 ++++++++++------------- drivers/of/unittest-data/overlay_10.dts | 39 ++++----- drivers/of/unittest-data/overlay_11.dts | 40 ++++----- drivers/of/unittest-data/overlay_15.dts | 41 ++++----- drivers/of/unittest-data/overlay_2.dts | 11 +-- drivers/of/unittest-data/overlay_3.dts | 11 +-- drivers/of/unittest-data/overlay_4.dts | 23 ++---- drivers/of/unittest-data/overlay_5.dts | 11 +-- drivers/of/unittest-data/overlay_6.dts | 13 +-- drivers/of/unittest-data/overlay_7.dts | 13 +-- drivers/of/unittest-data/overlay_8.dts | 13 +-- drivers/of/unittest-data/overlay_9.dts | 13 +-- drivers/of/unittest-data/overlay_bad_phandle.dts | 23 ++---- drivers/of/unittest-data/overlay_bad_symbol.dts | 25 ++---- drivers/of/unittest-data/tests-overlay.dtsi | 4 +- 15 files changed, 148 insertions(+), 233 deletions(-)
drivers/of/unittest-data/overlay.dts +44 -57
@@ -2,76 +2,63 @@ /dts-v1/; /plugin/; -/ { +&electric_1 { - fragment@0 { - target = <&electric_1>; + status = "okay"; - __overlay__ { - status = "okay"; - - hvac_2: hvac-large-1 { - compatible = "ot,hvac-large"; - heat-range = < 40 75 >; - cool-range = < 65 80 >; - }; - }; + hvac_2: hvac-large-1 { + compatible = "ot,hvac-large"; + heat-range = < 40 75 >; + cool-range = < 65 80 >; }; +}; - fragment@1 { - target = <&rides_1>; - - __overlay__ { - #address-cells = <1>; - #size-cells = <1>; - status = "okay"; - - ride@100 { - #address-cells = <1>; - #size-cells = <1>; - - track@30 { - incline-up = < 48 32 16 >; - }; +&rides_1 { - track@40 { - incline-up = < 47 31 15 >; - }; - }; + #address-cells = <1>; + #size-cells = <1>; + status = "okay"; - ride_200: ride@200 { - #address-cells = <1>; - #size-cells = <1>; - compatible = "ot,ferris-wheel"; - reg = < 0x00000200 0x100 >; - hvac-provider = < &hvac_2 >; - hvac-thermostat = < 27 32 > ; - hvac-zones = < 12 5 >; - hvac-zone-names = "operator", "snack-bar"; - spin-controller = < &spin_ctrl_1 3 >; - spin-rph = < 30 >; - gondolas = < 16 >; - gondola-capacity = < 6 >; + ride@100 { + #address-cells = <1>; + #size-cells = <1>; - ride_200_left: track@10 { - reg = < 0x00000010 0x10 >; - }; + track@30 { + incline-up = < 48 32 16 >; + }; - ride_200_right: track@20 { - reg = < 0x00000020 0x10 >; - }; - }; + track@40 { + incline-up = < 47 31 15 >; }; }; - fragment@2 { - target = <&lights_2>; + ride_200: ride@200 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "ot,ferris-wheel"; + reg = < 0x00000200 0x100 >; + hvac-provider = < &hvac_2 >; + hvac-thermostat = < 27 32 > ; + hvac-zones = < 12 5 >; + hvac-zone-names = "operator", "snack-bar"; + spin-controller = < &spin_ctrl_1 3 >; + spin-rph = < 30 >; + gondolas = < 16 >; + gondola-capacity = < 6 >; + + ride_200_left: track@10 { + reg = < 0x00000010 0x10 >; + }; - __overlay__ { - status = "okay"; - color = "purple", "white", "red", "green"; - rate = < 3 256 >; + ride_200_right: track@20 { + reg = < 0x00000020 0x10 >; }; }; +}; + +&lights_2 { + status = "okay"; + color = "purple", "white", "red", "green"; + rate = < 3 256 >; };
drivers/of/unittest-data/overlay_10.dts +16 -23
@@ -2,33 +2,26 @@ /dts-v1/; /plugin/; -/ { - /* overlay_10 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_10 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus"; - __overlay__ { +&unittest_test_bus { + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; - /* suppress DTC warning */ - #address-cells = <1>; - #size-cells = <0>; + test-unittest10 { + compatible = "unittest"; + status = "okay"; + reg = <10>; - test-unittest10 { - compatible = "unittest"; - status = "okay"; - reg = <10>; + #address-cells = <1>; + #size-cells = <0>; - #address-cells = <1>; - #size-cells = <0>; - - test-unittest101 { - compatible = "unittest"; - status = "okay"; - reg = <1>; - }; - - }; + test-unittest101 { + compatible = "unittest"; + status = "okay"; + reg = <1>; }; }; };
drivers/of/unittest-data/overlay_11.dts +17 -23
@@ -2,33 +2,27 @@ /dts-v1/; /plugin/; -/ { - /* overlay_11 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_11 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus"; - __overlay__ { +&unittest_test_bus { + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; - /* suppress DTC warning */ - #address-cells = <1>; - #size-cells = <0>; + test-unittest11 { + compatible = "unittest"; + status = "okay"; + reg = <11>; - test-unittest11 { - compatible = "unittest"; - status = "okay"; - reg = <11>; + #address-cells = <1>; + #size-cells = <0>; - #address-cells = <1>; - #size-cells = <0>; - - test-unittest111 { - compatible = "unittest"; - status = "okay"; - reg = <1>; - }; - - }; + test-unittest111 { + compatible = "unittest"; + status = "okay"; + reg = <1>; }; + }; };
drivers/of/unittest-data/overlay_15.dts +18 -23
51 lines not on this page · raw message
drivers/of/unittest-data/overlay_2.dts +3 -8
@@ -2,13 +2,8 @@ /dts-v1/; /plugin/; -/ { - /* overlay_2 - enable using label */ +/* overlay_2 - enable using label */ - fragment@0 { - target = <&unittest2>; - __overlay__ { - status = "okay"; - }; - }; +&unittest2 { + status = "okay"; };
drivers/of/unittest-data/overlay_3.dts +3 -8
@@ -2,13 +2,8 @@ /dts-v1/; /plugin/; -/ { - /* overlay_3 - disable using label */ +/* overlay_3 - disable using label */ - fragment@0 { - target = <&unittest3>; - __overlay__ { - status = "disabled"; - }; - }; +&unittest3 { + status = "disabled"; };
drivers/of/unittest-data/overlay_4.dts +9 -14
@@ -2,22 +2,17 @@ /dts-v1/; /plugin/; -/ { - /* overlay_4 - test insertion of a full node */ +/* overlay_4 - test insertion of a full node */ - fragment@0 { - target = <&unittestbus>; - __overlay__ { +&unittest_test_bus { - /* suppress DTC warning */ - #address-cells = <1>; - #size-cells = <0>; + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; - test-unittest4 { - compatible = "unittest"; - status = "okay"; - reg = <4>; - }; - }; + test-unittest4 { + compatible = "unittest"; + status = "okay"; + reg = <4>; }; };
drivers/of/unittest-data/overlay_5.dts +3 -8
@@ -2,13 +2,8 @@ /dts-v1/; /plugin/; -/ { - /* overlay_5 - test overlay apply revert */ +/* overlay_5 - test overlay apply revert */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest5"; - __overlay__ { - status = "okay"; - }; - }; +&unittest5 { + status = "okay"; };
drivers/of/unittest-data/overlay_6.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_6 */ - /* overlays 6, 7 application and removal in sequence */ +/* overlay_6 */ +/* overlays 6, 7 application and removal in sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest6"; - __overlay__ { - status = "okay"; - }; - }; +&unittest6 { + status = "okay"; };
drivers/of/unittest-data/overlay_7.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_7 */ - /* overlays 6, 7 application and removal in sequence */ +/* overlay_7 */ +/* overlays 6, 7 application and removal in sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest7"; - __overlay__ { - status = "okay"; - }; - }; +&unittest7 { + status = "okay"; };
drivers/of/unittest-data/overlay_8.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_8 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_8 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; - __overlay__ { - status = "okay"; - }; - }; +&unittest8 { + status = "okay"; };
drivers/of/unittest-data/overlay_9.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_9 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_9 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; - __overlay__ { - property-foo = "bar"; - }; - }; +&unittest8 { + property-foo = "bar"; };
drivers/of/unittest-data/overlay_bad_phandle.dts +8 -15
@@ -2,20 +2,13 @@ /dts-v1/; /plugin/; -/ { - - fragment@0 { - target = <&electric_1>; - - __overlay__ { - - // This label should cause an error when the overlay - // is applied. There is already a phandle value - // in the base tree for motor-1. - spin_ctrl_1_conflict: motor-1 { - accelerate = < 3 >; - decelerate = < 5 >; - }; - }; +&electric_1 { + + // This label should cause an error when the overlay + // is applied. There is already a phandle value + // in the base tree for motor-1. + spin_ctrl_1_conflict: motor-1 { + accelerate = < 3 >; + decelerate = < 5 >; }; };
drivers/of/unittest-data/overlay_bad_symbol.dts +9 -16
@@ -2,22 +2,15 @@ /dts-v1/; /plugin/; -/ { +&electric_1 { - fragment@0 { - target = <&electric_1>; - - __overlay__ { - - // This label should cause an error when the overlay - // is applied. There is already a symbol hvac_1 - // in the base tree - hvac_1: hvac-medium-2 { - compatible = "ot,hvac-medium"; - heat-range = < 50 75 >; - cool-range = < 60 80 >; - }; - - }; + // This label should cause an error when the overlay + // is applied. There is already a symbol hvac_1 + // in the base tree + hvac_1: hvac-medium-2 { + compatible = "ot,hvac-medium"; + heat-range = < 50 75 >; + cool-range = < 60 80 >; }; + };
drivers/of/unittest-data/tests-overlay.dtsi +2 -2
@@ -5,7 +5,7 @@ overlay-node { /* test bus */ - unittestbus: test-bus { + unittest_test_bus: test-bus { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>;
@@ -70,7 +70,7 @@ reg = <8>; }; - i2c-test-bus { + unittest_i2c_test_bus: i2c-test-bus { compatible = "unittest-i2c-bus"; status = "okay"; reg = <50>;
Signature · 1 line
Frank Rowand <[email protected]>
PATCH v3 4/4 of: improve reporting invalid overlay target path
In reply to [email protected]From: Frank Rowand <[email protected]>
Errors while developing the patch to create of_overlay_fdt_apply() exposed inadequate error messages to debug problems when overlay devicetree fragment nodes contain an invalid target path. Improve the messages in find_target_node() to remedy this.
---
changes from v2:
- add fragment node name as suggested by Geert
- existing error message printed short node name, thus not discriminating between fragments; change to full node name
- existing error message printed node address, which is devicetree internal debugging, not useful in an overlay apply error message; remove node address from message
drivers/of/overlay.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/of/overlay.c +16 -6
@@ -488,20 +488,30 @@ static int build_changeset(struct overlay_changeset *ovcs)*/ static struct device_node *find_target_node (struct device_node *info_node) { +struct device_node *node;const char *path;u32 val;int ret; ret =of_property_read_u32 (info_node,"target" , &val); -if (!ret) -return of_find_node_by_phandle (val); +if (!ret) { + node =of_find_node_by_phandle (val); +if (!node) +pr_err ("find target, node: %pOF, phandle 0x%x not found\n" , + info_node, val); +return node; + } ret =of_property_read_string (info_node,"target-path" , &path); -if (!ret) -return of_find_node_by_path (path); +if (!ret) { + node =of_find_node_by_path (path); +if (!node) +pr_err ("find target, node: %pOF, path '%s' not found\n" , + info_node, path); +return node; + } -pr_err ("Failed to find target for node %p (%s)\n" , - info_node, info_node->name); +pr_err ("find target, node: %pOF, no target property\n" , info_node);return NULL ; }
Signature · 1 line
Frank Rowand <[email protected]>
Rob Herring
maintainerRe: [PATCH v3 4/4] of: improve reporting invalid overlay target path
Quoted 31 lines · On Wed, Feb 14, 2018 at 09:35:46PM -0800, [email protected] wrote:
From: Frank Rowand <[email protected]>
Errors while developing the patch to create
of_overlay_fdt_apply()exposed inadequate error messages to debug problems when overlay devicetree fragment nodes contain an invalid target path. Improve the messages infind_target_node()to remedy this.Signed-off-by Frank Rowand <[email protected]>---
changes from v2:
- add fragment node name as suggested by Geert
- existing error message printed short node name, thus not discriminating between fragments; change to full node name
- existing error message printed node address, which is devicetree internal debugging, not useful in an overlay apply error message; remove node address from messagedrivers/of/overlay.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)drivers/of/overlay.c +1
-0@@ -488,20 +488,30 @@ static int build_changeset(struct overlay_changeset *ovcs)*/ static struct device_node *find_target_node (struct device_node *info_node) { +struct device_node *node;const char *path;
drivers/of/overlay.c static int build_changeset(struct overlay_changeset *ovcs) · line 500
Quoted 10 lines
drivers/of/overlay.c +4
-2u32 val;int ret; ret =of_property_read_u32 (info_node,"target" , &val); -if (!ret) -return of_find_node_by_phandle (val); +if (!ret) { + node =of_find_node_by_phandle (val); +if (!node) + pr_err("find target, node: %pOF, phandle 0x%x not found\n",
I'm wondering if the core should print the error rather than having all the callers do it. The question is whether there are cases where failing is okay? I guess sometimes we use 0 to skip cells, but the core handle not printing an error in that case.
Rob
Quoted 24 lines
drivers/of/overlay.c +11
-4+ info_node, val); +return node; + } ret =of_property_read_string (info_node,"target-path" , &path); -if (!ret) -return of_find_node_by_path (path); +if (!ret) { + node =of_find_node_by_path (path); +if (!node) +pr_err ("find target, node: %pOF, path '%s' not found\n" , + info_node, path); +return node; + } -pr_err ("Failed to find target for node %p (%s)\n" , - info_node, info_node->name); +pr_err ("find target, node: %pOF, no target property\n" , info_node);return NULL ; }Signature · 1 line
Frank Rowand <[email protected]>
Re: [PATCH v3 4/4] of: improve reporting invalid overlay target path
Quoted 35 lines · Rob Herring
Quoted 34 lines · On Wed, Feb 14, 2018 at 09:35:46PM -0800, [email protected] wrote:
From: Frank Rowand <[email protected]>
Errors while developing the patch to create
of_overlay_fdt_apply()exposed inadequate error messages to debug problems when overlay devicetree fragment nodes contain an invalid target path. Improve the messages infind_target_node()to remedy this.Signed-off-by Frank Rowand <[email protected]>---
changes from v2:
- add fragment node name as suggested by Geert
- existing error message printed short node name, thus not discriminating between fragments; change to full node name
- existing error message printed node address, which is devicetree internal debugging, not useful in an overlay apply error message; remove node address from messagedrivers/of/overlay.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)drivers/of/overlay.c +1
-0@@ -488,20 +488,30 @@ static int build_changeset(struct overlay_changeset *ovcs)*/ static struct device_node *find_target_node (struct device_node *info_node) { +struct device_node *node;const char *path;u32 val;int ret;
Quoted 12 lines
drivers/of/overlay.c static int build_changeset(struct overlay_changeset *ovcs) · line 500
Quoted 7 lines
drivers/of/overlay.c +4
-2ret =of_property_read_u32 (info_node,"target" , &val); -if (!ret) -return of_find_node_by_phandle (val); +if (!ret) { + node =of_find_node_by_phandle (val); +if (!node) + pr_err("find target, node: %pOF, phandle 0x%x not found\n",I'm wondering if the core should print the error rather than having all the callers do it. The question is whether there are cases where failing is okay? I guess sometimes we use 0 to skip cells, but the core handle not printing an error in that case.
find_target_node() is overlay specific, and is only called from one location in overlay.c.
There are no cases where failing is ok. This is used to find the target node that an overlay fragment is being applied to. If it fails then either the base devicetree or the overlay devicetree has an error.
-Frank
Quoted 27 lines
Rob
Quoted 24 lines
drivers/of/overlay.c +11
-4+ info_node, val); +return node; + } ret =of_property_read_string (info_node,"target-path" , &path); -if (!ret) -return of_find_node_by_path (path); +if (!ret) { + node =of_find_node_by_path (path); +if (!node) +pr_err ("find target, node: %pOF, path '%s' not found\n" , + info_node, path); +return node; + } -pr_err ("Failed to find target for node %p (%s)\n" , - info_node, info_node->name); +pr_err ("find target, node: %pOF, no target property\n" , info_node);return NULL ; }Signature · 1 line
Frank Rowand <[email protected]>