netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] octeon_ep: Add missing check for ioremap
@ 2023-06-14  3:23 Jiasheng Jiang
  2023-06-14  6:03 ` Kalesh Anakkur Purayil
  2023-06-14 19:53 ` Jakub Kicinski
  0 siblings, 2 replies; 5+ messages in thread
From: Jiasheng Jiang @ 2023-06-14  3:23 UTC (permalink / raw)
  To: vburru, aayarekar, davem, edumazet, kuba, pabeni, sburla
  Cc: netdev, linux-kernel, Jiasheng Jiang

Add check for ioremap() and return the error if it fails in order to
guarantee the success of ioremap().

Fixes: 862cd659a6fb ("octeon_ep: Add driver framework and device initialization")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
index e1853da280f9..06816d2baef8 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
@@ -969,7 +969,7 @@ static const char *octep_devid_to_str(struct octep_device *oct)
 int octep_device_setup(struct octep_device *oct)
 {
 	struct pci_dev *pdev = oct->pdev;
-	int i, ret;
+	int i, j, ret;
 
 	/* allocate memory for oct->conf */
 	oct->conf = kzalloc(sizeof(*oct->conf), GFP_KERNEL);
@@ -981,6 +981,9 @@ int octep_device_setup(struct octep_device *oct)
 		oct->mmio[i].hw_addr =
 			ioremap(pci_resource_start(oct->pdev, i * 2),
 				pci_resource_len(oct->pdev, i * 2));
+		if (!oct->mmio[i].hw_addr)
+			goto unsupported_dev;
+
 		oct->mmio[i].mapped = 1;
 	}
 
@@ -1015,8 +1018,8 @@ int octep_device_setup(struct octep_device *oct)
 	return 0;
 
 unsupported_dev:
-	for (i = 0; i < OCTEP_MMIO_REGIONS; i++)
-		iounmap(oct->mmio[i].hw_addr);
+	for (j = 0; j < i; j++)
+		iounmap(oct->mmio[j].hw_addr);
 
 	kfree(oct->conf);
 	return -1;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* Re: [PATCH] octeon_ep: Add missing check for ioremap
@ 2023-06-15  3:24 Jiasheng Jiang
  0 siblings, 0 replies; 5+ messages in thread
From: Jiasheng Jiang @ 2023-06-15  3:24 UTC (permalink / raw)
  To: kuba
  Cc: vburru, aayarekar, davem, edumazet, pabeni, sburla, netdev,
	linux-kernel, Jiasheng Jiang

On Thu, 15 Jun 2023 03:53:04 +0800 Jakub Kicinski wrote:
> On Wed, 14 Jun 2023 11:23:47 +0800 Jiasheng Jiang wrote:
>> @@ -981,6 +981,9 @@ int octep_device_setup(struct octep_device *oct)
>>  		oct->mmio[i].hw_addr =
>>  			ioremap(pci_resource_start(oct->pdev, i * 2),
>>  				pci_resource_len(oct->pdev, i * 2));
>> +		if (!oct->mmio[i].hw_addr)
>> +			goto unsupported_dev;
>> +
>>  		oct->mmio[i].mapped = 1;
>>  	}
>>  
>> @@ -1015,8 +1018,8 @@ int octep_device_setup(struct octep_device *oct)
>>  	return 0;
>>  
>>  unsupported_dev:
>> -	for (i = 0; i < OCTEP_MMIO_REGIONS; i++)
>> -		iounmap(oct->mmio[i].hw_addr);
>> +	for (j = 0; j < i; j++)
>> +		iounmap(oct->mmio[j].hw_addr);
> 
> Assuming @i is not changed by the rest of the function is a bit fragile.
> 
> Better way of handling this situation is:
> 
> unsupported_dev:
> 	i = OCTEP_MMIO_REGIONS;
> unmap_prev:
> 	while (i--)
> 		iounmap(oct->mmio[i].hw_addr);
> 
> and jump to unmap_prev

Fine, I will submit a v2 to fix it.

Thanks,
Jiasheng


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

end of thread, other threads:[~2023-06-15  3:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14  3:23 [PATCH] octeon_ep: Add missing check for ioremap Jiasheng Jiang
2023-06-14  6:03 ` Kalesh Anakkur Purayil
2023-06-14 19:51   ` Jakub Kicinski
2023-06-14 19:53 ` Jakub Kicinski
  -- strict thread matches above, loose matches on Subject: below --
2023-06-15  3:24 Jiasheng Jiang

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).