Skip to contentSkip to conversation

ice: simplify PF nominal-state checking

PATCH In review Yury Norov 5 participants 13 messages Sep 3 – Sep 30

Subsystems (3)
lore
Share & tools
lore

Yury Norov

author
#0 lore raw

cover ice: simplify PF nominal-state checking

Simplify ice_pf_state_is_nominal() by checking the relevant state bits directly with bitmap_empty(), instead of constructing a temporary bitmap on the stack.

Two of the three callers dereference the PF before calling the helper. Move the NULL check to the remaining caller so that ice_pf_state_is_nominal() becomes a one-liner.

Yury Norov (2):
ice: simplify ice_pf_state_is_nominal()
ice: drop pf == NULL check in ice_pf_state_is_nominal()

 drivers/net/ethernet/intel/ice/ice_lib.c  | 11 +----------
 drivers/net/ethernet/intel/ice/ice_main.c |  2 +-
 2 files changed, 2 insertions(+), 11 deletions(-)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/2 ice: simplify ice_pf_state_is_nominal()

The function creates a temporary mask on stack just to check that first ICE_STATE_NOMINAL_CHECK_BITS is empty. Simplify it by using the ice_pf_state_is_nominal().

---
 drivers/net/ethernet/intel/ice/ice_lib.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +1 -7
index 9e08db376d3d..73996e3022ef 100644
@@ -1705,16 +1705,10 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)
 {
-	DECLARE_BITMAP(check_bits, ICE_STATE_NBITS) = { 0 };
-
 	if (!pf)
 		return false;
 
-	bitmap_set(check_bits, 0, ICE_STATE_NOMINAL_CHECK_BITS);
-	if (bitmap_intersects(pf->state, check_bits, ICE_STATE_NBITS))
-		return false;
-
-	return true;
+	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
 #define ICE_FW_MODE_REC_M BIT(1)
Signature · 1 line
2.53.0
Reviewed-by on v1 1/2
#2 lore raw

RE: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()

Quoted 45 lines

-----Original Message-----
From: Yury Norov <[email protected]>
Sent: Thursday, September 3, 2026 3:21 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; open list <[email protected]>
Cc: Yury Norov <[email protected]>
Subject: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()

The function creates a temporary mask on stack just to check that first ICE_STATE_NOMINAL_CHECK_BITS is empty. Simplify it by using the ice_pf_state_is_nominal().

---
 drivers/net/ethernet/intel/ice/ice_lib.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +1 -8
index 9e08db376d3d..73996e3022ef 100644
@@ -1705,16 +1705,10 @@ static void ice_vsi_set_rss_flow_fld(struct
 ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)  {
-	DECLARE_BITMAP(check_bits, ICE_STATE_NBITS) = { 0 };
-
 	if (!pf)
 		return false;
 
-	bitmap_set(check_bits, 0, ICE_STATE_NOMINAL_CHECK_BITS);
-	if (bitmap_intersects(pf->state, check_bits, ICE_STATE_NBITS))
-		return false;
-
-	return true;
+	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
 #define ICE_FW_MODE_REC_M BIT(1)
--
Quoted 1 line

2.53.0

reviewer Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()

In reply to Yury Norov
Quoted 3 lines · Yury Norov

The function creates a temporary mask on stack just to check that first ICE_STATE_NOMINAL_CHECK_BITS is empty. Simplify it by using the ice_pf_state_is_nominal().

maybe s/the ice_pf_state_is_nominal/bitmap_empty/

Quoted 2 lines

The above nit not withstanding this looks good to me.

Quoted 29 lines
---
 drivers/net/ethernet/intel/ice/ice_lib.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +1 -7
index 9e08db376d3d..73996e3022ef 100644
@@ -1705,16 +1705,10 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)
 {
-	DECLARE_BITMAP(check_bits, ICE_STATE_NBITS) = { 0 };
-
 	if (!pf)
 		return false;
 
-	bitmap_set(check_bits, 0, ICE_STATE_NOMINAL_CHECK_BITS);
-	if (bitmap_intersects(pf->state, check_bits, ICE_STATE_NBITS))
-		return false;
-
-	return true;
+	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
 #define ICE_FW_MODE_REC_M BIT(1)
Signature · 1 line
2.53.0
Reviewed-by on v1 1/2
#4 lore raw

RE: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()

In reply to Yury Norov
Quoted 47 lines

-----Original Message-----
From: Yury Norov <[email protected]>
Sent: Thursday, September 3, 2026 3:21 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; open list <[email protected]>
Cc: Yury Norov <[email protected]>
Subject: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()

The function creates a temporary mask on stack just to check that first ICE_STATE_NOMINAL_CHECK_BITS is empty. Simplify it by using the ice_pf_state_is_nominal().

---
 drivers/net/ethernet/intel/ice/ice_lib.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +1 -8
index 9e08db376d3d..73996e3022ef 100644
@@ -1705,16 +1705,10 @@ static void ice_vsi_set_rss_flow_fld(struct
 ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)  {
-	DECLARE_BITMAP(check_bits, ICE_STATE_NBITS) = { 0 };
-
 	if (!pf)
 		return false;
 
-	bitmap_set(check_bits, 0, ICE_STATE_NOMINAL_CHECK_BITS);
-	if (bitmap_intersects(pf->state, check_bits, ICE_STATE_NBITS))
-		return false;
-
-	return true;
+	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
 #define ICE_FW_MODE_REC_M BIT(1)
--
Quoted 1 line

2.53.0

Tested-by on v1 1/2
#5 lore raw

RE: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()

In reply to Yury Norov
Quoted 7 lines

-----Original Message-----
From: Yury Norov <[email protected]>
Sent: Thursday, September 3, 2026 6:21 AM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; open list <[email protected]>
Cc: Yury Norov <[email protected]>
Subject: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()

Quoted 6 lines

The function creates a temporary mask on stack just to check that first ICE_STATE_NOMINAL_CHECK_BITS is empty. Simplify it by using the ice_pf_state_is_nominal().

---
 drivers/net/ethernet/intel/ice/ice_lib.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
author
#6 lore raw

PATCH 2/2 ice: drop pf == NULL check in ice_pf_state_is_nominal()

In reply to Yury Norov

The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makse the fun function a one-liner.

---
 drivers/net/ethernet/intel/ice/ice_lib.c  | 3 ---
 drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -3
index 73996e3022ef..6d5b8acc4764 100644
@@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)
 {
-	if (!pf)
-		return false;
-
 	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
index d88835482d3a..168d85f9477f 100644
@@ -5521,7 +5521,7 @@ static int ice_suspend(struct device *dev)
 
 	pf = pci_get_drvdata(pdev);
 
-	if (!ice_pf_state_is_nominal(pf)) {
+	if (!pf || !ice_pf_state_is_nominal(pf)) {
 		dev_err(dev, "Device is not ready, no need to suspend it\n");
 		return -EBUSY;
 	}
Signature · 1 line
2.53.0
Reviewed-by on v1 2/2
#7 lore raw

RE: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

Quoted 52 lines

-----Original Message-----
From: Yury Norov <[email protected]>
Sent: Thursday, September 3, 2026 3:21 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; open list <[email protected]>
Cc: Yury Norov <[email protected]>
Subject: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makse the fun function a one-liner.

---
 drivers/net/ethernet/intel/ice/ice_lib.c  | 3 ---
drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -3
index 73996e3022ef..6d5b8acc4764 100644
@@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi
 *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)  {
-	if (!pf)
-		return false;
-
 	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
drivers/net/ethernet/intel/ice/ice_main.c +1 -2
index d88835482d3a..168d85f9477f 100644
@@ -5521,7 +5521,7 @@ static int ice_suspend(struct device *dev)
 
 	pf = pci_get_drvdata(pdev);
 
-	if (!ice_pf_state_is_nominal(pf)) {
+	if (!pf || !ice_pf_state_is_nominal(pf)) {
 		dev_err(dev, "Device is not ready, no need to suspend it\n");
 		return -EBUSY;
 	}
--
Quoted 1 line

2.53.0

reviewer
#8 lore raw

Re: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

In reply to Yury Norov
Quoted 30 lines · Yury Norov

The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makse the fun function a one-liner.

---
 drivers/net/ethernet/intel/ice/ice_lib.c  | 3 ---
 drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -3
index 73996e3022ef..6d5b8acc4764 100644
@@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)
 {
-	if (!pf)
-		return false;
-
 	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
index d88835482d3a..168d85f9477f 100644

drivers/net/ethernet/intel/ice/ice_main.c static int ice_suspend(struct device *dev) · line 5527

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
@@ -5521,7 +5521,7 @@ static int ice_suspend(struct device *dev)
 
 	pf = pci_get_drvdata(pdev);
 
-	if (!ice_pf_state_is_nominal(pf)) {
+	if (!pf || !ice_pf_state_is_nominal(pf)) {
 		dev_err(dev, "Device is not ready, no need to suspend it\n");
 		return -EBUSY;
 	}

Is the new condition necessary in ice_suspend?

author
#9 lore raw

Re: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

Quoted 34 lines · Simon Horman
Quoted 33 lines · Yury Norov

The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makse the fun function a one-liner.

---
 drivers/net/ethernet/intel/ice/ice_lib.c  | 3 ---
 drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -3
index 73996e3022ef..6d5b8acc4764 100644
@@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)
 {
-	if (!pf)
-		return false;
-
 	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
index d88835482d3a..168d85f9477f 100644
@@ -5521,7 +5521,7 @@ static int ice_suspend(struct device *dev)
 
 	pf = pci_get_drvdata(pdev);
 
Quoted 7 lines

drivers/net/ethernet/intel/ice/ice_main.c static int ice_suspend(struct device *dev) · line 5527

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
-	if (!ice_pf_state_is_nominal(pf)) {
+	if (!pf || !ice_pf_state_is_nominal(pf)) {
 		dev_err(dev, "Device is not ready, no need to suspend it\n");
 		return -EBUSY;
 	}

Is the new condition necessary in ice_suspend?

IDK. I'm just trying to stay on the safe side. The ice_pf_state_is_nominal() was safe against pf == NULL, so I'm trying to preserve the invariant.

If it's impossible, I can do:

        if (WARN_ON(!pf) || !ice_pf_state_is_nominal(pf)) 

This would imply unlikely(), and more verbose than an implied assumption that pf is never uninitialized.

reviewer Reviewed-by
#10 lore raw

Re: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

Quoted 47 lines · Yury Norov
Quoted 34 lines · Simon Horman
Quoted 33 lines · Yury Norov

The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makse the fun function a one-liner.

---
 drivers/net/ethernet/intel/ice/ice_lib.c  | 3 ---
 drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -3
index 73996e3022ef..6d5b8acc4764 100644
@@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)
 {
-	if (!pf)
-		return false;
-
 	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
index d88835482d3a..168d85f9477f 100644
@@ -5521,7 +5521,7 @@ static int ice_suspend(struct device *dev)
 
 	pf = pci_get_drvdata(pdev);
 
Quoted 7 lines

drivers/net/ethernet/intel/ice/ice_main.c static int ice_suspend(struct device *dev) · line 5527

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
-	if (!ice_pf_state_is_nominal(pf)) {
+	if (!pf || !ice_pf_state_is_nominal(pf)) {
 		dev_err(dev, "Device is not ready, no need to suspend it\n");
 		return -EBUSY;
 	}

Is the new condition necessary in ice_suspend?

IDK. I'm just trying to stay on the safe side. The ice_pf_state_is_nominal() was safe against pf == NULL, so I'm trying to preserve the invariant.

Quoted 6 lines

If it's impossible, I can do:

        if (WARN_ON(!pf) || !ice_pf_state_is_nominal(pf)) 

This would imply unlikely(), and more verbose than an implied assumption that pf is never uninitialized.

Let's stick with what you've got.

Reviewed-by on v1 2/2
#11 lore raw

RE: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

In reply to Yury Norov
Quoted 55 lines

-----Original Message-----
From: Yury Norov <[email protected]>
Sent: Thursday, September 3, 2026 3:21 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; open list <[email protected]>
Cc: Yury Norov <[email protected]>
Subject: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makse the fun function a one-liner.

---
 drivers/net/ethernet/intel/ice/ice_lib.c  | 3 ---
drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +0 -3
index 73996e3022ef..6d5b8acc4764 100644
@@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(struct
 ice_vsi *vsi)
  */
 bool ice_pf_state_is_nominal(struct ice_pf *pf)  {
-	if (!pf)
-		return false;
-
 	return bitmap_empty(pf->state, ICE_STATE_NOMINAL_CHECK_BITS);
 }
 
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
index d88835482d3a..168d85f9477f 100644
@@ -5521,7 +5521,7 @@ static int ice_suspend(struct device *dev)
 
 	pf = pci_get_drvdata(pdev);
 
-	if (!ice_pf_state_is_nominal(pf)) {
+	if (!pf || !ice_pf_state_is_nominal(pf)) {
 		dev_err(dev, "Device is not ready, no need to suspend
 it\n");
 		return -EBUSY;
Quoted 3 lines

}
--
2.53.0

Tested-by on v1 2/2
#12 lore raw

RE: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

In reply to Yury Norov
Quoted 7 lines

-----Original Message-----
From: Yury Norov <[email protected]>
Sent: Thursday, September 3, 2026 6:21 AM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; open list <[email protected]>
Cc: Yury Norov <[email protected]>
Subject: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()

Quoted 6 lines

The function has 3 callers, all except one explicitly require pf != NULL. Add the corresponding check to the remaining caller, and remove it from the ice_pf_state_is_nominal(). It makse the fun function a one-liner.

---
 drivers/net/ethernet/intel/ice/ice_lib.c  | 3 ---  drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)