diff mbox series

net: stmmac: Check NULL ptr on lvts_data in qcom_ethqos_probe()

Message ID 20240821131949.1465949-1-make24@iscas.ac.cn (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: stmmac: Check NULL ptr on lvts_data in qcom_ethqos_probe() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-08-21--21-00 (tests: 712)

Commit Message

Ma Ke Aug. 21, 2024, 1:19 p.m. UTC
of_device_get_match_data() can return NULL if of_match_device failed, and
the pointer 'data' was dereferenced without checking against NULL. Add
checking of pointer 'data' in qcom_ethqos_probe().

Cc: stable@vger.kernel.org
Fixes: a7c30e62d4b8 ("net: stmmac: Add driver for Qualcomm ethqos")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Simon Horman Aug. 21, 2024, 5:37 p.m. UTC | #1
On Wed, Aug 21, 2024 at 09:19:49PM +0800, Ma Ke wrote:
> of_device_get_match_data() can return NULL if of_match_device failed, and
> the pointer 'data' was dereferenced without checking against NULL. Add
> checking of pointer 'data' in qcom_ethqos_probe().
> 
> Cc: stable@vger.kernel.org
> Fixes: a7c30e62d4b8 ("net: stmmac: Add driver for Qualcomm ethqos")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>

Hi Ma Ke,

There is probably no need to repost just because of this.
But as a fix for Networking code it should be targeted at the net tree.

	Subject: [PATCH net] ...

> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> index 901a3c1959fa..f18393fe58a4 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> @@ -838,6 +838,9 @@ static int qcom_ethqos_probe(struct platform_device *pdev)
>  	ethqos->mac_base = stmmac_res.addr;
>  
>  	data = of_device_get_match_data(dev);
> +	if (!data)
> +		return -ENODEV;
> +

In this function dev_err_probe() is used, I assume in cases
where a function that returns an error does not emit any logs.

For consistency, perhaps that is appropriate here too?

>  	ethqos->por = data->por;
>  	ethqos->num_por = data->num_por;
>  	ethqos->rgmii_config_loopback_en = data->rgmii_config_loopback_en;
> -- 
> 2.25.1
Bjorn Andersson Aug. 21, 2024, 7:18 p.m. UTC | #2
On Wed, Aug 21, 2024 at 06:37:30PM +0100, Simon Horman wrote:
> On Wed, Aug 21, 2024 at 09:19:49PM +0800, Ma Ke wrote:
> > of_device_get_match_data() can return NULL if of_match_device failed, and
> > the pointer 'data' was dereferenced without checking against NULL. Add
> > checking of pointer 'data' in qcom_ethqos_probe().
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: a7c30e62d4b8 ("net: stmmac: Add driver for Qualcomm ethqos")
> > Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> 
> Hi Ma Ke,
> 
> There is probably no need to repost just because of this.
> But as a fix for Networking code it should be targeted at the net tree.
> 
> 	Subject: [PATCH net] ...
> 
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> > index 901a3c1959fa..f18393fe58a4 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> > @@ -838,6 +838,9 @@ static int qcom_ethqos_probe(struct platform_device *pdev)
> >  	ethqos->mac_base = stmmac_res.addr;
> >  
> >  	data = of_device_get_match_data(dev);
> > +	if (!data)
> > +		return -ENODEV;
> > +
> 
> In this function dev_err_probe() is used, I assume in cases
> where a function that returns an error does not emit any logs.
> 
> For consistency, perhaps that is appropriate here too?
> 

Unless I'm missing something here this function can only ever be invoked
by a match against one of the entries in qcom_ethqos_match[], which all
of them have a non-NULL data pointer.

As such, if we somehow arrive here with data of NULL, the NULL pointer
dereference on the next line will provide a welcome large splat and a
callstack indicating that we have a problem.


If there's some use case I'm missing, I would prefer if this was
documented in the commit message.

Regards,
Bjorn

> >  	ethqos->por = data->por;
> >  	ethqos->num_por = data->num_por;
> >  	ethqos->rgmii_config_loopback_en = data->rgmii_config_loopback_en;
> > -- 
> > 2.25.1
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
index 901a3c1959fa..f18393fe58a4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
@@ -838,6 +838,9 @@  static int qcom_ethqos_probe(struct platform_device *pdev)
 	ethqos->mac_base = stmmac_res.addr;
 
 	data = of_device_get_match_data(dev);
+	if (!data)
+		return -ENODEV;
+
 	ethqos->por = data->por;
 	ethqos->num_por = data->num_por;
 	ethqos->rgmii_config_loopback_en = data->rgmii_config_loopback_en;