Skip to contentSkip to conversation

ata: sata_dwc_460ex: use platform_get_irq()

PATCH Applied Rosen Penev 4 participants 16 messages Jun 28 – Jun 30 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ata: sata_dwc_460ex: use platform_get_irq()

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle
---
 drivers/ata/sata_dwc_460ex.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/ata/sata_dwc_460ex.c +6 -12
index 4fc22ce4bd9a..35aa7f9acdf7 100644
@@ -19,7 +19,6 @@
 #include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
 #include <linux/libata.h>
@@ -226,7 +225,6 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 				 struct sata_dwc_device *hsdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;
 
 	hsdev->dma = devm_kzalloc(dev, sizeof(*hsdev->dma), GFP_KERNEL);
 	if (!hsdev->dma)
@@ -236,11 +234,9 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 	hsdev->dma->id = pdev->id;
 
 	/* Get SATA DMA interrupt number */
-	hsdev->dma->irq = irq_of_parse_and_map(np, 1);
-	if (!hsdev->dma->irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	hsdev->dma->irq = platform_get_irq(pdev, 1);
+	if (hsdev->dma->irq < 0)
+		return hsdev->dma->irq;
 
 	/* Get physical SATA DMA register base address */
 	hsdev->dma->regs = devm_platform_ioremap_resource(pdev, 1);
@@ -1173,11 +1169,9 @@ static int sata_dwc_probe(struct platform_device *ofdev)
 	sata_dwc_enable_interrupts(hsdev);
 
 	/* Get SATA interrupt number */
-	irq = irq_of_parse_and_map(np, 0);
-	if (!irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;
 
 #ifdef CONFIG_SATA_DWC_OLD_DMA
 	if (!of_property_present(np, "dmas")) {
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Pre-existing issues:
- [High] Probe error paths leave hardware interrupts unmasked, potentially causing an interrupt storm if a subsequent step fails or defers probe.
- [High] sata_dwc_probe() silently ignores ata_host_activate() failures, falsely reporting success and skipping cleanup.
- [High] Probe error path calls phy_exit() when phy_init() fails, corrupting the PHY's internal state.
- [High] Missing cleanup of old DMA resources on probe error paths.
--

commit 38e92fff8b9d315da09f885e72d12d704d5b7b50
Author: Rosen Penev <[email protected]>

ata: sata_dwc_460ex: use platform_get_irq()

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting.

Quoted 4 lines
drivers/ata/sata_dwc_460ex.c +0 -0
index 4fc22ce4bd9aa..35aa7f9acdf75 100644

[ ... ]

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev) · line 1174

Quoted 12 lines
drivers/ata/sata_dwc_460ex.c +3 -5
@@ -1173,11 +1169,9 @@ static int sata_dwc_probe(struct platform_device *ofdev)
 	sata_dwc_enable_interrupts(hsdev);
 
 	/* Get SATA interrupt number */
-	irq = irq_of_parse_and_map(np, 0);
-	if (!irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;

[Severity: High]
This is a pre-existing issue, but does returning directly here leave hardware interrupts unmasked?

Because sata_dwc_enable_interrupts() is called right before obtaining the IRQ, if platform_get_irq() returns -EPROBE_DEFER, probe will fail while interrupts remain enabled on the hardware. Could this lead to an unhandled interrupt storm?

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev) · line 1177

Quoted 3 lines
drivers/ata/sata_dwc_460ex.c +0 -0
 #ifdef CONFIG_SATA_DWC_OLD_DMA
 	if (!of_property_present(np, "dmas")) {

[Severity: High]
This isn't a bug introduced by this patch, but is there a missing cleanup for the old DMA resources on the error paths that follow this block?

If sata_dwc_dma_init_old() succeeds, but a subsequent operation like phy_init() fails later in sata_dwc_probe(), does the driver leave the DMA controller active and registered without calling a corresponding cleanup function?

[Severity: High]
This is a pre-existing issue, but does jumping to the error_out label when phy_init() fails corrupt the PHY's internal state?

Later in sata_dwc_probe(), when phy_init() fails, it jumps to error_out which unconditionally calls phy_exit(). Calling phy_exit() will decrement the internal init_count to -1, which can cause subsequent probe retries to falsely assume the PHY is already initialized.

[Severity: High]
This isn't a bug introduced by this patch, but does the driver silently ignore failures from ata_host_activate() at the end of sata_dwc_probe()?

If ata_host_activate() fails, it logs an error but still executes return 0; instead of jumping to error_out. Does this falsely signal success to the driver core and skip necessary cleanup, potentially leading to a crash on unbind?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Rosen Penev
Quoted 10 lines · Rosen Penev

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle

---

maintainer Applied
#3 lore raw
In reply to Rosen Penev
Quoted 9 lines · Rosen Penev

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle

Applied to for-7.2-fixes. Thanks!

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#4 lore raw
In reply to Rosen Penev
Quoted 26 lines · Rosen Penev

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle
---
 drivers/ata/sata_dwc_460ex.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/ata/sata_dwc_460ex.c +0 -1
index 4fc22ce4bd9a..35aa7f9acdf7 100644
@@ -19,7 +19,6 @@
 #include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
 #include <linux/libata.h>

drivers/ata/sata_dwc_460ex.c static int sata_dwc_dma_init_old(struct platform_device *pdev, · line 229

Quoted 4 lines
drivers/ata/sata_dwc_460ex.c +0 -1
@@ -226,7 +225,6 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 				 struct sata_dwc_device *hsdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;

While this patch drops 'struct device_node *np = dev->of_node;' from sata_dwc_dma_init_old() ...

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev)

Quoted 19 lines
drivers/ata/sata_dwc_460ex.c +3 -5
 	hsdev->dma = devm_kzalloc(dev, sizeof(*hsdev->dma), GFP_KERNEL);
 	if (!hsdev->dma)
@@ -236,11 +234,9 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 	hsdev->dma->id = pdev->id;
 
 	/* Get SATA DMA interrupt number */
-	hsdev->dma->irq = irq_of_parse_and_map(np, 1);
-	if (!hsdev->dma->irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	hsdev->dma->irq = platform_get_irq(pdev, 1);
+	if (hsdev->dma->irq < 0)
+		return hsdev->dma->irq;
 
 	/* Get physical SATA DMA register base address */
 	hsdev->dma->regs = devm_platform_ioremap_resource(pdev, 1);
@@ -1173,11 +1169,9 @@ static int sata_dwc_probe(struct platform_device *ofdev)

it seems like you forgot to do the same for sata_dwc_probe().

Which results in a new warning:
https://lore.kernel.org/oe-kbuild-all/[email protected]/T/#u

Damien, perhaps drop this patch and wait for a v2,
or fixup the patch to remove 'struct device_node *np = dev->of_node;' also from sata_dwc_probe().

Quoted 17 lines
drivers/ata/sata_dwc_460ex.c +3 -5
 	sata_dwc_enable_interrupts(hsdev);
 
 	/* Get SATA interrupt number */
-	irq = irq_of_parse_and_map(np, 0);
-	if (!irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;
 
 #ifdef CONFIG_SATA_DWC_OLD_DMA
 	if (!of_property_present(np, "dmas")) {
Signature · 1 line
2.54.0
maintainer
#5 lore raw
Quoted 77 lines · Niklas Cassel
Quoted 26 lines · Rosen Penev

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle
---
 drivers/ata/sata_dwc_460ex.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/ata/sata_dwc_460ex.c +0 -1
index 4fc22ce4bd9a..35aa7f9acdf7 100644
@@ -19,7 +19,6 @@
 #include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
 #include <linux/libata.h>

drivers/ata/sata_dwc_460ex.c static int sata_dwc_dma_init_old(struct platform_device *pdev, · line 229

Quoted 4 lines
drivers/ata/sata_dwc_460ex.c +0 -1
@@ -226,7 +225,6 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 				 struct sata_dwc_device *hsdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;

While this patch drops 'struct device_node *np = dev->of_node;' from sata_dwc_dma_init_old() ...

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev)

Quoted 19 lines
drivers/ata/sata_dwc_460ex.c +3 -5
 	hsdev->dma = devm_kzalloc(dev, sizeof(*hsdev->dma), GFP_KERNEL);
 	if (!hsdev->dma)
@@ -236,11 +234,9 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 	hsdev->dma->id = pdev->id;
 
 	/* Get SATA DMA interrupt number */
-	hsdev->dma->irq = irq_of_parse_and_map(np, 1);
-	if (!hsdev->dma->irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	hsdev->dma->irq = platform_get_irq(pdev, 1);
+	if (hsdev->dma->irq < 0)
+		return hsdev->dma->irq;
 
 	/* Get physical SATA DMA register base address */
 	hsdev->dma->regs = devm_platform_ioremap_resource(pdev, 1);
@@ -1173,11 +1169,9 @@ static int sata_dwc_probe(struct platform_device *ofdev)

it seems like you forgot to do the same for sata_dwc_probe().

Which results in a new warning:
https://lore.kernel.org/oe-kbuild-all/[email protected]/T/#u

Damien, perhaps drop this patch and wait for a v2,
or fixup the patch to remove 'struct device_node *np = dev->of_node;' also from sata_dwc_probe().

Quoted 12 lines
drivers/ata/sata_dwc_460ex.c +3 -5
 	sata_dwc_enable_interrupts(hsdev);
 
 	/* Get SATA interrupt number */
-	irq = irq_of_parse_and_map(np, 0);
-	if (!irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;
 
Quoted 2 lines

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev) · line 1177

Quoted 2 lines
drivers/ata/sata_dwc_460ex.c +0 -0
 #ifdef CONFIG_SATA_DWC_OLD_DMA
 	if (!of_property_present(np, "dmas")) {

Hmmm... np is used here though...

I will drop the patch for now and wait for a v2.

Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.54.0
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#6 lore raw
Quoted 78 lines · Damien Le Moal
Quoted 77 lines · Niklas Cassel
Quoted 26 lines · Rosen Penev

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle
---
 drivers/ata/sata_dwc_460ex.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/ata/sata_dwc_460ex.c +0 -1
index 4fc22ce4bd9a..35aa7f9acdf7 100644
@@ -19,7 +19,6 @@
 #include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
 #include <linux/libata.h>

drivers/ata/sata_dwc_460ex.c static int sata_dwc_dma_init_old(struct platform_device *pdev, · line 229

Quoted 4 lines
drivers/ata/sata_dwc_460ex.c +0 -1
@@ -226,7 +225,6 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 				 struct sata_dwc_device *hsdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;

While this patch drops 'struct device_node *np = dev->of_node;' from sata_dwc_dma_init_old() ...

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev)

Quoted 19 lines
drivers/ata/sata_dwc_460ex.c +3 -5
 	hsdev->dma = devm_kzalloc(dev, sizeof(*hsdev->dma), GFP_KERNEL);
 	if (!hsdev->dma)
@@ -236,11 +234,9 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
 	hsdev->dma->id = pdev->id;
 
 	/* Get SATA DMA interrupt number */
-	hsdev->dma->irq = irq_of_parse_and_map(np, 1);
-	if (!hsdev->dma->irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	hsdev->dma->irq = platform_get_irq(pdev, 1);
+	if (hsdev->dma->irq < 0)
+		return hsdev->dma->irq;
 
 	/* Get physical SATA DMA register base address */
 	hsdev->dma->regs = devm_platform_ioremap_resource(pdev, 1);
@@ -1173,11 +1169,9 @@ static int sata_dwc_probe(struct platform_device *ofdev)

it seems like you forgot to do the same for sata_dwc_probe().

Which results in a new warning:
https://lore.kernel.org/oe-kbuild-all/[email protected]/T/#u

Damien, perhaps drop this patch and wait for a v2,
or fixup the patch to remove 'struct device_node *np = dev->of_node;' also from sata_dwc_probe().

Quoted 12 lines
drivers/ata/sata_dwc_460ex.c +3 -5
 	sata_dwc_enable_interrupts(hsdev);
 
 	/* Get SATA interrupt number */
-	irq = irq_of_parse_and_map(np, 0);
-	if (!irq) {
-		dev_err(dev, "no SATA DMA irq\n");
-		return -ENODEV;
-	}
+	irq = platform_get_irq(ofdev, 0);
+	if (irq < 0)
+		return irq;
 
Quoted 4 lines
Quoted 2 lines

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev) · line 1177

Quoted 2 lines
drivers/ata/sata_dwc_460ex.c +0 -0
 #ifdef CONFIG_SATA_DWC_OLD_DMA
 	if (!of_property_present(np, "dmas")) {

Hmmm... np is used here though...

Inside ifdef, that is probably why Sashiko did not catch this new warning.

Rosen, I suggest that you use dev->of_node directly within the ifdef, and drop the local np variable.

Kind regards,
Niklas

#7 lore raw
Quoted 80 lines · Niklas Cassel
Quoted 78 lines · Damien Le Moal
Quoted 77 lines · Niklas Cassel
Quoted 26 lines · Rosen Penev

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle
---
 drivers/ata/sata_dwc_460ex.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/ata/sata_dwc_460ex.c +0 -1
index 4fc22ce4bd9a..35aa7f9acdf7 100644
@@ -19,7 +19,6 @@
 #include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
 #include <linux/libata.h>

drivers/ata/sata_dwc_460ex.c static int sata_dwc_dma_init_old(struct platform_device *pdev, · line 229

Quoted 4 lines
drivers/ata/sata_dwc_460ex.c +0 -1
@@ -226,7 +225,6 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
                             struct sata_dwc_device *hsdev)
 {
    struct device *dev = &pdev->dev;
-   struct device_node *np = dev->of_node;

While this patch drops 'struct device_node *np = dev->of_node;' from sata_dwc_dma_init_old() ...

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev)

Quoted 19 lines
drivers/ata/sata_dwc_460ex.c +3 -5
    hsdev->dma = devm_kzalloc(dev, sizeof(*hsdev->dma), GFP_KERNEL);
    if (!hsdev->dma)
@@ -236,11 +234,9 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
    hsdev->dma->id = pdev->id;
 
    /* Get SATA DMA interrupt number */
-   hsdev->dma->irq = irq_of_parse_and_map(np, 1);
-   if (!hsdev->dma->irq) {
-           dev_err(dev, "no SATA DMA irq\n");
-           return -ENODEV;
-   }
+   hsdev->dma->irq = platform_get_irq(pdev, 1);
+   if (hsdev->dma->irq < 0)
+           return hsdev->dma->irq;
 
    /* Get physical SATA DMA register base address */
    hsdev->dma->regs = devm_platform_ioremap_resource(pdev, 1);
@@ -1173,11 +1169,9 @@ static int sata_dwc_probe(struct platform_device *ofdev)

it seems like you forgot to do the same for sata_dwc_probe().

Which results in a new warning:
https://lore.kernel.org/oe-kbuild-all/[email protected]/T/#u

Damien, perhaps drop this patch and wait for a v2,
or fixup the patch to remove 'struct device_node *np = dev->of_node;' also from sata_dwc_probe().

Quoted 12 lines
drivers/ata/sata_dwc_460ex.c +3 -5
    sata_dwc_enable_interrupts(hsdev);
 
    /* Get SATA interrupt number */
-   irq = irq_of_parse_and_map(np, 0);
-   if (!irq) {
-           dev_err(dev, "no SATA DMA irq\n");
-           return -ENODEV;
-   }
+   irq = platform_get_irq(ofdev, 0);
+   if (irq < 0)
+           return irq;
 
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev) · line 1177

Quoted 2 lines
drivers/ata/sata_dwc_460ex.c +0 -0
 #ifdef CONFIG_SATA_DWC_OLD_DMA
    if (!of_property_present(np, "dmas")) {

Hmmm... np is used here though...

Inside ifdef, that is probably why Sashiko did not catch this new warning.

Rosen, I suggest that you use dev->of_node directly within the ifdef, and drop the local np variable.

device_property_present is probably better. But yeah. I'll whip up a v2.

Quoted 5 lines

Kind regards,
Niklas

#8 lore raw
Quoted 85 lines · Rosen Penev
Quoted 83 lines · Niklas Cassel
Quoted 81 lines · Damien Le Moal
Quoted 79 lines · Niklas Cassel
Quoted 26 lines · Rosen Penev

Replace irq_of_parse_and_map() with platform_get_irq() in both sata_dwc_dma_init_old() and sata_dwc_probe(). This is the preferred way to obtain IRQs for platform devices and provides better error reporting. Remove the now-unnecessary #include <linux/of_irq.h>.

irq_of_parse_and_map() requires irq_dispose_mapping(), which is missing.

Assisted-by opencode:big-pickle
---
 drivers/ata/sata_dwc_460ex.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/ata/sata_dwc_460ex.c +0 -1
index 4fc22ce4bd9a..35aa7f9acdf7 100644
@@ -19,7 +19,6 @@
 #include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
 #include <linux/libata.h>

drivers/ata/sata_dwc_460ex.c static int sata_dwc_dma_init_old(struct platform_device *pdev, · line 229

Quoted 4 lines
drivers/ata/sata_dwc_460ex.c +0 -1
@@ -226,7 +225,6 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
                             struct sata_dwc_device *hsdev)
 {
    struct device *dev = &pdev->dev;
-   struct device_node *np = dev->of_node;

While this patch drops 'struct device_node *np = dev->of_node;' from sata_dwc_dma_init_old() ...

drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev)

Quoted 19 lines
drivers/ata/sata_dwc_460ex.c +3 -5
    hsdev->dma = devm_kzalloc(dev, sizeof(*hsdev->dma), GFP_KERNEL);
    if (!hsdev->dma)
@@ -236,11 +234,9 @@ static int sata_dwc_dma_init_old(struct platform_device *pdev,
    hsdev->dma->id = pdev->id;
 
    /* Get SATA DMA interrupt number */
-   hsdev->dma->irq = irq_of_parse_and_map(np, 1);
-   if (!hsdev->dma->irq) {
-           dev_err(dev, "no SATA DMA irq\n");
-           return -ENODEV;
-   }
+   hsdev->dma->irq = platform_get_irq(pdev, 1);
+   if (hsdev->dma->irq < 0)
+           return hsdev->dma->irq;
 
    /* Get physical SATA DMA register base address */
    hsdev->dma->regs = devm_platform_ioremap_resource(pdev, 1);
@@ -1173,11 +1169,9 @@ static int sata_dwc_probe(struct platform_device *ofdev)

it seems like you forgot to do the same for sata_dwc_probe().

Which results in a new warning:
https://lore.kernel.org/oe-kbuild-all/[email protected]/T/#u

Damien, perhaps drop this patch and wait for a v2,
or fixup the patch to remove 'struct device_node *np = dev->of_node;' also from sata_dwc_probe().

Quoted 14 lines
drivers/ata/sata_dwc_460ex.c +3 -5
    sata_dwc_enable_interrupts(hsdev);
 
    /* Get SATA interrupt number */
-   irq = irq_of_parse_and_map(np, 0);
-   if (!irq) {
-           dev_err(dev, "no SATA DMA irq\n");
-           return -ENODEV;
-   }
+   irq = platform_get_irq(ofdev, 0);
+   if (irq < 0)
+           return irq;
 
 #ifdef CONFIG_SATA_DWC_OLD_DMA
    if (!of_property_present(np, "dmas")) {
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

Hmmm... np is used here though...

Inside ifdef, that is probably why Sashiko did not catch this new warning.

Rosen, I suggest that you use dev->of_node directly within the ifdef, and drop the local np variable.

device_property_present is probably better. But yeah. I'll whip up a v2.

thinking about this some more. Should use IS_ENABLED to prevent hiding this code from the compiler.

Quoted 5 lines
Quoted 5 lines

Kind regards,
Niklas

maintainer
#9 lore raw
Quoted 6 lines · Rosen Penev
Quoted 4 lines
Quoted 3 lines

Inside ifdef, that is probably why Sashiko did not catch this new warning.

Rosen, I suggest that you use dev->of_node directly within the ifdef, and drop the local np variable.

device_property_present is probably better. But yeah. I'll whip up a v2.

thinking about this some more. Should use IS_ENABLED to prevent hiding this code from the compiler.

What code are you talking about ?
What is in the #ifdef CONFIG_SATA_DWC_OLD_DMA ? CONFIG_SATA_DWC_OLD_DMA is determined automatically by Kconfig. So this is not hidding anything and why I did not see the warning in my compile tests (CONFIG_SATA_DWC_OLD_DMA was enabled for me). The report was for Sparc, and CONFIG_SATA_DWC_OLD_DMA was disabled so the unused variable warning showed up.

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#10 lore raw
Quoted 8 lines · Damien Le Moal
Quoted 6 lines · Rosen Penev
Quoted 4 lines
Quoted 3 lines

Inside ifdef, that is probably why Sashiko did not catch this new warning.

Rosen, I suggest that you use dev->of_node directly within the ifdef, and drop the local np variable.

device_property_present is probably better. But yeah. I'll whip up a v2.

thinking about this some more. Should use IS_ENABLED to prevent hiding this code from the compiler.

Quoted 6 lines

What code are you talking about ?
What is in the #ifdef CONFIG_SATA_DWC_OLD_DMA ? CONFIG_SATA_DWC_OLD_DMA is determined automatically by Kconfig. So this is not hidding anything and why I did not see the warning in my compile tests (CONFIG_SATA_DWC_OLD_DMA was enabled for me). The report was for Sparc, and CONFIG_SATA_DWC_OLD_DMA was disabled so the unused variable warning showed up.

I think he means: keep the local np variable,
and replace the #ifdef with
if (IS_ENABLED(CONFIG_SATA_DWC_OLD_DMA) && !of_property_present(np, "dmas")) {

I think it will work for both CONFIG_SATA_DWC_OLD_DMA=y and CONFIG_SATA_DWC_OLD_DMA=n without giving any warnings.

Kind regards,
Niklas

maintainer
#11 lore raw
Quoted 16 lines · Niklas Cassel
Quoted 8 lines · Damien Le Moal
Quoted 6 lines · Rosen Penev
Quoted 4 lines
Quoted 3 lines

Inside ifdef, that is probably why Sashiko did not catch this new warning.

Rosen, I suggest that you use dev->of_node directly within the ifdef, and drop the local np variable.

device_property_present is probably better. But yeah. I'll whip up a v2.

thinking about this some more. Should use IS_ENABLED to prevent hiding this code from the compiler.

Quoted 6 lines

What code are you talking about ?
What is in the #ifdef CONFIG_SATA_DWC_OLD_DMA ? CONFIG_SATA_DWC_OLD_DMA is determined automatically by Kconfig. So this is not hidding anything and why I did not see the warning in my compile tests (CONFIG_SATA_DWC_OLD_DMA was enabled for me). The report was for Sparc, and CONFIG_SATA_DWC_OLD_DMA was disabled so the unused variable warning showed up.

Quoted 7 lines

I think he means: keep the local np variable,
and replace the #ifdef with
if (IS_ENABLED(CONFIG_SATA_DWC_OLD_DMA) && !of_property_present(np, "dmas")) {

I think it will work for both CONFIG_SATA_DWC_OLD_DMA=y and CONFIG_SATA_DWC_OLD_DMA=n without giving any warnings.

I do not think it will. The if() will be compiled out if IS_ENABLED() is false, but the variable declaration will remain and so will the warning. Unless that declaration also goes away, IS_ENABLED() will not solve the issue. But if the variable is removed, I gree is is a lot cleaner !

Quoted 5 lines

Kind regards,
Niklas

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#12 lore raw
Quoted 22 lines · Damien Le Moal
Quoted 21 lines · Niklas Cassel
Quoted 8 lines · Damien Le Moal
Quoted 6 lines · Rosen Penev
Quoted 4 lines
Quoted 3 lines

Inside ifdef, that is probably why Sashiko did not catch this new warning.

Rosen, I suggest that you use dev->of_node directly within the ifdef, and drop the local np variable.

device_property_present is probably better. But yeah. I'll whip up a v2.

thinking about this some more. Should use IS_ENABLED to prevent hiding this code from the compiler.

Quoted 6 lines

What code are you talking about ?
What is in the #ifdef CONFIG_SATA_DWC_OLD_DMA ? CONFIG_SATA_DWC_OLD_DMA is determined automatically by Kconfig. So this is not hidding anything and why I did not see the warning in my compile tests (CONFIG_SATA_DWC_OLD_DMA was enabled for me). The report was for Sparc, and CONFIG_SATA_DWC_OLD_DMA was disabled so the unused variable warning showed up.

I think he means: keep the local np variable,
and replace the #ifdef with
if (IS_ENABLED(CONFIG_SATA_DWC_OLD_DMA) && !of_property_present(np, "dmas")) {

Quoted 7 lines
Quoted 2 lines

I think it will work for both CONFIG_SATA_DWC_OLD_DMA=y and CONFIG_SATA_DWC_OLD_DMA=n without giving any warnings.

I do not think it will. The if() will be compiled out if IS_ENABLED() is false, but the variable declaration will remain and so will the warning. Unless that declaration also goes away, IS_ENABLED() will not solve the issue. But if the variable is removed, I gree is is a lot cleaner !

The point of using IS_ENABLED, is that the compiler will see the code (that is what Rosen meant), and the code that is not used will be eliminated using dead code elimination from the compiler.

The statement:
if (0 && !of_property_present(np, "dmas")) {

Will not make the compiler consider np as unused.

I even verified it using:

if (IS_ENABLED(CONFIG_SATA_DWC_OLD_DMA) && !of_property_present(np, "dmas")) {

and if did not give my any warning when CONFIG_SATA_DWC_OLD_DMA=n.

However, I had to comment out the call to sata_dwc_dma_init_old() since sata_dwc_dma_init_old() is only defined inside #ifdef...

Sure, we could create a dummy / stub for that function, but to be honest, I think my earlier suggestion of just using dev->of_node directly within the ifdef, and drop the local np variable would be the smallest change.

Kind regards,
Niklas

maintainer
#13 lore raw
Quoted 3 lines · Niklas Cassel

Sure, we could create a dummy / stub for that function, but to be honest, I think my earlier suggestion of just using dev->of_node directly within the ifdef, and drop the local np variable would be the smallest change.

Yes. But I am not against replacing that ifdef with IS_ENABLED(). That's prettier :)

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#14 lore raw
Quoted 7 lines · Damien Le Moal
Quoted 3 lines · Niklas Cassel

Sure, we could create a dummy / stub for that function, but to be honest, I think my earlier suggestion of just using dev->of_node directly within the ifdef, and drop the local np variable would be the smallest change.

Yes. But I am not against replacing that ifdef with IS_ENABLED(). That's prettier :)

That is possible if we create a dummy / stub for sata_dwc_dma_init_old() (since that function is currently defined within #ifdef).

Kind regards,
Niklas

#15 lore raw
Quoted 7 lines · Niklas Cassel
Quoted 5 lines · Damien Le Moal
Quoted 3 lines · Niklas Cassel

Sure, we could create a dummy / stub for that function, but to be honest, I think my earlier suggestion of just using dev->of_node directly within the ifdef, and drop the local np variable would be the smallest change.

Quoted 5 lines
Quoted 2 lines

Yes. But I am not against replacing that ifdef with IS_ENABLED(). That's prettier :)

That is possible if we create a dummy / stub for sata_dwc_dma_init_old() (since that function is currently defined within #ifdef).

Yeah for that reason I'll keep it as it.

Quoted 4 lines

Kind regards,
Niklas