netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe()
@ 2023-04-08  6:56 Harshit Mogalapalli
  2023-04-08 15:32 ` Simon Horman
  0 siblings, 1 reply; 6+ messages in thread
From: Harshit Mogalapalli @ 2023-04-08  6:56 UTC (permalink / raw)
  To: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes
  Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel, error27,
	simon.horman, kernel-janitors, vegard.nossum, Harshit Mogalapalli

Smatch reports:
	drivers/net/wwan/iosm/iosm_ipc_pcie.c:298 ipc_pcie_probe()
	warn: missing unwind goto?

When dma_set_mask fails it directly returns without disabling pci
device and freeing ipc_pcie. Fix this my calling a correct goto label

As dma_set_mask returns either 0 or -EIO, we can use a goto label, as
it finally returns -EIO.

Renamed the goto label as name of the label before this patch is not
relevant after this patch.

Fixes: 035e3befc191 ("net: wwan: iosm: fix driver not working with INTEL_IOMMU disabled")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is based on static analysis, only compile tested.
---
 drivers/net/wwan/iosm/iosm_ipc_pcie.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
index 5bf5a93937c9..a6a6a0df1f7d 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
@@ -295,7 +295,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
 	ret = dma_set_mask(ipc_pcie->dev, DMA_BIT_MASK(64));
 	if (ret) {
 		dev_err(ipc_pcie->dev, "Could not set PCI DMA mask: %d", ret);
-		return ret;
+		goto err_disable_pci;
 	}
 
 	ipc_pcie_config_aspm(ipc_pcie);
@@ -308,7 +308,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
 	ipc_pcie->suspend = 0;
 
 	if (ipc_pcie_resources_request(ipc_pcie))
-		goto resources_req_fail;
+		goto err_disable_pci;
 
 	/* Establish the link to the imem layer. */
 	ipc_pcie->imem = ipc_imem_init(ipc_pcie, pci->device,
@@ -322,7 +322,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
 
 imem_init_fail:
 	ipc_pcie_resources_release(ipc_pcie);
-resources_req_fail:
+err_disable_pci:
 	pci_disable_device(pci);
 pci_enable_fail:
 	kfree(ipc_pcie);
-- 
2.38.1


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

* Re: [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe()
  2023-04-08  6:56 [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe() Harshit Mogalapalli
@ 2023-04-08 15:32 ` Simon Horman
  2023-04-08 17:42   ` Harshit Mogalapalli
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Horman @ 2023-04-08 15:32 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, error27,
	kernel-janitors, vegard.nossum

On Fri, Apr 07, 2023 at 11:56:07PM -0700, Harshit Mogalapalli wrote:
> Smatch reports:
> 	drivers/net/wwan/iosm/iosm_ipc_pcie.c:298 ipc_pcie_probe()
> 	warn: missing unwind goto?
> 
> When dma_set_mask fails it directly returns without disabling pci
> device and freeing ipc_pcie. Fix this my calling a correct goto label
> 
> As dma_set_mask returns either 0 or -EIO, we can use a goto label, as
> it finally returns -EIO.
> 
> Renamed the goto label as name of the label before this patch is not
> relevant after this patch.

nit: I agree that it's nice to name the labels after what they unwind,
rather than where they are called from. But now both schemes
are used in this function.
> 
> Fixes: 035e3befc191 ("net: wwan: iosm: fix driver not working with INTEL_IOMMU disabled")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> This is based on static analysis, only compile tested.

I agree with your analysis.

Reviewed-by: Simon Horman <simon.horman@corigine.com>

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

* Re: [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe()
  2023-04-08 15:32 ` Simon Horman
@ 2023-04-08 17:42   ` Harshit Mogalapalli
  2023-04-08 19:30     ` Simon Horman
  0 siblings, 1 reply; 6+ messages in thread
From: Harshit Mogalapalli @ 2023-04-08 17:42 UTC (permalink / raw)
  To: Simon Horman
  Cc: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, error27,
	kernel-janitors, vegard.nossum

Hi Simon,

On 08/04/23 9:02 pm, Simon Horman wrote:
> On Fri, Apr 07, 2023 at 11:56:07PM -0700, Harshit Mogalapalli wrote:
>> Smatch reports:
>> 	drivers/net/wwan/iosm/iosm_ipc_pcie.c:298 ipc_pcie_probe()
>> 	warn: missing unwind goto?
>>
>> When dma_set_mask fails it directly returns without disabling pci
>> device and freeing ipc_pcie. Fix this my calling a correct goto label
>>
>> As dma_set_mask returns either 0 or -EIO, we can use a goto label, as
>> it finally returns -EIO.
>>
>> Renamed the goto label as name of the label before this patch is not
>> relevant after this patch.
> 
> nit: I agree that it's nice to name the labels after what they unwind,
> rather than where they are called from. But now both schemes
> are used in this function.

Thanks a lot for the review.
I agree that the naming of the label is inconsistent, should we do 
something like below?

diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c 
b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
index 5bf5a93937c9..04517bd3325a 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
@@ -295,7 +295,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
         ret = dma_set_mask(ipc_pcie->dev, DMA_BIT_MASK(64));
         if (ret) {
                 dev_err(ipc_pcie->dev, "Could not set PCI DMA mask: 
%d", ret);
-               return ret;
+               goto set_mask_fail;
         }

         ipc_pcie_config_aspm(ipc_pcie);
@@ -323,6 +323,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
  imem_init_fail:
         ipc_pcie_resources_release(ipc_pcie);
  resources_req_fail:
+set_mask_fail:
         pci_disable_device(pci);
  pci_enable_fail:
         kfree(ipc_pcie);



-- but resources_req_fail: has nothing in its block particularly.

Thanks,
Harshit

>>
>> Fixes: 035e3befc191 ("net: wwan: iosm: fix driver not working with INTEL_IOMMU disabled")
>> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
>> ---
>> This is based on static analysis, only compile tested.
> 
> I agree with your analysis.
> 
> Reviewed-by: Simon Horman <simon.horman@corigine.com>

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

* Re: [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe()
  2023-04-08 17:42   ` Harshit Mogalapalli
@ 2023-04-08 19:30     ` Simon Horman
  2023-04-08 19:46       ` Harshit Mogalapalli
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Horman @ 2023-04-08 19:30 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, error27,
	kernel-janitors, vegard.nossum

On Sat, Apr 08, 2023 at 11:12:25PM +0530, Harshit Mogalapalli wrote:
> Hi Simon,
> 
> On 08/04/23 9:02 pm, Simon Horman wrote:
> > On Fri, Apr 07, 2023 at 11:56:07PM -0700, Harshit Mogalapalli wrote:
> > > Smatch reports:
> > > 	drivers/net/wwan/iosm/iosm_ipc_pcie.c:298 ipc_pcie_probe()
> > > 	warn: missing unwind goto?
> > > 
> > > When dma_set_mask fails it directly returns without disabling pci
> > > device and freeing ipc_pcie. Fix this my calling a correct goto label
> > > 
> > > As dma_set_mask returns either 0 or -EIO, we can use a goto label, as
> > > it finally returns -EIO.
> > > 
> > > Renamed the goto label as name of the label before this patch is not
> > > relevant after this patch.
> > 
> > nit: I agree that it's nice to name the labels after what they unwind,
> > rather than where they are called from. But now both schemes
> > are used in this function.
> 
> Thanks a lot for the review.
> I agree that the naming of the label is inconsistent, should we do something
> like below?
> 
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> index 5bf5a93937c9..04517bd3325a 100644
> --- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> +++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> @@ -295,7 +295,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
>         ret = dma_set_mask(ipc_pcie->dev, DMA_BIT_MASK(64));
>         if (ret) {
>                 dev_err(ipc_pcie->dev, "Could not set PCI DMA mask: %d",
> ret);
> -               return ret;
> +               goto set_mask_fail;
>         }
> 
>         ipc_pcie_config_aspm(ipc_pcie);
> @@ -323,6 +323,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
>  imem_init_fail:
>         ipc_pcie_resources_release(ipc_pcie);
>  resources_req_fail:
> +set_mask_fail:
>         pci_disable_device(pci);
>  pci_enable_fail:
>         kfree(ipc_pcie);
> 
> 
> 
> -- but resources_req_fail: has nothing in its block particularly.

I think this situation is common when one names the labels
after where they come from. So I'd say this is ok.

An alternative would be to rename all three of labels after what they
unwind.

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

* Re: [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe()
  2023-04-08 19:30     ` Simon Horman
@ 2023-04-08 19:46       ` Harshit Mogalapalli
  2023-04-10  8:00         ` Simon Horman
  0 siblings, 1 reply; 6+ messages in thread
From: Harshit Mogalapalli @ 2023-04-08 19:46 UTC (permalink / raw)
  To: Simon Horman
  Cc: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, error27,
	kernel-janitors, vegard.nossum

Hi Simon,

On 09/04/23 1:00 am, Simon Horman wrote:
> On Sat, Apr 08, 2023 at 11:12:25PM +0530, Harshit Mogalapalli wrote:
>> Hi Simon,
>>
>> On 08/04/23 9:02 pm, Simon Horman wrote:
>>> On Fri, Apr 07, 2023 at 11:56:07PM -0700, Harshit Mogalapalli wrote:
>>>> Smatch reports:
>>>> 	drivers/net/wwan/iosm/iosm_ipc_pcie.c:298 ipc_pcie_probe()
>>>> 	warn: missing unwind goto?
>>>>
>>>> When dma_set_mask fails it directly returns without disabling pci
>>>> device and freeing ipc_pcie. Fix this my calling a correct goto label
>>>>
>>>> As dma_set_mask returns either 0 or -EIO, we can use a goto label, as
>>>> it finally returns -EIO.
>>>>
>>>> Renamed the goto label as name of the label before this patch is not
>>>> relevant after this patch.
>>>
>>> nit: I agree that it's nice to name the labels after what they unwind,
>>> rather than where they are called from. But now both schemes
>>> are used in this function.
>>
>> Thanks a lot for the review.
>> I agree that the naming of the label is inconsistent, should we do something
>> like below?
>>
>> diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
>> b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
>> index 5bf5a93937c9..04517bd3325a 100644
>> --- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
>> +++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
>> @@ -295,7 +295,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
>>          ret = dma_set_mask(ipc_pcie->dev, DMA_BIT_MASK(64));
>>          if (ret) {
>>                  dev_err(ipc_pcie->dev, "Could not set PCI DMA mask: %d",
>> ret);
>> -               return ret;
>> +               goto set_mask_fail;
>>          }
>>
>>          ipc_pcie_config_aspm(ipc_pcie);
>> @@ -323,6 +323,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
>>   imem_init_fail:
>>          ipc_pcie_resources_release(ipc_pcie);
>>   resources_req_fail:
>> +set_mask_fail:
>>          pci_disable_device(pci);
>>   pci_enable_fail:
>>          kfree(ipc_pcie);
>>
>>
>>
>> -- but resources_req_fail: has nothing in its block particularly.
> 
> I think this situation is common when one names the labels
> after where they come from. So I'd say this is ok.
> 
Thanks I have a sent a V2 with this.

> An alternative would be to rename all three of labels after what they
> unwind.

Other functions in this file are using similar labels. So may be we 
could with above diff(V2 patch).

Regards,
Harshit

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

* Re: [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe()
  2023-04-08 19:46       ` Harshit Mogalapalli
@ 2023-04-10  8:00         ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2023-04-10  8:00 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, netdev, linux-kernel, error27,
	kernel-janitors, vegard.nossum

On Sun, Apr 09, 2023 at 01:16:49AM +0530, Harshit Mogalapalli wrote:
> Hi Simon,
> 
> On 09/04/23 1:00 am, Simon Horman wrote:
> > On Sat, Apr 08, 2023 at 11:12:25PM +0530, Harshit Mogalapalli wrote:
> > > Hi Simon,
> > > 
> > > On 08/04/23 9:02 pm, Simon Horman wrote:
> > > > On Fri, Apr 07, 2023 at 11:56:07PM -0700, Harshit Mogalapalli wrote:
> > > > > Smatch reports:
> > > > > 	drivers/net/wwan/iosm/iosm_ipc_pcie.c:298 ipc_pcie_probe()
> > > > > 	warn: missing unwind goto?
> > > > > 
> > > > > When dma_set_mask fails it directly returns without disabling pci
> > > > > device and freeing ipc_pcie. Fix this my calling a correct goto label
> > > > > 
> > > > > As dma_set_mask returns either 0 or -EIO, we can use a goto label, as
> > > > > it finally returns -EIO.
> > > > > 
> > > > > Renamed the goto label as name of the label before this patch is not
> > > > > relevant after this patch.
> > > > 
> > > > nit: I agree that it's nice to name the labels after what they unwind,
> > > > rather than where they are called from. But now both schemes
> > > > are used in this function.
> > > 
> > > Thanks a lot for the review.
> > > I agree that the naming of the label is inconsistent, should we do something
> > > like below?
> > > 
> > > diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> > > b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> > > index 5bf5a93937c9..04517bd3325a 100644
> > > --- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> > > +++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
> > > @@ -295,7 +295,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
> > >          ret = dma_set_mask(ipc_pcie->dev, DMA_BIT_MASK(64));
> > >          if (ret) {
> > >                  dev_err(ipc_pcie->dev, "Could not set PCI DMA mask: %d",
> > > ret);
> > > -               return ret;
> > > +               goto set_mask_fail;
> > >          }
> > > 
> > >          ipc_pcie_config_aspm(ipc_pcie);
> > > @@ -323,6 +323,7 @@ static int ipc_pcie_probe(struct pci_dev *pci,
> > >   imem_init_fail:
> > >          ipc_pcie_resources_release(ipc_pcie);
> > >   resources_req_fail:
> > > +set_mask_fail:
> > >          pci_disable_device(pci);
> > >   pci_enable_fail:
> > >          kfree(ipc_pcie);
> > > 
> > > 
> > > 
> > > -- but resources_req_fail: has nothing in its block particularly.
> > 
> > I think this situation is common when one names the labels
> > after where they come from. So I'd say this is ok.
> > 
> Thanks I have a sent a V2 with this.
> 
> > An alternative would be to rename all three of labels after what they
> > unwind.
> 
> Other functions in this file are using similar labels. So may be we could
> with above diff(V2 patch).

Yes, I agree that makes sense.

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

end of thread, other threads:[~2023-04-10  8:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-08  6:56 [PATCH net] net: wwan: iosm: Fix error handling path in ipc_pcie_probe() Harshit Mogalapalli
2023-04-08 15:32 ` Simon Horman
2023-04-08 17:42   ` Harshit Mogalapalli
2023-04-08 19:30     ` Simon Horman
2023-04-08 19:46       ` Harshit Mogalapalli
2023-04-10  8:00         ` Simon Horman

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