Skip to contentSkip to conversation

drm/bridge: tpd12s015: Fix irq registering in tpd12s015_probe

PATCH Superseded YueHaibing 4 participants 10 messages Oct 31, 2020 – Nov 5, 2020

Subsystems (3)
lore
Share & tools
lore

YueHaibing

author
#0 lore raw

PATCH 1/1 drm/bridge: tpd12s015: Fix irq registering in tpd12s015_probe

gpiod_to_irq() return negative value in case of error, the existing code handle negative error codes wrongly.

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")
---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
index 514cbf0eac75..a18d5197c16c 100644
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq > 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |
Signature · 1 line
2.17.1
#1 lore raw

Hi YueHaibing

Thanks for the fix. Appreciated but please update as per comments below.

Quoted 14 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code handle negative error codes wrongly.

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")
---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +0 -0
index 514cbf0eac75..a18d5197c16c 100644

drivers/gpu/drm/bridge/ti-tpd12s015.c static int tpd12s015_probe(struct platform_device *pdev) · line 166

Quoted 8 lines
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq > 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |

The current implmentation will skip devm_request_threaded_irq() in case or error - but continue with the rest of the function. So the driver fails to return an error code.

In case of error (negative value) then return early with that error value. If gpiod_to_irq() returns 0 assume this is a valid irq and let the code continue.

Please fix and re-submit - or tell me if I am mistaken.

Sam

author
#2 lore raw
Quoted 32 lines · Sam Ravnborg

Hi YueHaibing

Thanks for the fix. Appreciated but please update as per comments below.

Quoted 14 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code handle negative error codes wrongly.

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")
---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +0 -0
index 514cbf0eac75..a18d5197c16c 100644

drivers/gpu/drm/bridge/ti-tpd12s015.c static int tpd12s015_probe(struct platform_device *pdev) · line 166

Quoted 8 lines
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq > 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |

The current implmentation will skip devm_request_threaded_irq() in case or error - but continue with the rest of the function. So the driver fails to return an error code.

Quoted 1 line

In case of error (negative value) then return early with that error

Agree, will resubmit.

Quoted 2 lines

value. If gpiod_to_irq() returns 0 assume this is a valid irq and let the code continue.

gpiod_to_irq() never returns 0, so no need check this.

Quoted 6 lines

Please fix and re-submit - or tell me if I am mistaken.

Sam
.

#3 lore raw
In reply to Sam Ravnborg
Quoted 20 lines · Sam Ravnborg

Hi YueHaibing

Thanks for the fix. Appreciated but please update as per comments below.

Quoted 15 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code handle negative error codes wrongly.

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")
---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +0 -0
index 514cbf0eac75..a18d5197c16c 100644
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
Quoted 11 lines

drivers/gpu/drm/bridge/ti-tpd12s015.c static int tpd12s015_probe(struct platform_device *pdev) · line 166

Quoted 7 lines
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq > 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |

The current implmentation will skip devm_request_threaded_irq() in case or error - but continue with the rest of the function. So the driver fails to return an error code.

That is intended. If the HPD gpio supports IRQs (gpiod_to_irq returns a valid number), we use the IRQ. If it doesn't (gpiod_to_irq returns an error), it gets polled via detect(). Both are ok.

I don't know if the gpiod_to_irq never returning 0 is something we should rely on. The docs say gpiod_to_irq returns the irq number or an error, so I think checking for >= 0 matches the docs better.

Tomi

Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#4 lore raw
Quoted 33 lines · Tomi Valkeinen
Quoted 20 lines · Sam Ravnborg

Hi YueHaibing

Thanks for the fix. Appreciated but please update as per comments below.

Quoted 15 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code handle negative error codes wrongly.

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")
---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +0 -0
index 514cbf0eac75..a18d5197c16c 100644
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
Quoted 11 lines

drivers/gpu/drm/bridge/ti-tpd12s015.c static int tpd12s015_probe(struct platform_device *pdev) · line 166

Quoted 7 lines
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq > 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |

The current implmentation will skip devm_request_threaded_irq() in case or error - but continue with the rest of the function. So the driver fails to return an error code.

Quoted 6 lines

That is intended. If the HPD gpio supports IRQs (gpiod_to_irq returns a valid number), we use the IRQ. If it doesn't (gpiod_to_irq returns an error), it gets polled via detect(). Both are ok.

I don't know if the gpiod_to_irq never returning 0 is something we should rely on. The docs say gpiod_to_irq returns the irq number or an error, so I think checking for >= 0 matches the docs better.

gpiod_to_irq() now never returns 0, see:
https://elixir.bootlin.com/linux/v5.10-rc2/source/drivers/gpio/gpiolib.c#L3183

Also commit 4c37ce8608a8 ("gpio: make gpiod_to_irq() return negative for NO_IRQ") says:

commit 4c37ce8608a8c6521726d4cd1d4f54424e8d095f

Author: Linus Walleij <[email protected]>
Date:   Mon May 2 13:13:10 2016 +0200

gpio: make gpiod_to_irq() return negative for NO_IRQ

If a translation returns zero, that means NO_IRQ, so we should return an error since the function is documented to return a negative code on error.

So checking for >0 is enough, my patch is correct.

Quoted 2 lines

Tomi

#5 lore raw
Quoted 50 lines · Yuehaibing
Quoted 33 lines · Tomi Valkeinen
Quoted 20 lines · Sam Ravnborg

Hi YueHaibing

Thanks for the fix. Appreciated but please update as per comments below.

Quoted 15 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code handle negative error codes wrongly.

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")
---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +0 -0
index 514cbf0eac75..a18d5197c16c 100644
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
Quoted 11 lines

drivers/gpu/drm/bridge/ti-tpd12s015.c static int tpd12s015_probe(struct platform_device *pdev) · line 166

Quoted 7 lines
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq > 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |

The current implmentation will skip devm_request_threaded_irq() in case or error - but continue with the rest of the function. So the driver fails to return an error code.

Quoted 6 lines

That is intended. If the HPD gpio supports IRQs (gpiod_to_irq returns a valid number), we use the IRQ. If it doesn't (gpiod_to_irq returns an error), it gets polled via detect(). Both are ok.

I don't know if the gpiod_to_irq never returning 0 is something we should rely on. The docs say gpiod_to_irq returns the irq number or an error, so I think checking for >= 0 matches the docs better.

gpiod_to_irq() now never returns 0, see:
https://elixir.bootlin.com/linux/v5.10-rc2/source/drivers/gpio/gpiolib.c#L3183

Also commit 4c37ce8608a8 ("gpio: make gpiod_to_irq() return negative for NO_IRQ") says:

commit 4c37ce8608a8c6521726d4cd1d4f54424e8d095f

Author: Linus Walleij <[email protected]>
Date:   Mon May 2 13:13:10 2016 +0200
Quoted 7 lines

gpio: make gpiod_to_irq() return negative for NO_IRQ

If a translation returns zero, that means NO_IRQ, so we should return an error since the function is documented to return a negative code on error.

So checking for >0 is enough, my patch is correct.

Yes, but that is a gpiod_to_irq internal implementation detail. The documentation says it returns an error code (negative) or a valid irq number. The documentation does not say gpiod_to_irq never returns 0.

Tomi

Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#6 lore raw

PATCH v2 1/1 drm/bridge: tpd12s015: Fix irq registering in tpd12s015_probe

In reply to YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code doesn't handle negative error codes. If the HPD gpio supports IRQs (gpiod_to_irq returns a valid number), we use the IRQ. If it doesn't (gpiod_to_irq returns an error), it gets polled via detect().

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")

---
v2: Add checking for >= 0 and update commit message

---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
index 514cbf0eac75..e0e015243a60 100644
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq >= 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |
Signature · 1 line
2.17.1
reviewer Reviewed-by on v2 1/1
#7 lore raw

Hi Yue,

Thank you for the patch.

Quoted 8 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code doesn't handle negative error codes. If the HPD gpio supports IRQs (gpiod_to_irq returns a valid number), we use the IRQ. If it doesn't (gpiod_to_irq returns an error), it gets polled via detect().

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")
Quoted 19 lines

---
v2: Add checking for >= 0 and update commit message

---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
index 514cbf0eac75..e0e015243a60 100644
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq >= 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |
Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 1/1
#8 lore raw
In reply to YueHaibing
Quoted 20 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code doesn't handle negative error codes. If the HPD gpio supports IRQs (gpiod_to_irq returns a valid number), we use the IRQ. If it doesn't (gpiod_to_irq returns an error), it gets polled via detect().

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")

---
v2: Add checking for >= 0 and update commit message

---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +0 -0
index 514cbf0eac75..e0e015243a60 100644

drivers/gpu/drm/bridge/ti-tpd12s015.c static int tpd12s015_probe(struct platform_device *pdev) · line 166

Quoted 8 lines
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq >= 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |

Tomi

Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Applied
#9 lore raw
In reply to YueHaibing

Hi YueHaibing

Quoted 10 lines · YueHaibing

gpiod_to_irq() return negative value in case of error, the existing code doesn't handle negative error codes. If the HPD gpio supports IRQs (gpiod_to_irq returns a valid number), we use the IRQ. If it doesn't (gpiod_to_irq returns an error), it gets polled via detect().

Fixes cff5e6f7e83f ("drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter")

---
v2: Add checking for >= 0 and update commit message

Thanks, applied to drm-misc-next.

Sam

Quoted 24 lines
---
 drivers/gpu/drm/bridge/ti-tpd12s015.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-tpd12s015.c +1 -1
index 514cbf0eac75..e0e015243a60 100644
@@ -160,7 +160,7 @@ static int tpd12s015_probe(struct platform_device *pdev)
 
 	/* Register the IRQ if the HPD GPIO is IRQ-capable. */
 	tpd->hpd_irq = gpiod_to_irq(tpd->hpd_gpio);
-	if (tpd->hpd_irq) {
+	if (tpd->hpd_irq >= 0) {
 		ret = devm_request_threaded_irq(&pdev->dev, tpd->hpd_irq, NULL,
 						tpd12s015_hpd_isr,
 						IRQF_TRIGGER_RISING |
Signature · 6 lines
2.17.1

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