Skip to contentSkip to conversation

drm: vc4: Use of_property_present()

PATCH In review Rob Herring (Arm) 2 participants 7 messages Jul 31, 2024 – Sep 9, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: vc4: Use of_property_present()

Use of_property_present() to test for property presence rather than of_find_property(). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +2 -2
index d57c4a5948c8..049de06460d5 100644
@@ -2211,7 +2211,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
 	struct device *dev = &vc4_hdmi->pdev->dev;
 	struct platform_device *codec_pdev;
 	const __be32 *addr;
-	int index, len;
+	int index;
 	int ret;
 
 	/*
@@ -2234,7 +2234,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
 	BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0);
 	BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0);
 
-	if (!of_find_property(dev->of_node, "dmas", &len) || !len) {
+	if (!of_property_present(dev->of_node, "dmas")) {
 		dev_warn(dev,
 			 "'dmas' DT property is missing or empty, no HDMI audio\n");
 		return 0;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 11 lines · Rob Herring (Arm)

Use of_property_present() to test for property presence rather than of_find_property(). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Ping!

Quoted 26 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +2 -3
index d57c4a5948c8..049de06460d5 100644
@@ -2211,7 +2211,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        struct device *dev = &vc4_hdmi->pdev->dev;
        struct platform_device *codec_pdev;
        const __be32 *addr;
-       int index, len;
+       int index;
        int ret;
 
        /*
@@ -2234,7 +2234,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0);
        BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0);
 
-       if (!of_find_property(dev->of_node, "dmas", &len) || !len) {
+       if (!of_property_present(dev->of_node, "dmas")) {
                dev_warn(dev,
                         "'dmas' DT property is missing or empty, no HDMI audio\n");
                return 0;
--

2.43.0

maintainer
#2 lore raw

Hi Rob

Quoted 9 lines · Rob Herring
Quoted 7 lines · Rob Herring (Arm)

Use of_property_present() to test for property presence rather than of_find_property(). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed.

Quoted 6 lines
Quoted 4 lines
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Ping!

Sorry, this fell through the cracks.

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index d57c4a5948c8..049de06460d5 100644
@@ -2211,7 +2211,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        struct device *dev = &vc4_hdmi->pdev->dev;
        struct platform_device *codec_pdev;
        const __be32 *addr;
-       int index, len;
+       int index;
        int ret;
 
Quoted 7 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi) · line 2237

Quoted 7 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
        /*
@@ -2234,7 +2234,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0);
        BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0);
 
-       if (!of_find_property(dev->of_node, "dmas", &len) || !len) {
+       if (!of_property_present(dev->of_node, "dmas")) {

The existing conditional is true if the property is not present or is 0 length. Your new one is only true if the property isn't present, so it isn't the same.

Is there a more appropriate of_ call to return the length of the property?

Thanks
Dave

Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +0 -1
                dev_warn(dev,
                         "'dmas' DT property is missing or empty, no HDMI audio\n");
                return 0;
--

2.43.0

#3 lore raw
Quoted 40 lines · Dave Stevenson

Hi Rob

Quoted 9 lines · Rob Herring
Quoted 7 lines · Rob Herring (Arm)

Use of_property_present() to test for property presence rather than of_find_property(). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed.

Quoted 6 lines
Quoted 4 lines
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Ping!

Sorry, this fell through the cracks.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index d57c4a5948c8..049de06460d5 100644
@@ -2211,7 +2211,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        struct device *dev = &vc4_hdmi->pdev->dev;
        struct platform_device *codec_pdev;
        const __be32 *addr;
-       int index, len;
+       int index;
        int ret;
 
        /*
@@ -2234,7 +2234,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0);
        BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0);
 
Quoted 5 lines
Quoted 2 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi) · line 2237

Quoted 2 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-       if (!of_find_property(dev->of_node, "dmas", &len) || !len) {
+       if (!of_property_present(dev->of_node, "dmas")) {

The existing conditional is true if the property is not present or is 0 length. Your new one is only true if the property isn't present, so it isn't the same.

It is not the kernel's job to validate the DT. It does a terrible job of it and we have better tools for that now (schemas (though RPi platforms are in a pretty sad state for schemas)). I'm pretty sure a zero length or otherwise malformed "dmas" property would also cause a dtc warning as well. Non-zero length is hardly a complete test anyways. Any bogus value of "dmas" would pass. Or it can be completely valid, but the DMA driver is not enabled (whether you even probe depends on fw_devlinks).

The kernel should just parse the properties it wants and handle any errors then.

Quoted 2 lines

Is there a more appropriate of_ call to return the length of the property?

There are several which are all based on the data type (string, u32, u8, phandle+args, etc.). This case would be of_count_phandle_with_args(). Unless you required something like 2 dmas entries instead of 1, I wouldn't use that here though.

Rob

maintainer
#4 lore raw
Quoted 58 lines · Rob Herring
Quoted 40 lines · Dave Stevenson

Hi Rob

Quoted 9 lines · Rob Herring
Quoted 7 lines · Rob Herring (Arm)

Use of_property_present() to test for property presence rather than of_find_property(). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed.

Quoted 6 lines
Quoted 4 lines
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Ping!

Sorry, this fell through the cracks.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index d57c4a5948c8..049de06460d5 100644
@@ -2211,7 +2211,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        struct device *dev = &vc4_hdmi->pdev->dev;
        struct platform_device *codec_pdev;
        const __be32 *addr;
-       int index, len;
+       int index;
        int ret;
 
        /*
@@ -2234,7 +2234,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0);
        BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0);
 
Quoted 5 lines
Quoted 2 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi) · line 2237

Quoted 2 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-       if (!of_find_property(dev->of_node, "dmas", &len) || !len) {
+       if (!of_property_present(dev->of_node, "dmas")) {

The existing conditional is true if the property is not present or is 0 length. Your new one is only true if the property isn't present, so it isn't the same.

It is not the kernel's job to validate the DT. It does a terrible job of it and we have better tools for that now (schemas (though RPi platforms are in a pretty sad state for schemas)). I'm pretty sure a zero length or otherwise malformed "dmas" property would also cause a dtc warning as well. Non-zero length is hardly a complete test anyways. Any bogus value of "dmas" would pass. Or it can be completely valid, but the DMA driver is not enabled (whether you even probe depends on fw_devlinks).

Quoted 1 line

The kernel should just parse the properties it wants and handle any errors then.

I've followed up over the rationale of this.

The base DT enables HDMI audio.
On some systems there is a need to use the DMA channels for other purposes and no need for HDMI audio.
As we understand it, an overlay can't remove a property from the base DT, but it can set it to being empty. (Please correct us if there is a way to delete an existing property).

The current check therefore allows an overlay to disable the HDMI audio that is enabled in the base DT. It doesn't care how long the property actually is, just whether it is totally empty or not as an alternative to being present.

I understand that you may consider that abuse of DT, but that is the reasoning behind it. We can drop it to a downstream patch if necessary.

Dave

Quoted 9 lines
Quoted 2 lines

Is there a more appropriate of_ call to return the length of the property?

There are several which are all based on the data type (string, u32, u8, phandle+args, etc.). This case would be of_count_phandle_with_args(). Unless you required something like 2 dmas entries instead of 1, I wouldn't use that here though.

Rob

#5 lore raw
Quoted 60 lines · Dave Stevenson
Quoted 58 lines · Rob Herring
Quoted 40 lines · Dave Stevenson

Hi Rob

Quoted 9 lines · Rob Herring
Quoted 7 lines · Rob Herring (Arm)

Use of_property_present() to test for property presence rather than of_find_property(). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed.

Quoted 6 lines
Quoted 4 lines
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Ping!

Sorry, this fell through the cracks.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index d57c4a5948c8..049de06460d5 100644
@@ -2211,7 +2211,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        struct device *dev = &vc4_hdmi->pdev->dev;
        struct platform_device *codec_pdev;
        const __be32 *addr;
-       int index, len;
+       int index;
        int ret;
 
        /*
@@ -2234,7 +2234,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0);
        BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0);
 
Quoted 5 lines
Quoted 2 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi) · line 2237

Quoted 2 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-       if (!of_find_property(dev->of_node, "dmas", &len) || !len) {
+       if (!of_property_present(dev->of_node, "dmas")) {

The existing conditional is true if the property is not present or is 0 length. Your new one is only true if the property isn't present, so it isn't the same.

It is not the kernel's job to validate the DT. It does a terrible job of it and we have better tools for that now (schemas (though RPi platforms are in a pretty sad state for schemas)). I'm pretty sure a zero length or otherwise malformed "dmas" property would also cause a dtc warning as well. Non-zero length is hardly a complete test anyways. Any bogus value of "dmas" would pass. Or it can be completely valid, but the DMA driver is not enabled (whether you even probe depends on fw_devlinks).

Quoted 7 lines
Quoted 1 line

The kernel should just parse the properties it wants and handle any errors then.

I've followed up over the rationale of this.

The base DT enables HDMI audio.
On some systems there is a need to use the DMA channels for other purposes and no need for HDMI audio.

If that's a user decision, I wouldn't use overlays to decide that, but make it a run-time OS decision...

Quoted 3 lines

As we understand it, an overlay can't remove a property from the base DT, but it can set it to being empty. (Please correct us if there is a way to delete an existing property).

There isn't currently.

Quoted 8 lines

The current check therefore allows an overlay to disable the HDMI audio that is enabled in the base DT. It doesn't care how long the property actually is, just whether it is totally empty or not as an alternative to being present.

I understand that you may consider that abuse of DT, but that is the reasoning behind it. We can drop it to a downstream patch if necessary.

I guess it's going to be use of_count_phandle_with_args() instead.

Rob

maintainer
#6 lore raw
Quoted 65 lines · Rob Herring
Quoted 62 lines · Dave Stevenson
Quoted 59 lines · Rob Herring
Quoted 40 lines · Dave Stevenson

Hi Rob

Quoted 9 lines · Rob Herring
Quoted 7 lines · Rob Herring (Arm)

Use of_property_present() to test for property presence rather than of_find_property(). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed.

Quoted 6 lines
Quoted 4 lines
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Ping!

Sorry, this fell through the cracks.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index d57c4a5948c8..049de06460d5 100644
@@ -2211,7 +2211,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        struct device *dev = &vc4_hdmi->pdev->dev;
        struct platform_device *codec_pdev;
        const __be32 *addr;
-       int index, len;
+       int index;
        int ret;
 
        /*
@@ -2234,7 +2234,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi)
        BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0);
        BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0);
 
Quoted 5 lines
Quoted 2 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi) · line 2237

Quoted 2 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-       if (!of_find_property(dev->of_node, "dmas", &len) || !len) {
+       if (!of_property_present(dev->of_node, "dmas")) {

The existing conditional is true if the property is not present or is 0 length. Your new one is only true if the property isn't present, so it isn't the same.

It is not the kernel's job to validate the DT. It does a terrible job of it and we have better tools for that now (schemas (though RPi platforms are in a pretty sad state for schemas)). I'm pretty sure a zero length or otherwise malformed "dmas" property would also cause a dtc warning as well. Non-zero length is hardly a complete test anyways. Any bogus value of "dmas" would pass. Or it can be completely valid, but the DMA driver is not enabled (whether you even probe depends on fw_devlinks).

The kernel should just parse the properties it wants and handle any errors then.

Quoted 8 lines
Quoted 5 lines

I've followed up over the rationale of this.

The base DT enables HDMI audio.
On some systems there is a need to use the DMA channels for other purposes and no need for HDMI audio.

If that's a user decision, I wouldn't use overlays to decide that, but make it a run-time OS decision...

Raspberry Pi users tend to mess far more with the hardware configuration than on most other platforms, so they do want to make these changes when adding extra external peripherals, but they aren't DT experts.
AFAIK configuring audio availability like that is not an option that can really be pushed fully into userspace through any current API, which would only leave a module parameter, and those generally seem to be frowned upon these days.

Quoted 11 lines
Quoted 3 lines

As we understand it, an overlay can't remove a property from the base DT, but it can set it to being empty. (Please correct us if there is a way to delete an existing property).

There isn't currently.

Quoted 5 lines

The current check therefore allows an overlay to disable the HDMI audio that is enabled in the base DT. It doesn't care how long the property actually is, just whether it is totally empty or not as an alternative to being present.

Quoted 5 lines
Quoted 3 lines

I understand that you may consider that abuse of DT, but that is the reasoning behind it. We can drop it to a downstream patch if necessary.

I guess it's going to be use of_count_phandle_with_args() instead.

I'm happy with that if you are.

Thanks
Dave

Quoted 1 line

Rob