Message ID | 20190323033942.21796-1-kjlu@umn.edu |
---|---|
State | Rejected |
Delegated to: | David Miller |
Headers | show |
Series | net: stmmac: fix a potential NULL pointer dereference | expand |
From: Kangjie Lu <kjlu@umn.edu> Date: Fri, 22 Mar 2019 22:39:42 -0500 > @@ -485,6 +485,8 @@ static int dwc_eth_dwmac_remove(struct platform_device *pdev) > int err; > > data = of_device_get_match_data(&pdev->dev); > + if (!data) > + return -EINVAL; > > err = stmmac_dvr_remove(&pdev->dev); > if (err < 0) > -- > 2.17.1 > Please show me the entry in dwc_eth_dwmac_driver that has a NULL of_match_table field. Otherwise I'm not applying this.
From: Mukesh Ojha <mojha@codeaurora.org> Date: Tue, 26 Mar 2019 15:27:03 +0530 > > On 3/23/2019 9:09 AM, Kangjie Lu wrote: >> In case of_device_get_match_data fails, the fix return -EINVAL >> to avoid the NULL pointer dereference. >> >> Signed-off-by: Kangjie Lu <kjlu@umn.edu> >> --- >> drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c >> b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c >> index 3256e5cbad27..344ead5949b1 100644 >> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c >> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c >> @@ -485,6 +485,8 @@ static int dwc_eth_dwmac_remove(struct >> platform_device *pdev) >> int err; >> data = of_device_get_match_data(&pdev->dev); >> + if (!data) >> + return -EINVAL; > > Although, it is false alarm for this driver as of_match_table is not > NULL, but it would be good to add the check. I disagree. This is adding a check just for the sake of adding the check and shutting up a static analysis tool. Now, if the tool looked at the table entries being fed into this function, and found such a posibility then we would fix the bug and still not add the check.
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c index 3256e5cbad27..344ead5949b1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c @@ -485,6 +485,8 @@ static int dwc_eth_dwmac_remove(struct platform_device *pdev) int err; data = of_device_get_match_data(&pdev->dev); + if (!data) + return -EINVAL; err = stmmac_dvr_remove(&pdev->dev); if (err < 0)
In case of_device_get_match_data fails, the fix return -EINVAL to avoid the NULL pointer dereference. Signed-off-by: Kangjie Lu <kjlu@umn.edu> --- drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 ++ 1 file changed, 2 insertions(+)