Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5796860rwb; Tue, 22 Nov 2022 05:10:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf485pS0k8mPADlxjZ/njrmkXQrgkYyDbqwM8HzxYYBD8T3VD1m2n4weQnzGtrYWxL8DhQy8 X-Received: by 2002:a17:902:ee51:b0:189:1dda:5675 with SMTP id 17-20020a170902ee5100b001891dda5675mr6155731plo.115.1669122613807; Tue, 22 Nov 2022 05:10:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669122613; cv=none; d=google.com; s=arc-20160816; b=qj5dyYOs9laEvN7XsS5g6eqLGyiGqhaTCsi4S+RXydIdyCEU/rG7S5GcGM0QSDreuf 8FEXtO3GuoHFbwp7vKGA+7GoGKHO136bc5RoSiiQx+kMcVIsegne6TsDg1phbS23d2wq tOczys1QOdjmWSnDgNYL5mqDmfpnvNZTdcXlDQoGVgW78jc88I1Pe8QKpVxCfhmE/sMm unpyRZZYgLSOzzHhyLdEwaKeBwW+hiC/uwyLZF9M+uXqC5ABA024jAMwyG1JBdAXHY/B jxfzz9GdRLbl07UHMj8gRnxYtYwauzCqgULjZ7tN+Jy9o/YYmChr/dVDa/++7Xf1Wj0m kcZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3HETUZhbafwZ2VLQQMVxrIJrGqzgBZ2mQkwqvKoWlSA=; b=x34oqybfBOU+sfiutXrAX+PkhtkfrAKysV3FAl53aduXoOP3nTFvd8Ab6kiF1W451f G+h0lFfj5d3SMU82XLVVuxHdfWK9sWDTkumnCiu7RIErXmNwFHezdDW+tg4aXvTOPuJ0 xhza+VQIYeKHeehcPCxzNdmHf0K9EUM59r0HY999XIIdb1CtRRmxwXT1JbZNCa+5YXqk 7vFCRFDWIKUYvE6Zd4Tj2kv0b2v84GjvtwLdfOkibJZzrj1WEXCIp1JIymz66N3twOPL SEg3i4Abt7+PE/cfnGKKRu17simhKpCzdwcNb1D8sqr0RIyyxpZkF1RRN4GW1ciUxWR7 YIQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a170902db0200b001789faa627csi2194903plx.396.2022.11.22.05.10.00; Tue, 22 Nov 2022 05:10:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232788AbiKVL3t (ORCPT + 90 others); Tue, 22 Nov 2022 06:29:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233000AbiKVL2y (ORCPT ); Tue, 22 Nov 2022 06:28:54 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3312C6415 for ; Tue, 22 Nov 2022 03:22:39 -0800 (PST) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NGhg51dN7zRpPv; Tue, 22 Nov 2022 19:22:09 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 19:22:37 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 19:22:37 +0800 From: Xiongfeng Wang To: , CC: , , Subject: [PATCH] applicom: Fix PCI device refcount leak in applicom_init() Date: Tue, 22 Nov 2022 19:40:35 +0800 Message-ID: <20221122114035.24194-1-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As comment of pci_get_class() says, it returns a pci_device with its refcount increased and decreased the refcount for the input parameter @from if it is not NULL. If we break the loop in applicom_init() with 'dev' not NULL, we need to call pci_dev_put() to decrease the refcount. Add the missing pci_dev_put() to avoid refcount leak. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Xiongfeng Wang --- drivers/char/applicom.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c index 36203d3fa6ea..69314532f38c 100644 --- a/drivers/char/applicom.c +++ b/drivers/char/applicom.c @@ -197,8 +197,10 @@ static int __init applicom_init(void) if (!pci_match_id(applicom_pci_tbl, dev)) continue; - if (pci_enable_device(dev)) + if (pci_enable_device(dev)) { + pci_dev_put(dev); return -EIO; + } RamIO = ioremap(pci_resource_start(dev, 0), LEN_RAM_IO); @@ -207,6 +209,7 @@ static int __init applicom_init(void) "space at 0x%llx\n", (unsigned long long)pci_resource_start(dev, 0)); pci_disable_device(dev); + pci_dev_put(dev); return -EIO; } -- 2.20.1