linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table
@ 2016-12-22 11:39 Arvind Yadav
  2016-12-22 11:50 ` Mika Westerberg
  2016-12-22 14:35 ` Andy Shevchenko
  0 siblings, 2 replies; 4+ messages in thread
From: Arvind Yadav @ 2016-12-22 11:39 UTC (permalink / raw)
  To: jarkko.nikula, wsa
  Cc: andriy.shevchenko, mika.westerberg, linux-i2c, linux-kernel

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 <arvind.yadav.cs@gmail.com>
---
 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;
+	}
 	dev->dev = &pdev->dev;
 	dev->irq = pdev->irq;
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table
  2016-12-22 11:39 [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table Arvind Yadav
@ 2016-12-22 11:50 ` Mika Westerberg
  2016-12-22 14:35 ` Andy Shevchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Mika Westerberg @ 2016-12-22 11:50 UTC (permalink / raw)
  To: Arvind Yadav
  Cc: jarkko.nikula, wsa, andriy.shevchenko, linux-i2c, linux-kernel

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 <arvind.yadav.cs@gmail.com>
> ---
>  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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table
  2016-12-22 11:39 [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table Arvind Yadav
  2016-12-22 11:50 ` Mika Westerberg
@ 2016-12-22 14:35 ` Andy Shevchenko
  2016-12-22 17:11   ` arvind Yadav
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2016-12-22 14:35 UTC (permalink / raw)
  To: Arvind Yadav, jarkko.nikula, wsa; +Cc: mika.westerberg, linux-i2c, linux-kernel

On Thu, 2016-12-22 at 17:09 +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 <arvind.yadav.cs@gmail.com>
> ---
>  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;
> +	}

NAK.


-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table
  2016-12-22 14:35 ` Andy Shevchenko
@ 2016-12-22 17:11   ` arvind Yadav
  0 siblings, 0 replies; 4+ messages in thread
From: arvind Yadav @ 2016-12-22 17:11 UTC (permalink / raw)
  To: Andy Shevchenko, jarkko.nikula, wsa
  Cc: mika.westerberg, linux-i2c, linux-kernel

Yes, It will not fail. Sorry for the noise.

Thanks
-Arvind

On Thursday 22 December 2016 08:05 PM, Andy Shevchenko wrote:
> On Thu, 2016-12-22 at 17:09 +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 <arvind.yadav.cs@gmail.com>
>> ---
>>   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;
>> +	}
> NAK.
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-22 17:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-22 11:39 [v1] i2c: busses: i2c-designware-pcidrv:- Handle return NULL error from pcim_iomap_table Arvind Yadav
2016-12-22 11:50 ` Mika Westerberg
2016-12-22 14:35 ` Andy Shevchenko
2016-12-22 17:11   ` arvind Yadav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).