EDAC/altera: Guard against NULL of_node
Subsystems (2)
Dinh Nguyen
maintainercover EDAC/altera: Guard against NULL of_node
Hi EDAC maintainers,
I wanted to explain the reason why I think this patch doesn't need a Fixes tag. The way the Altera EDAC is written there are many instances of the driver referencing the of_node, which is why they are flagged in many sashiko reviews.
This patch checks for those NULL of_node in the probe functions using dev_of_node() so we don't have to guard the of_node in all the other functions.
The reason we don't need the Fixes tag is because this system is supposed to run with CONFIG_OF enabled. The system would fail way before it gets to this driver if an of_node is not found. Thus I don't see a need for a Fixes tag but the guard should be in place for completeness.
Thanks,
Dinh Nguyen (1):
EDAC/altera: Guard against NULL of_node pointer dereference
drivers/edac/altera_edac.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.42.0.411.g813d9a9188
Dinh Nguyen
maintainerPATCH 1/1 EDAC/altera: Guard against NULL of_node pointer dereference
There are many sashiko reports on this driver because it is using an unusually high amount of functions that dereference an of_node pointer. While you can guard the NULL pointer dereference in every function, it would be much simpler to guard it during probe functions. This edac driver is static, meaning it cannot add/remove nodes during runtime.
So it's best to use dev_of_node() in the probe functions, so if the of_node is NULL, the driver would simply fail to load.
--- drivers/edac/altera_edac.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/edac/altera_edac.c +9 -6
@@ -290,7 +290,7 @@ static int altr_sdram_probe(struct platform_device *pdev)unsigned long mem_size, irqflags =0 ;/* Grab the register range from the sdr controller in device tree */ - mc_vbase =syscon_regmap_lookup_by_phandle (pdev->dev.of_node, + mc_vbase =syscon_regmap_lookup_by_phandle (dev_of_node (&pdev->dev),"altr,sdr-syscon" );if (IS_ERR (mc_vbase)) { edac_printk(KERN_ERR, EDAC_MC,
@@ -507,9 +507,12 @@ MODULE_DEVICE_TABLE(of, altr_edac_of_match);static int altr_edac_probe (struct platform_device *pdev) { -of_platform_populate (pdev->dev.of_node, altr_edac_device_of_match, -NULL , &pdev->dev); -return 0 ; +int ret; + + ret =of_platform_populate (dev_of_node (&pdev->dev), altr_edac_device_of_match, +NULL , &pdev->dev); + +return ret; }static struct platform_driver altr_edac_driver = {
@@ -2184,7 +2187,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev) altr_edac_a10_irq_handler, edac); } -for_each_child_of_node (pdev->dev.of_node, child) { +for_each_child_of_node (dev_of_node (&pdev->dev), child) {if (!of_device_is_available (child))continue ;
@@ -2193,7 +2196,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev)#ifdef CONFIG_EDAC_ALTERA_SDRAM else if (of_device_is_compatible(child, "altr,sdram-edac-a10")) -of_platform_populate (pdev->dev.of_node, +of_platform_populate (dev_of_node (&pdev->dev), altr_sdram_ctrl_of_match,NULL , &pdev->dev);#endif
Signature · 1 line
2.42.0.411.g813d9a9188
Borislav Petkov
maintainerQuoted 6 lines · Dinh Nguyen
Hi EDAC maintainers,
I wanted to explain the reason why I think this patch doesn't need a Fixes tag. The way the Altera EDAC is written there are many instances of the driver referencing the
of_node, which is why they are flagged in many sashiko reviews.
If you think this patch would make your life easier, then sure. But we're not "fixing" the code just because a tool is stupid. No matter which tool it is.
Thx.