ocxl: fix pci device refcount leak when calling get_function_0()
authorYang Yingliang <yangyingliang@huawei.com>
Mon, 21 Nov 2022 15:43:39 +0000 (23:43 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 24 Nov 2022 12:31:46 +0000 (23:31 +1100)
commit5f58cad1e4c65bebee34292696c6d2105eeb2027
tree2e83ebfcdff8459ed1ec5f5a0da6dd4776faa2d2
parent295faa17722a11cac8dbf51e4c9f9405a5e07ef1
ocxl: fix pci device refcount leak when calling get_function_0()

get_function_0() calls pci_get_domain_bus_and_slot(), as comment
says, it returns a pci device with refcount increment, so after
using it, pci_dev_put() needs be called.

Get the device reference when get_function_0() is not called, so
pci_dev_put() can be called in the error path and callers
unconditionally. And add comment above get_dvsec_vendor0() to tell
callers to call pci_dev_put().

Fixes: 87db7579ebd5 ("ocxl: control via sysfs whether the FPGA is reloaded on a link reset")
Suggested-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Acked-by: Frederic Barrat <fbarrat@linux.ibm.com>
Acked-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221121154339.4088935-1-yangyingliang@huawei.com
drivers/misc/ocxl/config.c