Message ID | 20241216022538.381209-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive) |
---|---|
State | Accepted, archived |
Headers | show |
Series | platform/x86: mlx-platform: call pci_dev_put() to balance the refcount | expand |
> -----Original Message----- > From: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> > Sent: Monday, 16 December 2024 4:26 > To: Vadim Pasternak <vadimp@nvidia.com>; hdegoede@redhat.com; > ilpo.jarvinen@linux.intel.com > Cc: platform-driver-x86@vger.kernel.org; Joe Hattori <joe@pf.is.s.u- > tokyo.ac.jp> > Subject: [PATCH] platform/x86: mlx-platform: call pci_dev_put() to balance the > refcount > > mlxplat_pci_fpga_device_init() calls pci_get_device() but does not release the > refcount on error path. Call pci_dev_put() on the error path and in > mlxplat_pci_fpga_device_exit() to fix this. > > This bug was found by an experimental static analysis tool that I am > developing. > > Fixes: 02daa222fbdd ("platform: mellanox: Add initial support for PCIe based > programming logic device") > Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> Reviewed-by: Vadim Pasternak <vadimp@nvidia.com> > --- > drivers/platform/x86/mlx-platform.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/platform/x86/mlx-platform.c b/drivers/platform/x86/mlx- > platform.c > index 671021cd1f59..9c7f30a47f1f 100644 > --- a/drivers/platform/x86/mlx-platform.c > +++ b/drivers/platform/x86/mlx-platform.c > @@ -6237,6 +6237,7 @@ mlxplat_pci_fpga_device_init(unsigned int device, > const char *res_name, struct p > fail_pci_request_regions: > pci_disable_device(pci_dev); > fail_pci_enable_device: > + pci_dev_put(pci_dev); > return err; > } > > @@ -6247,6 +6248,7 @@ mlxplat_pci_fpga_device_exit(struct pci_dev > *pci_bridge, > iounmap(pci_bridge_addr); > pci_release_regions(pci_bridge); > pci_disable_device(pci_bridge); > + pci_dev_put(pci_bridge); > } > > static int > -- > 2.34.1
On Mon, 16 Dec 2024 11:25:38 +0900, Joe Hattori wrote: > mlxplat_pci_fpga_device_init() calls pci_get_device() but does not > release the refcount on error path. Call pci_dev_put() on the error path > and in mlxplat_pci_fpga_device_exit() to fix this. > > This bug was found by an experimental static analysis tool that I am > developing. > > [...] Thank you for your contribution, it has been applied to my local review-ilpo-fixes branch. Note it will show up in the public platform-drivers-x86/review-ilpo-fixes branch only once I've pushed my local branch there, which might take a while. The list of commits applied: [1/1] platform/x86: mlx-platform: call pci_dev_put() to balance the refcount commit: 185e1b1d91e419445d3fd99c1c0376a970438acf -- i.
diff --git a/drivers/platform/x86/mlx-platform.c b/drivers/platform/x86/mlx-platform.c index 671021cd1f59..9c7f30a47f1f 100644 --- a/drivers/platform/x86/mlx-platform.c +++ b/drivers/platform/x86/mlx-platform.c @@ -6237,6 +6237,7 @@ mlxplat_pci_fpga_device_init(unsigned int device, const char *res_name, struct p fail_pci_request_regions: pci_disable_device(pci_dev); fail_pci_enable_device: + pci_dev_put(pci_dev); return err; } @@ -6247,6 +6248,7 @@ mlxplat_pci_fpga_device_exit(struct pci_dev *pci_bridge, iounmap(pci_bridge_addr); pci_release_regions(pci_bridge); pci_disable_device(pci_bridge); + pci_dev_put(pci_bridge); } static int
mlxplat_pci_fpga_device_init() calls pci_get_device() but does not release the refcount on error path. Call pci_dev_put() on the error path and in mlxplat_pci_fpga_device_exit() to fix this. This bug was found by an experimental static analysis tool that I am developing. Fixes: 02daa222fbdd ("platform: mellanox: Add initial support for PCIe based programming logic device") Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> --- drivers/platform/x86/mlx-platform.c | 2 ++ 1 file changed, 2 insertions(+)