public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: ntb_netdev: Fix NULL check ordering in TX handler
@ 2026-02-24 13:04 Alok Tiwari
  2026-02-24 14:42 ` Dave Jiang
  2026-02-26  3:22 ` Jakub Kicinski
  0 siblings, 2 replies; 4+ messages in thread
From: Alok Tiwari @ 2026-02-24 13:04 UTC (permalink / raw)
  To: pabeni, kuba, edumazet, davem, andrew+netdev, jdmason, dave.jiang,
	allenbh, ntb, netdev
  Cc: alok.a.tiwarilinux, alok.a.tiwari

ntb_netdev_tx_handler() calls netdev_priv(ndev) before checking
whether ndev is NULL. Although qp_data is expected to always be
valid in normal operation, dereferencing the pointer before the
NULL check is logically incorrect.

Move netdev_priv() after validating ndev.

No functional change intended.

Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
---
 drivers/net/ntb_netdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ntb_netdev.c b/drivers/net/ntb_netdev.c
index fbeae05817e9..6792b3b1f253 100644
--- a/drivers/net/ntb_netdev.c
+++ b/drivers/net/ntb_netdev.c
@@ -177,13 +177,15 @@ static void ntb_netdev_tx_handler(struct ntb_transport_qp *qp, void *qp_data,
 				  void *data, int len)
 {
 	struct net_device *ndev = qp_data;
+	struct ntb_netdev *dev;
 	struct sk_buff *skb;
-	struct ntb_netdev *dev = netdev_priv(ndev);
 
 	skb = data;
 	if (!skb || !ndev)
 		return;
 
+	dev = netdev_priv(ndev);
+
 	if (len > 0) {
 		ndev->stats.tx_packets++;
 		ndev->stats.tx_bytes += skb->len;
-- 
2.50.1


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

* Re: [PATCH net-next] net: ntb_netdev: Fix NULL check ordering in TX handler
  2026-02-24 13:04 [PATCH net-next] net: ntb_netdev: Fix NULL check ordering in TX handler Alok Tiwari
@ 2026-02-24 14:42 ` Dave Jiang
  2026-02-26  3:22 ` Jakub Kicinski
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Jiang @ 2026-02-24 14:42 UTC (permalink / raw)
  To: Alok Tiwari, pabeni, kuba, edumazet, davem, andrew+netdev,
	jdmason, allenbh, ntb, netdev
  Cc: alok.a.tiwarilinux



On 2/24/26 6:04 AM, Alok Tiwari wrote:
> ntb_netdev_tx_handler() calls netdev_priv(ndev) before checking
> whether ndev is NULL. Although qp_data is expected to always be
> valid in normal operation, dereferencing the pointer before the
> NULL check is logically incorrect.
> 
> Move netdev_priv() after validating ndev.
> 
> No functional change intended.
> 
> Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>

Acked-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  drivers/net/ntb_netdev.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ntb_netdev.c b/drivers/net/ntb_netdev.c
> index fbeae05817e9..6792b3b1f253 100644
> --- a/drivers/net/ntb_netdev.c
> +++ b/drivers/net/ntb_netdev.c
> @@ -177,13 +177,15 @@ static void ntb_netdev_tx_handler(struct ntb_transport_qp *qp, void *qp_data,
>  				  void *data, int len)
>  {
>  	struct net_device *ndev = qp_data;
> +	struct ntb_netdev *dev;
>  	struct sk_buff *skb;
> -	struct ntb_netdev *dev = netdev_priv(ndev);
>  
>  	skb = data;
>  	if (!skb || !ndev)
>  		return;
>  
> +	dev = netdev_priv(ndev);
> +
>  	if (len > 0) {
>  		ndev->stats.tx_packets++;
>  		ndev->stats.tx_bytes += skb->len;


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

* Re: [PATCH net-next] net: ntb_netdev: Fix NULL check ordering in TX handler
  2026-02-24 13:04 [PATCH net-next] net: ntb_netdev: Fix NULL check ordering in TX handler Alok Tiwari
  2026-02-24 14:42 ` Dave Jiang
@ 2026-02-26  3:22 ` Jakub Kicinski
  2026-02-26 14:14   ` ALOK TIWARI
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2026-02-26  3:22 UTC (permalink / raw)
  To: Alok Tiwari
  Cc: pabeni, edumazet, davem, andrew+netdev, jdmason, dave.jiang,
	allenbh, ntb, netdev, alok.a.tiwarilinux

On Tue, 24 Feb 2026 05:04:47 -0800 Alok Tiwari wrote:
> ntb_netdev_tx_handler() calls netdev_priv(ndev) before checking
> whether ndev is NULL. Although qp_data is expected to always be
> valid in normal operation,

Right. Can we delete the seemingly pointless null check instead?
Defensive programming is discouraged in the kernel..

> dereferencing the pointer before the
> NULL check is logically incorrect.

If you strongly prefer to keep the patch as is maybe say "valid 
but surprising" rather than "logically incorrect"

> Move netdev_priv() after validating ndev.
> 
> No functional change intended.
-- 
pw-bot: cr

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

* Re: [PATCH net-next] net: ntb_netdev: Fix NULL check ordering in TX handler
  2026-02-26  3:22 ` Jakub Kicinski
@ 2026-02-26 14:14   ` ALOK TIWARI
  0 siblings, 0 replies; 4+ messages in thread
From: ALOK TIWARI @ 2026-02-26 14:14 UTC (permalink / raw)
  To: Jakub Kicinski, Koichiro Den
  Cc: pabeni, edumazet, davem, andrew+netdev, jdmason, dave.jiang,
	allenbh, ntb, netdev, alok.a.tiwarilinux



On 2/26/2026 8:52 AM, Jakub Kicinski wrote:
> On Tue, 24 Feb 2026 05:04:47 -0800 Alok Tiwari wrote:
>> ntb_netdev_tx_handler() calls netdev_priv(ndev) before checking
>> whether ndev is NULL. Although qp_data is expected to always be
>> valid in normal operation,
> Right. Can we delete the seemingly pointless null check instead?
> Defensive programming is discouraged in the kernel..
> 
>> dereferencing the pointer before the
>> NULL check is logically incorrect.
> If you strongly prefer to keep the patch as is maybe say "valid
> but surprising" rather than "logically incorrect"

Thanks Jakub, it seems these changes have now been superseded by 
Koichiro's patch series.

> 
>> Move netdev_priv() after validating ndev.
>>
>> No functional change intended.
> -- pw-bot: cr


https://lore.kernel.org/all/u6k7xyjkqdn5xsgderrxi5yw6mhwtl3srfeefagp44jco7jc44@c7f4tzlaem2l/


Thanks,
Alok

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

end of thread, other threads:[~2026-02-26 14:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24 13:04 [PATCH net-next] net: ntb_netdev: Fix NULL check ordering in TX handler Alok Tiwari
2026-02-24 14:42 ` Dave Jiang
2026-02-26  3:22 ` Jakub Kicinski
2026-02-26 14:14   ` ALOK TIWARI

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox