ozgungunyeli
Posts: 1
Joined: Tue Nov 26, 2019 1:04 pm

Dynamic Device Tree

Tue Nov 26, 2019 1:40 pm

Hello,
I am new to this device tree stuff and I have a problem with dynamic device tree structure.
I have two overlays;
First:

Code: Select all

/dts-v1/;
/plugin/;

/ {
    [email protected] {
        target = <&i2c1>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;

            sensor1: [email protected] {
                compatible = "abc,sensor1";
                reg = <0x33>;
                reset-gpios = <&gpio 27 0>;    /* reset pin is 27 */
                interrupt-parent = <&gpio>;
                interrupts = <17 0x02>;      /* interrupt pin is 17 */
            };
        };
    };
};
Second;

Code: Select all

/dts-v1/;
/plugin/;

/ {
    [email protected] {
        target = <&i2c1>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;

            sensor2: [email protected] {
                compatible = "abc,sensor2";
                reg = <0x32>;
                reset-gpios = <&gpio 13 0>;    /* reset pin is 13*/
                interrupt-parent = <&gpio>;
                interrupts = <12  0x02>;      /* interrupt pin is 12*/
            };
        };
    };
};
I compiled .dts files and generated .dtbo files.
I can upload overlay with;
sudo dtoverlay sensor1
sudo dtoverlay sensor2
However, when I try to remove overlay, I got this error:
sudo dtoverlay -r sensor1

Code: Select all

OF: ERROR: memory leak, expected refcount 1 instead of 2, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay node /soc/[email protected]/[email protected]
or
sudo dtoverlay -r sensor2

Code: Select all

OF: ERROR: memory leak, expected refcount 1 instead of 2, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay node /soc/[email protected]/[email protected]
I searched the forum and the Internet but I could not find any explanation about this problem.
Anybody know what is the problem ?
Thanks for any help.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2656
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Dynamic Device Tree

Tue Nov 26, 2019 2:57 pm

That is a warning I've seen, but it's not something I've had time to dive into. Dynamic Device Tree is barely used in the kernel, even in 5.4 - a few drivers apply small DT patches at run time, but the dynamic overlay application support is only used by a downstream patch and some upstream test code. Some subsystems are aware of the possibility of devices appearing and disappearing at random, and others aren't - if it works for you, great, but there's no guarantee that all overlays will function as expected.

It could be that the leak is caused by a bug in the downstream patch, or in the core kernel code, or it could be a fact of life caused by the I2C interface node being used by the driver that owns the compatible string you've just added. If you wanted to debug this further I would suggest:

1. Cut the overlay down to the absolute minimum such that it still works - that "sensor1" label seems to be unused.
2. Blacklist the driver: do an "lsmod" to find the driver name, then create a file in /etc/modprobe.d/ called something like "my_blacklist.conf" containing "blacklist my_driver", where "my_driver" is the name you found earlier. This should prevent the driver from being loaded when the overlay is applied, but you can still force it with "sudo modprobe my_driver". You can now try removing the overlay with and without the driver being loaded.

Let me know what you find.

Return to “Device Tree”