Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1168621AbdDXKhM (ORCPT ); Mon, 24 Apr 2017 06:37:12 -0400 Received: from mga09.intel.com ([134.134.136.24]:8849 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1168607AbdDXKhE (ORCPT ); Mon, 24 Apr 2017 06:37:04 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,244,1488873600"; d="scan'208";a="1139395982" Date: Mon, 24 Apr 2017 13:36:58 +0300 From: Mika Westerberg To: Pan Bian Cc: Bjorn Helgaas , Lukas Wunner , Keith Busch , "Rafael J. Wysocki" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: Re: [PATCH 1/1] PCI: check return value of pci_find_ext_capability Message-ID: <20170424103658.GU7152@lahna.fi.intel.com> References: <1492956020-32271-1-git-send-email-bianpan201603@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1492956020-32271-1-git-send-email-bianpan201603@163.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1049 Lines: 26 On Sun, Apr 23, 2017 at 10:00:20PM +0800, Pan Bian wrote: > 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; I don't think this can happen because get_port_device_capability() will enumerate this capability and only if it exists, set PCIE_PORT_SERVICE_AER.