crypto: hisilicon/qm - Fix device reference leak in qm_get_qos_value
Subsystems (3)
PATCH 1/1 crypto: hisilicon/qm - Fix device reference leak in qm_get_qos_value
The qm_get_qos_value() function calls bus_find_device_by_name() which increases the device reference count, but fails to call put_device() to balance the reference count and lead to a device reference leak.
Add put_device() calls in both the error path and success path to properly balance the reference count.
Found via static analysis.
--- drivers/crypto/hisilicon/qm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/crypto/hisilicon/qm.c +2 -0
@@ -3871,10 +3871,12 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf, pdev = container_of(dev, struct pci_dev, dev);if (pci_physfn (pdev) != qm->pdev) {pci_err (qm->pdev,"the pdev input does not match the pf!\n" ); +put_device (dev);return -EINVAL ; } *fun_index = pdev->devfn; +put_device (dev);return 0 ; }
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 24 lines · Miaoqian Lin
The
qm_get_qos_value()function callsbus_find_device_by_name()which increases the device reference count, but fails to callput_device()to balance the reference count and lead to a device reference leak.Add
put_device()calls in both the error path and success path to properly balance the reference count.Found via static analysis.
Fixes 22d7a6c39cab ("crypto: hisilicon/qm - add pci bdf number check")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/crypto/hisilicon/qm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/crypto/hisilicon/qm.c +0
-0@@ -3871,10 +3871,12 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf, pdev = container_of(dev, struct pci_dev, dev);if (pci_physfn (pdev) != qm->pdev) {
drivers/crypto/hisilicon/qm.c static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf, · line 3882
Quoted 10 lines
drivers/crypto/hisilicon/qm.c +2
-0pci_err (qm->pdev,"the pdev input does not match the pf!\n" ); +put_device (dev);return -EINVAL ; } *fun_index = pdev->devfn; +put_device (dev);return 0 ; }
Thanks.
Herbert Xu
maintainerQuoted 7 lines · Miaoqian Lin
The
qm_get_qos_value()function callsbus_find_device_by_name()which increases the device reference count, but fails to callput_device()to balance the reference count and lead to a device reference leak.Add
put_device()calls in both the error path and success path to properly balance the reference count.
Quoted 8 lines
Found via static analysis.
Fixes 22d7a6c39cab ("crypto: hisilicon/qm - add pci bdf number check")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/crypto/hisilicon/qm.c | 2 ++ 1 file changed, 2 insertions(+)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt