Skip to contentSkip to conversation

soc: ti: pruss: Fix return value check

PATCH In review Wei Yongjun 2 participants 2 messages Sep 15, 2020 – Sep 17, 2020

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

PATCH 1/1 soc: ti: pruss: Fix return value check

In case of error, the function of_device_get_match_data() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Fixes ba59c9b43c86 ("soc: ti: pruss: support CORECLK_MUX and IEPCLK_MUX")
---
 drivers/soc/ti/pruss.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/ti/pruss.c +2 -2
index cc0b4ad7a3d3..582f48051c30 100644
@@ -126,7 +126,7 @@ static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node)
 	int ret = 0;
 
 	data = of_device_get_match_data(dev);
-	if (IS_ERR(data))
+	if (!data)
 		return -ENODEV;
 
 	clks_np = of_get_child_by_name(cfg_node, "clocks");
@@ -175,7 +175,7 @@ static int pruss_probe(struct platform_device *pdev)
 	const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" };
 
 	data = of_device_get_match_data(&pdev->dev);
-	if (IS_ERR(data)) {
+	if (!data) {
 		dev_err(dev, "missing private data\n");
 		return -ENODEV;
 	}
#1 lore raw

Hi

Quoted 26 lines · Wei Yongjun

In case of error, the function of_device_get_match_data() returns NULL pointer not ERR_PTR(). The IS_ERR() test in the return value check should be replaced with NULL test.

Fixes ba59c9b43c86 ("soc: ti: pruss: support CORECLK_MUX and IEPCLK_MUX")
---
 drivers/soc/ti/pruss.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/ti/pruss.c +1 -1
index cc0b4ad7a3d3..582f48051c30 100644
@@ -126,7 +126,7 @@ static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node)
        int ret = 0;
 
        data = of_device_get_match_data(dev);
-       if (IS_ERR(data))
+       if (!data)
                return -ENODEV;
 
        clks_np = of_get_child_by_name(cfg_node, "clocks");

drivers/soc/ti/pruss.c static int pruss_probe(struct platform_device *pdev) · line 181

Quoted 8 lines
drivers/soc/ti/pruss.c +1 -1
@@ -175,7 +175,7 @@ static int pruss_probe(struct platform_device *pdev)
        const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" };
 
        data = of_device_get_match_data(&pdev->dev);
-       if (IS_ERR(data)) {
+       if (!data) {
                dev_err(dev, "missing private data\n");
                return -ENODEV;
        }

First of all thank you for reporting this issue. Indeed the IS_ERR is wrongly used and is leftover from a bit different former internal implementation. Nevertheless with your fix the driver will not be functional anymore for all devices without match data (e.g. "ti,am3356-pruss") which is not what we want.

The proper fix would be removing the mentioned error checks, since the "data" in both cases is checked later, before usage:
if (data && data->...).

Please let me know if you want to improve this patch by yourself or want me to push a proper fix with your e.g. "Reported-by:" tag. For me both solutions are ok.

Thank you,
Grzegorz