Skip to contentSkip to conversation

ice: Don't dereference NULL in ice_gns_read error path

PATCH In review Simon Horman 3 participants 3 messages May 25, 2023 – Jun 6, 2023

Subsystems (3)
lore
Share & tools
lore

Simon Horman

author reviewer
#0 lore raw

PATCH 1/1 ice: Don't dereference NULL in ice_gns_read error path

If pf is NULL in ice_gns_read() then it will be dereferenced in the error path by a call to dev_dbg(ice_pf_to_dev(pf), ...).

Avoid this by simply returning in this case. If logging is desired an alternate approach might be to use pr_err() before returning.

Flagged by Smatch as:

.../ice_gnss.c:196 ice_gnss_read() error: we previously assumed 'pf' could be null (see line 131)

Fixes 43113ff73453 ("ice: add TTY for GNSS module for E810T device")
---
 drivers/net/ethernet/intel/ice/ice_gnss.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_gnss.c +1 -7
index 2ea8a2b11bcd..3d0663840aa1 100644
@@ -128,12 +128,7 @@ static void ice_gnss_read(struct kthread_work *work)
 	int err = 0;
 
 	pf = gnss->back;
-	if (!pf) {
-		err = -EFAULT;
-		goto exit;
-	}
-
-	if (!test_bit(ICE_FLAG_GNSS, pf->flags))
+	if (!pf || !test_bit(ICE_FLAG_GNSS, pf->flags))
 		return;
 
 	hw = &pf->hw;
@@ -191,7 +186,6 @@ static void ice_gnss_read(struct kthread_work *work)
 	free_page((unsigned long)buf);
 requeue:
 	kthread_queue_delayed_work(gnss->kworker, &gnss->read_work, delay);
-exit:
 	if (err)
 		dev_dbg(ice_pf_to_dev(pf), "GNSS failed to read err=%d\n", err);
 }
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Simon Horman

If pf is NULL in ice_gns_read() then it will be dereferenced in the error path by a call to dev_dbg(ice_pf_to_dev(pf), ...).

Avoid this by simply returning in this case. If logging is desired an alternate approach might be to use pr_err() before returning.

Quoted 7 lines

Flagged by Smatch as:

.../ice_gnss.c:196 ice_gnss_read() error: we previously assumed 'pf' could be null (see line 131)

Fixes 43113ff73453 ("ice: add TTY for GNSS module for E810T device")

---

LGTM.

#2 lore raw
Quoted 9 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Tariq Toukan
Sent: Friday, May 26, 2023 2:48 AM
To: Simon Horman <[email protected]>; Brandeburg, Jesse <[email protected]>; Nguyen, Anthony L <[email protected]>
Cc: Mishra, Sudhansu Sekhar <[email protected]>; Kolacinski, Karol <[email protected]>; [email protected]; Eric Dumazet <[email protected]>; [email protected]; [email protected]; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; David S. Miller <[email protected]>; Dan Carpenter <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net] ice: Don't dereference NULL in ice_gns_read error path

Quoted 16 lines
Quoted 15 lines · Simon Horman

If pf is NULL in ice_gns_read() then it will be dereferenced in the
error path by a call to dev_dbg(ice_pf_to_dev(pf), ...).

Avoid this by simply returning in this case.
If logging is desired an alternate approach might be to use pr_err() before returning.

Flagged by Smatch as:

.../ice_gnss.c:196 ice_gnss_read() error: we previously assumed
'pf' could be null (see line 131)

Fixes 43113ff73453 ("ice: add TTY for GNSS module for E810T device")

---