Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752904AbdDWOAz (ORCPT ); Sun, 23 Apr 2017 10:00:55 -0400 Received: from m50-133.163.com ([123.125.50.133]:58190 "EHLO m50-133.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1045557AbdDWOAq (ORCPT ); Sun, 23 Apr 2017 10:00:46 -0400 From: Pan Bian To: Bjorn Helgaas , Lukas Wunner , Keith Busch , "Rafael J. Wysocki" , Mika Westerberg , linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] PCI: check return value of pci_find_ext_capability Date: Sun, 23 Apr 2017 22:00:20 +0800 Message-Id: <1492956020-32271-1-git-send-email-bianpan201603@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DdGowAD3LIJ0s_xYYkItAA--.908S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xr4xGr4DZr1ruFW5GF1fXrb_yoWfKrg_uw 1xZrnrXrs5WF15K3s09F43ZryYk3W8Zrs3Ww48KFy3CF17AwnrZFZ7ZryDCw1fW34UZFyD uayDZr4Uury7AjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUn-dbUUUUUU== X-Originating-IP: [123.118.194.153] X-CM-SenderInfo: held01tdqsiiqwqtqiywtou0bp/xtbBXhfC91aDqPgCGAAAsj Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 927 Lines: 28 From: Pan Bian Function pci_find_ext_capability() will returns 0 on failure, and its return value should be checked before it is used. However, in function pcie_port_enable_msix(), its return value is not checked. This patch adds the check. Signed-off-by: Pan Bian --- drivers/pci/pcie/portdrv_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c index cea504f..001951d 100644 --- a/drivers/pci/pcie/portdrv_core.c +++ b/drivers/pci/pcie/portdrv_core.c @@ -103,6 +103,8 @@ static int pcie_port_enable_msix(struct pci_dev *dev, int *irqs, int mask) * interrupt message." */ pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); + if (!pos) + goto out_free_irqs; pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, ®32); entry = reg32 >> 27; if (entry >= nr_entries) -- 1.9.1