Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764711AbcLVLvF (ORCPT ); Thu, 22 Dec 2016 06:51:05 -0500 Received: from mga07.intel.com ([134.134.136.100]:35669 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756443AbcLVLvD (ORCPT ); Thu, 22 Dec 2016 06:51:03 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,388,1477983600"; d="scan'208";a="915143304" Date: Thu, 22 Dec 2016 13:50:33 +0200 From: Mika Westerberg To: Arvind Yadav Cc: jarkko.nikula@linux.intel.com, wsa@the-dreams.de, andriy.shevchenko@linux.intel.com, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table Message-ID: <20161222115033.GO1460@lahna.fi.intel.com> References: <1482406759-13094-1-git-send-email-arvind.yadav.cs@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1482406759-13094-1-git-send-email-arvind.yadav.cs@gmail.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: 1081 Lines: 26 On Thu, Dec 22, 2016 at 05:09:19PM +0530, Arvind Yadav wrote: > Here, If pcim_iomap_table will fail. It will return NULL. > Kernel can run into a NULL-pointer dereference. > This error check will avoid NULL pointer dereference. > > Signed-off-by: Arvind Yadav > --- > drivers/i2c/busses/i2c-designware-pcidrv.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c > index d6423cf..6a1907d 100644 > --- a/drivers/i2c/busses/i2c-designware-pcidrv.c > +++ b/drivers/i2c/busses/i2c-designware-pcidrv.c > @@ -235,6 +235,10 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, > dev->controller = controller; > dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; > dev->base = pcim_iomap_table(pdev)[0]; > + if (!dev->base) { > + dev_err(&pdev->dev, "I/O map table allocation failed\n"); > + return -ENOMEM; Are you sure this can actually happen? IIRC pcim_iomap_regions() (which is called before this) makes sure the BARs you access here are valid.