mbox series

[v2,0/2] hwrng: Fix PCI device refcount leak

Message ID 20221202132234.60631-1-wangxiongfeng2@huawei.com
Headers show
Series hwrng: Fix PCI device refcount leak | expand

Message

Xiongfeng Wang Dec. 2, 2022, 1:22 p.m. UTC
for_each_pci_dev() is implemented by pci_get_device(). The comment of
pci_get_device() says that it will increase the reference count for the
returned pci_dev and also decrease the reference count for the input
pci_dev @from if it is not NULL.

If we break for_each_pci_dev() loop with pdev not NULL, we need to call
pci_dev_put() to decrease the reference count. Add the missing
pci_dev_put() for amd-hwrng and geode-hwrng.


ChangeLog:
v1 -> v2:
  1. fix error in amd_rng_mod_exit()
  2. also add refcount leak fix for geode-hwrng

Xiongfeng Wang (2):
  hwrng: amd - Fix PCI device refcount leak
  hwrng: geode - Fix PCI device refcount leak

 drivers/char/hw_random/amd-rng.c   | 18 ++++++++++-----
 drivers/char/hw_random/geode-rng.c | 36 +++++++++++++++++++++++-------
 2 files changed, 41 insertions(+), 13 deletions(-)

Comments

Herbert Xu Dec. 9, 2022, 11:08 a.m. UTC | #1
On Fri, Dec 02, 2022 at 09:22:32PM +0800, Xiongfeng Wang wrote:
> for_each_pci_dev() is implemented by pci_get_device(). The comment of
> pci_get_device() says that it will increase the reference count for the
> returned pci_dev and also decrease the reference count for the input
> pci_dev @from if it is not NULL.
> 
> If we break for_each_pci_dev() loop with pdev not NULL, we need to call
> pci_dev_put() to decrease the reference count. Add the missing
> pci_dev_put() for amd-hwrng and geode-hwrng.
> 
> 
> ChangeLog:
> v1 -> v2:
>   1. fix error in amd_rng_mod_exit()
>   2. also add refcount leak fix for geode-hwrng
> 
> Xiongfeng Wang (2):
>   hwrng: amd - Fix PCI device refcount leak
>   hwrng: geode - Fix PCI device refcount leak
> 
>  drivers/char/hw_random/amd-rng.c   | 18 ++++++++++-----
>  drivers/char/hw_random/geode-rng.c | 36 +++++++++++++++++++++++-------
>  2 files changed, 41 insertions(+), 13 deletions(-)
> 
> -- 
> 2.20.1

All applied.  Thanks.