ice: simplify PF nominal-state checking
Subsystems (3)
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
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
@@ -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
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: simplifyice_pf_state_is_nominal()The function creates a temporary mask on stack just to check that first
ICE_STATE_NOMINAL_CHECK_BITSis empty. Simplify it by using theice_pf_state_is_nominal().Signed-off-by Yury Norov <[email protected]>--- 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@@ -1705,16 +1705,10 @@ static void ice_vsi_set_rss_flow_fld(structice_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
Re: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()
In reply to Yury NorovQuoted 3 lines · Yury Norov
The function creates a temporary mask on stack just to check that first
ICE_STATE_NOMINAL_CHECK_BITSis empty. Simplify it by using theice_pf_state_is_nominal().
maybe s/the ice_pf_state_is_nominal/bitmap_empty/
Quoted 2 lines
Signed-off-by Yury Norov <[email protected]>
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@@ -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
RE: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()
In reply to Yury NorovQuoted 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: simplifyice_pf_state_is_nominal()The function creates a temporary mask on stack just to check that first
ICE_STATE_NOMINAL_CHECK_BITSis empty. Simplify it by using theice_pf_state_is_nominal().Signed-off-by Yury Norov <[email protected]>--- 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@@ -1705,16 +1705,10 @@ static void ice_vsi_set_rss_flow_fld(structice_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
RE: [PATCH 1/2] ice: simplify ice_pf_state_is_nominal()
In reply to Yury NorovQuoted 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: simplifyice_pf_state_is_nominal()
Quoted 6 lines
The function creates a temporary mask on stack just to check that first
ICE_STATE_NOMINAL_CHECK_BITSis empty. Simplify it by using theice_pf_state_is_nominal().Signed-off-by Yury Norov <[email protected]>--- drivers/net/ethernet/intel/ice/ice_lib.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
PATCH 2/2 ice: drop pf == NULL check in ice_pf_state_is_nominal()
In reply to Yury NorovThe 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
@@ -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
@@ -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
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 inice_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.Signed-off-by Yury Norov <[email protected]>--- 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@@ -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@@ -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
Simon Horman
reviewerRe: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()
In reply to Yury NorovQuoted 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.Signed-off-by Yury Norov <[email protected]>--- 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@@ -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
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?
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.Signed-off-by Yury Norov <[email protected]>--- 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@@ -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@@ -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.
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.Signed-off-by Yury Norov <[email protected]>--- 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@@ -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@@ -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.
RE: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()
In reply to Yury NorovQuoted 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 inice_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.Signed-off-by Yury Norov <[email protected]>--- 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@@ -1705,9 +1705,6 @@ static void ice_vsi_set_rss_flow_fld(structice_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@@ -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
RE: [PATCH 2/2] ice: drop pf == NULL check in ice_pf_state_is_nominal()
In reply to Yury NorovQuoted 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 inice_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.Signed-off-by Yury Norov <[email protected]>--- 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(-)