From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 477EEC433E1 for ; Sun, 21 Mar 2021 15:52:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 188766192B for ; Sun, 21 Mar 2021 15:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230165AbhCUPwH (ORCPT ); Sun, 21 Mar 2021 11:52:07 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:14414 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbhCUPv4 (ORCPT ); Sun, 21 Mar 2021 11:51:56 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4F3MXP3lNbzjLZG; Sun, 21 Mar 2021 23:50:13 +0800 (CST) Received: from [127.0.0.1] (10.174.176.117) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Sun, 21 Mar 2021 23:51:42 +0800 To: , , CC: , , "linux-kernel@vger.kernel.org" , linfeilong , From: Zhiqiang Liu Subject: [PATCH] pci/hotplug: fix potential memory leak in disable_slot() Message-ID: <245c1063-f0cf-551a-b93c-1a0a5ac06eff@huawei.com> Date: Sun, 21 Mar 2021 23:51:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.117] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In disable_slot(), if we obtain desired PCI device successfully by calling pci_get_slot(), we should call pci_dev_put() to release its reference. Signed-off-by: Zhiqiang Liu Signed-off-by: Feilong Lin --- drivers/pci/hotplug/s390_pci_hpc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/s390_pci_hpc.c b/drivers/pci/hotplug/s390_pci_hpc.c index c9e790c74051..999a34b6fd50 100644 --- a/drivers/pci/hotplug/s390_pci_hpc.c +++ b/drivers/pci/hotplug/s390_pci_hpc.c @@ -89,9 +89,11 @@ static int disable_slot(struct hotplug_slot *hotplug_slot) return -EIO; pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn); - if (pdev && pci_num_vf(pdev)) { + if (pdev) { + rc = pci_num_vf(pdev); pci_dev_put(pdev); - return -EBUSY; + if (rc) + return -EBUSY; } zpci_remove_device(zdev); -- 2.19.1