diff mbox series

net: ethernet: enetc: Add missing put_device() call

Message ID 20220415133633.87127-1-hanyihao@vivo.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: enetc: Add missing put_device() call | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 0 this patch: 9
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang fail Errors and warnings before: 0 this patch: 9
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 0 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yihao Han April 15, 2022, 1:36 p.m. UTC
A coccicheck run provided information like the following.

drivers/net/ethernet/freescale/enetc/enetc_pf.c:1180:1-7:
ERROR: missing put_device; call of_find_device_by_node
on line 1174, but without a corresponding object release
within this function.

Generated by: scripts/coccinelle/free/put_device.cocci

Signed-off-by: Yihao Han <hanyihao@vivo.com>
---
 drivers/net/ethernet/freescale/enetc/enetc_pf.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Paolo Abeni April 19, 2022, 8:22 a.m. UTC | #1
On Fri, 2022-04-15 at 06:36 -0700, Yihao Han wrote:
> A coccicheck run provided information like the following.
> 
> drivers/net/ethernet/freescale/enetc/enetc_pf.c:1180:1-7:
> ERROR: missing put_device; call of_find_device_by_node
> on line 1174, but without a corresponding object release
> within this function.
> 
> Generated by: scripts/coccinelle/free/put_device.cocci
> 
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> ---
>  drivers/net/ethernet/freescale/enetc/enetc_pf.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> index a0c75c717073..d6e18afda69a 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
> @@ -1177,6 +1177,7 @@ static int enetc_pf_register_with_ierb(struct pci_dev *pdev)
>  	if (!ierb_pdev)
>  		return -EPROBE_DEFER;
>  
> +	put_device(ierb_pdev);

put_device() gets a 'struct device' argument, e.g. ierb_pdev->dev.

Have a look at the patchwork checks they catch this sort of issue.

>  	return enetc_ierb_register_pf(ierb_pdev, pdev);

enetc_ierb_register_pf() uses/dereference ierb_pdev, you need to
release the device reference after the above call, or you may hit UaF,
I guess.

Thanks,

Paolo
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index a0c75c717073..d6e18afda69a 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -1177,6 +1177,7 @@  static int enetc_pf_register_with_ierb(struct pci_dev *pdev)
 	if (!ierb_pdev)
 		return -EPROBE_DEFER;
 
+	put_device(ierb_pdev);
 	return enetc_ierb_register_pf(ierb_pdev, pdev);
 }