Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2862465pxf; Sun, 21 Mar 2021 09:24:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzC0OQqC84/XUBkWFolVO6Ej+xJgRPKNMRduznVPzmIhKb5KYMEu9MHp+rcV/Tx0FzBR4o0 X-Received: by 2002:a05:6402:105a:: with SMTP id e26mr21191622edu.164.1616343875258; Sun, 21 Mar 2021 09:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616343875; cv=none; d=google.com; s=arc-20160816; b=SXgY8TavC0nCiJeSCoj0W7CYQVurxXYZKbj6rTZ2K5ujwSJpdz9NmhDhtJXwqD2+Pn NjUoGX6S3j0Tc1/vDbwDTyUGO/fpeB0x8e22R71E0Ujgr4BW8zi0uBN1Ph+nOpknFKNP Pr4INOeyzIk+/qazIQrP/u3Z/IBGopy0YYo4KUfw3HVObMohQ631WtOGsXt7GoIhjXwp o2FcxdY1QmtebL53CZmIxkN+M5qVhkVSN2DfZSywfhlDsbSgHICEz7Bjp5UPFUnupoDs NSOg23xVW3rNSKwd0XTEUC2tciag9SEXvjzUr3R0BlJGv6Xg8Cjkd3xtEZD8D5SUbcws Iicw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:cc:to; bh=tfPSnBkVFDV2CEZ92REC6zSKJnmv6NoTyLZguHY1k1M=; b=T4+UnLubnUlGGXzYMlzch0Z6UEwpdOlwTzAs0cj8c7HBTcZ0DrXRl4Iiroch1pgehY 0FchRKrVv4rtHCaFG6zLmZaQ6Sq3mPGY9dWrTHmLyGuC2HPeJAyEA494CqacEnnVTmX7 Ut6au05PqMrtkKBgs7p5GX9eUO/JI+lbWvJkNGpIzc0mw2RRt2qsHwpYns6dImA35ps6 bhfUzeLuM5jEto4zUQE5mLJtPnhnArRKkR1Kt0LLSa91y6H3mAtjN44RmpWN92oQeU12 NvvZ35ulWW7jMxFa0Gb6IKxCDsn+0S0wP66xAoZOezsbMxnW6hUEKAh8etd/wzrRpjiw Uc5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si9293670edm.261.2021.03.21.09.24.12; Sun, 21 Mar 2021 09:24:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230157AbhCUPwG (ORCPT + 99 others); Sun, 21 Mar 2021 11:52:06 -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