]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: hisilicon/qm - Fix device reference leak in qm_get_qos_value
authorMiaoqian Lin <linmq006@gmail.com>
Mon, 27 Oct 2025 15:09:34 +0000 (23:09 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 6 Nov 2025 06:29:49 +0000 (14:29 +0800)
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.

Fixes: 22d7a6c39cab ("crypto: hisilicon/qm - add pci bdf number check")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Longfang Liu <liulongfang@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/qm.c

index a5b96adf2d1e76c5b057ad371dfa5fcfbffcbe89..3b391a1466353d466bb129d11f5924a5ccc8646f 100644 (file)
@@ -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;
 }