netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: broadcom: bcm4908enet: add platform_get_irq_byname error checking
@ 2022-09-09  6:25 Yu Zhe
  2022-09-12 11:29 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Yu Zhe @ 2022-09-09  6:25 UTC (permalink / raw)
  To: rafal, bcm-kernel-feedback-list, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, kernel-janitors, liqiong, Yu Zhe

The platform_get_irq_byname() function returns negative error codes on error,
check it.

Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
---
 drivers/net/ethernet/broadcom/bcm4908_enet.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
index c131d8118489..d985056db6c2 100644
--- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
@@ -705,6 +705,8 @@ static int bcm4908_enet_probe(struct platform_device *pdev)
 		return netdev->irq;
 
 	enet->irq_tx = platform_get_irq_byname(pdev, "tx");
+	if (enet->irq_tx < 0)
+		return enet->irq_tx;
 
 	err = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
 	if (err)
-- 
2.11.0


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

* Re: [PATCH] net: broadcom: bcm4908enet: add platform_get_irq_byname error checking
  2022-09-09  6:25 [PATCH] net: broadcom: bcm4908enet: add platform_get_irq_byname error checking Yu Zhe
@ 2022-09-12 11:29 ` Dan Carpenter
  2022-09-12 18:14   ` Florian Fainelli
  2022-09-15  9:49   ` Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-09-12 11:29 UTC (permalink / raw)
  To: Yu Zhe
  Cc: rafal, bcm-kernel-feedback-list, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, kernel-janitors, liqiong

On Fri, Sep 09, 2022 at 02:25:45PM +0800, Yu Zhe wrote:
> The platform_get_irq_byname() function returns negative error codes on error,
> check it.
> 
> Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
> ---
>  drivers/net/ethernet/broadcom/bcm4908_enet.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> index c131d8118489..d985056db6c2 100644
> --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
> +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> @@ -705,6 +705,8 @@ static int bcm4908_enet_probe(struct platform_device *pdev)
>  		return netdev->irq;
>  
>  	enet->irq_tx = platform_get_irq_byname(pdev, "tx");
> +	if (enet->irq_tx < 0)
> +		return enet->irq_tx;
>  

If you read the driver, then you will see that this is deliberate.
Search for irq_tx and read the comments.  I'm not a subsystem expert so
I don't know if this an ideal way to write the code, but it's done
deliberately so please don't change it unless you can test it.

regards,
dan carpenter


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

* Re: [PATCH] net: broadcom: bcm4908enet: add platform_get_irq_byname error checking
  2022-09-12 11:29 ` Dan Carpenter
@ 2022-09-12 18:14   ` Florian Fainelli
  2022-09-13 10:51     ` Dan Carpenter
  2022-09-15  9:49   ` Dan Carpenter
  1 sibling, 1 reply; 5+ messages in thread
From: Florian Fainelli @ 2022-09-12 18:14 UTC (permalink / raw)
  To: Dan Carpenter, Yu Zhe
  Cc: rafal, bcm-kernel-feedback-list, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, kernel-janitors, liqiong

On 9/12/22 04:29, Dan Carpenter wrote:
> On Fri, Sep 09, 2022 at 02:25:45PM +0800, Yu Zhe wrote:
>> The platform_get_irq_byname() function returns negative error codes on error,
>> check it.
>>
>> Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
>> ---
>>   drivers/net/ethernet/broadcom/bcm4908_enet.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
>> index c131d8118489..d985056db6c2 100644
>> --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
>> +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
>> @@ -705,6 +705,8 @@ static int bcm4908_enet_probe(struct platform_device *pdev)
>>   		return netdev->irq;
>>   
>>   	enet->irq_tx = platform_get_irq_byname(pdev, "tx");
>> +	if (enet->irq_tx < 0)
>> +		return enet->irq_tx;
>>   
> 
> If you read the driver, then you will see that this is deliberate.
> Search for irq_tx and read the comments.  I'm not a subsystem expert so
> I don't know if this an ideal way to write the code, but it's done
> deliberately so please don't change it unless you can test it.

Yup, the transmit interrupt is deemed optional, or at least was up to 
some point during the driver development. There is however a worthy bug 
you could fix:

   static int bcm4908_enet_stop(struct net_device *netdev)
   {
           struct bcm4908_enet *enet = netdev_priv(netdev);
           struct bcm4908_enet_dma_ring *tx_ring = &enet->tx_ring;
           struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring;

           netif_stop_queue(netdev);
           netif_carrier_off(netdev);
           napi_disable(&rx_ring->napi);
           napi_disable(&tx_ring->napi);

           bcm4908_enet_dma_rx_ring_disable(enet, &enet->rx_ring);
           bcm4908_enet_dma_tx_ring_disable(enet, &enet->tx_ring);

           bcm4908_enet_dma_uninit(enet);

           free_irq(enet->irq_tx, enet);

We might attempt to free an invalid interrupt here ^^

           free_irq(enet->netdev->irq, enet);

           return 0;
-- 
Florian

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

* Re: [PATCH] net: broadcom: bcm4908enet: add platform_get_irq_byname error checking
  2022-09-12 18:14   ` Florian Fainelli
@ 2022-09-13 10:51     ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-09-13 10:51 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Yu Zhe, rafal, bcm-kernel-feedback-list, davem, edumazet, kuba,
	pabeni, netdev, linux-kernel, kernel-janitors, liqiong

On Mon, Sep 12, 2022 at 11:14:42AM -0700, Florian Fainelli wrote:
> On 9/12/22 04:29, Dan Carpenter wrote:
> > On Fri, Sep 09, 2022 at 02:25:45PM +0800, Yu Zhe wrote:
> > > The platform_get_irq_byname() function returns negative error codes on error,
> > > check it.
> > > 
> > > Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
> > > ---
> > >   drivers/net/ethernet/broadcom/bcm4908_enet.c | 2 ++
> > >   1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> > > index c131d8118489..d985056db6c2 100644
> > > --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
> > > +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> > > @@ -705,6 +705,8 @@ static int bcm4908_enet_probe(struct platform_device *pdev)
> > >   		return netdev->irq;
> > >   	enet->irq_tx = platform_get_irq_byname(pdev, "tx");
> > > +	if (enet->irq_tx < 0)
> > > +		return enet->irq_tx;
> > 
> > If you read the driver, then you will see that this is deliberate.
> > Search for irq_tx and read the comments.  I'm not a subsystem expert so
> > I don't know if this an ideal way to write the code, but it's done
> > deliberately so please don't change it unless you can test it.
> 
> Yup, the transmit interrupt is deemed optional, or at least was up to some
> point during the driver development. There is however a worthy bug you could
> fix:
> 
>   static int bcm4908_enet_stop(struct net_device *netdev)
>   {
>           struct bcm4908_enet *enet = netdev_priv(netdev);
>           struct bcm4908_enet_dma_ring *tx_ring = &enet->tx_ring;
>           struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring;
> 
>           netif_stop_queue(netdev);
>           netif_carrier_off(netdev);
>           napi_disable(&rx_ring->napi);
>           napi_disable(&tx_ring->napi);
> 
>           bcm4908_enet_dma_rx_ring_disable(enet, &enet->rx_ring);
>           bcm4908_enet_dma_tx_ring_disable(enet, &enet->tx_ring);
> 
>           bcm4908_enet_dma_uninit(enet);
> 
>           free_irq(enet->irq_tx, enet);
> 
> We might attempt to free an invalid interrupt here ^^

Freeing a negative IRQ does not cause an issue.  The irq_to_desc()
function will return NULL so it becomes a no-op.

It's ugly code because you have to read in a couple different files to
verify that it works...

regards,
dan carpenter


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

* Re: [PATCH] net: broadcom: bcm4908enet: add platform_get_irq_byname error checking
  2022-09-12 11:29 ` Dan Carpenter
  2022-09-12 18:14   ` Florian Fainelli
@ 2022-09-15  9:49   ` Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-09-15  9:49 UTC (permalink / raw)
  To: Yu Zhe
  Cc: rafal, bcm-kernel-feedback-list, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, kernel-janitors, liqiong

On Mon, Sep 12, 2022 at 02:29:17PM +0300, Dan Carpenter wrote:
> On Fri, Sep 09, 2022 at 02:25:45PM +0800, Yu Zhe wrote:
> > The platform_get_irq_byname() function returns negative error codes on error,
> > check it.
> > 
> > Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
> > ---
> >  drivers/net/ethernet/broadcom/bcm4908_enet.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> > index c131d8118489..d985056db6c2 100644
> > --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
> > +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> > @@ -705,6 +705,8 @@ static int bcm4908_enet_probe(struct platform_device *pdev)
> >  		return netdev->irq;
> >  
> >  	enet->irq_tx = platform_get_irq_byname(pdev, "tx");
> > +	if (enet->irq_tx < 0)
> > +		return enet->irq_tx;
> >  
> 
> If you read the driver, then you will see that this is deliberate.
> Search for irq_tx and read the comments.  I'm not a subsystem expert so
> I don't know if this an ideal way to write the code, but it's done
> deliberately so please don't change it unless you can test it.

Btw, my comment of "don't change it unless you can test it" only applies
to this specific IRQ...  We constantly apply untested patches.  I have
submitted my share of buggy patches.  I don't want to discourage you
from your static analysis work.

regards,
dan carpenter


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

end of thread, other threads:[~2022-09-15  9:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09  6:25 [PATCH] net: broadcom: bcm4908enet: add platform_get_irq_byname error checking Yu Zhe
2022-09-12 11:29 ` Dan Carpenter
2022-09-12 18:14   ` Florian Fainelli
2022-09-13 10:51     ` Dan Carpenter
2022-09-15  9:49   ` Dan Carpenter

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