Skip to contentSkip to conversation

drm: rcar-du: Fix the return check of of_parse_phandle and of_find_device_by_node

PATCH In review Wang Xiaojun 3 participants 4 messages Nov 11, 2020 – Dec 16, 2020

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

PATCH 1/1 drm: rcar-du: Fix the return check of of_parse_phandle and of_find_device_by_node

of_parse_phandle and of_find_device_by_node may return NULL which cannot be checked by IS_ERR.

---
 drivers/gpu/drm/rcar-du/rcar_du_kms.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/rcar-du/rcar_du_kms.c +4 -4
index 72dda446355f..fcfddf7ad3f3 100644
@@ -700,10 +700,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		int ret;
 
 		cmm = of_parse_phandle(np, "renesas,cmms", i);
-		if (IS_ERR(cmm)) {
+		if (!cmm) {
 			dev_err(rcdu->dev,
 				"Failed to parse 'renesas,cmms' property\n");
-			return PTR_ERR(cmm);
+			return -ENODEV;
 		}
 
 		if (!of_device_is_available(cmm)) {
@@ -713,10 +713,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		}
 
 		pdev = of_find_device_by_node(cmm);
-		if (IS_ERR(pdev)) {
+		if (!pdev) {
 			dev_err(rcdu->dev, "No device found for CMM%u\n", i);
 			of_node_put(cmm);
-			return PTR_ERR(pdev);
+			return -ENODEV;
 		}
 
 		of_node_put(cmm);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Wang Xiaojun,

Quoted 2 lines · Wang Xiaojun

of_parse_phandle and of_find_device_by_node may return NULL which cannot be checked by IS_ERR.

Indeed, both of these functions return either NULL or the correct value, and no an errno.

Quoted 3 lines
Fixes 8de707aeb452 ("drm: rcar-du: kms: Initialize CMM instances")
Quoted 35 lines
---
 drivers/gpu/drm/rcar-du/rcar_du_kms.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/rcar-du/rcar_du_kms.c +4 -4
index 72dda446355f..fcfddf7ad3f3 100644
@@ -700,10 +700,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		int ret;
 
 		cmm = of_parse_phandle(np, "renesas,cmms", i);
-		if (IS_ERR(cmm)) {
+		if (!cmm) {
 			dev_err(rcdu->dev,
 				"Failed to parse 'renesas,cmms' property\n");
-			return PTR_ERR(cmm);
+			return -ENODEV;
 		}
 
 		if (!of_device_is_available(cmm)) {
@@ -713,10 +713,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		}
 
 		pdev = of_find_device_by_node(cmm);
-		if (IS_ERR(pdev)) {
+		if (!pdev) {
 			dev_err(rcdu->dev, "No device found for CMM%u\n", i);
 			of_node_put(cmm);
-			return PTR_ERR(pdev);
+			return -ENODEV;
 		}
 
 		of_node_put(cmm);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Wang Xiaojun

Hi Wang,

Thank you for the patch.

Quoted 5 lines · Wang Xiaojun

of_parse_phandle and of_find_device_by_node may return NULL which cannot be checked by IS_ERR.

and queued in my tree for v5.12.

Quoted 34 lines
---
 drivers/gpu/drm/rcar-du/rcar_du_kms.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/rcar-du/rcar_du_kms.c +4 -4
index 72dda446355f..fcfddf7ad3f3 100644
@@ -700,10 +700,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		int ret;
 
 		cmm = of_parse_phandle(np, "renesas,cmms", i);
-		if (IS_ERR(cmm)) {
+		if (!cmm) {
 			dev_err(rcdu->dev,
 				"Failed to parse 'renesas,cmms' property\n");
-			return PTR_ERR(cmm);
+			return -ENODEV;
 		}
 
 		if (!of_device_is_available(cmm)) {
@@ -713,10 +713,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		}
 
 		pdev = of_find_device_by_node(cmm);
-		if (IS_ERR(pdev)) {
+		if (!pdev) {
 			dev_err(rcdu->dev, "No device found for CMM%u\n", i);
 			of_node_put(cmm);
-			return PTR_ERR(pdev);
+			return -ENODEV;
 		}
 
 		of_node_put(cmm);
Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
Quoted 26 lines · Laurent Pinchart

Hi Wang,

Thank you for the patch.

Quoted 5 lines · Wang Xiaojun

of_parse_phandle and of_find_device_by_node may return NULL which cannot be checked by IS_ERR.

and queued in my tree for v5.12.

Quoted 11 lines
---
 drivers/gpu/drm/rcar-du/rcar_du_kms.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/rcar-du/rcar_du_kms.c +0 -0
index 72dda446355f..fcfddf7ad3f3 100644
@@ -700,10 +700,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		int ret;
 
Quoted 7 lines

drivers/gpu/drm/rcar-du/rcar_du_kms.c static int rcar_du_cmm_init(struct rcar_du_device *rcdu) · line 706

Quoted 7 lines
drivers/gpu/drm/rcar-du/rcar_du_kms.c +2 -2
 		cmm = of_parse_phandle(np, "renesas,cmms", i);
-		if (IS_ERR(cmm)) {
+		if (!cmm) {
 			dev_err(rcdu->dev,
 				"Failed to parse 'renesas,cmms' property\n");
-			return PTR_ERR(cmm);
+			return -ENODEV;

Actually, this should return -EINVAL, as this error really shouldn't happen. Same below. I'll update this, no need to resend a new version.

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/rcar-du/rcar_du_kms.c +2 -2
 		}
 
 		if (!of_device_is_available(cmm)) {
@@ -713,10 +713,10 @@ static int rcar_du_cmm_init(struct rcar_du_device *rcdu)
 		}
 
 		pdev = of_find_device_by_node(cmm);
-		if (IS_ERR(pdev)) {
+		if (!pdev) {
 			dev_err(rcdu->dev, "No device found for CMM%u\n", i);
 			of_node_put(cmm);
-			return PTR_ERR(pdev);
+			return -ENODEV;
 		}
 
 		of_node_put(cmm);
Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel