diff mbox series

[net-next,8/8] net: mscc: ocelot: fix ineffective WARN_ON() in ocelot_stats.c

Message ID 20230412124737.2243527-9-vladimir.oltean@nxp.com (mailing list archive)
State Accepted
Commit a291399e635415295860765954e247e83445e291
Delegated to: Netdev Maintainers
Headers show
Series Ocelot/Felix driver cleanup | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch warning WARNING: line length of 109 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Vladimir Oltean April 12, 2023, 12:47 p.m. UTC
Since it is hopefully now clear that, since "last" and "layout[i].reg"
are enum types and not addresses, the existing WARN_ON() is ineffective
in checking that the _addresses_ are sorted in the proper order.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_stats.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Keller, Jacob E April 12, 2023, 9:23 p.m. UTC | #1
On 4/12/2023 5:47 AM, Vladimir Oltean wrote:
> Since it is hopefully now clear that, since "last" and "layout[i].reg"
> are enum types and not addresses, the existing WARN_ON() is ineffective
> in checking that the _addresses_ are sorted in the proper order.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---

This is definitely more clear after reviewing the other code dealing
with these encoded register addresses.

Nice fix.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

Thanks,
Jake

>  drivers/net/ethernet/mscc/ocelot_stats.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mscc/ocelot_stats.c b/drivers/net/ethernet/mscc/ocelot_stats.c
> index e82c9d9d0ad3..5c55197c7327 100644
> --- a/drivers/net/ethernet/mscc/ocelot_stats.c
> +++ b/drivers/net/ethernet/mscc/ocelot_stats.c
> @@ -901,6 +901,17 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
>  		if (!layout[i].reg)
>  			continue;
>  
> +		/* enum ocelot_stat must be kept sorted in the same order
> +		 * as the addresses behind layout[i].reg in order to have
> +		 * efficient bulking
> +		 */
> +		if (last) {
> +			WARN(ocelot->map[SYS][last & REG_MASK] >= ocelot->map[SYS][layout[i].reg & REG_MASK],
> +			     "reg 0x%x had address 0x%x but reg 0x%x has address 0x%x, bulking broken!",
> +			     last, ocelot->map[SYS][last & REG_MASK],
> +			     layout[i].reg, ocelot->map[SYS][layout[i].reg & REG_MASK]);
> +		}
> +
>  		if (region && ocelot->map[SYS][layout[i].reg & REG_MASK] ==
>  		    ocelot->map[SYS][last & REG_MASK] + 4) {
>  			region->count++;
> @@ -910,12 +921,6 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
>  			if (!region)
>  				return -ENOMEM;
>  
> -			/* enum ocelot_stat must be kept sorted in the same
> -			 * order as layout[i].reg in order to have efficient
> -			 * bulking
> -			 */
> -			WARN_ON(last >= layout[i].reg);
> -
>  			region->base = layout[i].reg;
>  			region->first_stat = i;
>  			region->count = 1;
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mscc/ocelot_stats.c b/drivers/net/ethernet/mscc/ocelot_stats.c
index e82c9d9d0ad3..5c55197c7327 100644
--- a/drivers/net/ethernet/mscc/ocelot_stats.c
+++ b/drivers/net/ethernet/mscc/ocelot_stats.c
@@ -901,6 +901,17 @@  static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
 		if (!layout[i].reg)
 			continue;
 
+		/* enum ocelot_stat must be kept sorted in the same order
+		 * as the addresses behind layout[i].reg in order to have
+		 * efficient bulking
+		 */
+		if (last) {
+			WARN(ocelot->map[SYS][last & REG_MASK] >= ocelot->map[SYS][layout[i].reg & REG_MASK],
+			     "reg 0x%x had address 0x%x but reg 0x%x has address 0x%x, bulking broken!",
+			     last, ocelot->map[SYS][last & REG_MASK],
+			     layout[i].reg, ocelot->map[SYS][layout[i].reg & REG_MASK]);
+		}
+
 		if (region && ocelot->map[SYS][layout[i].reg & REG_MASK] ==
 		    ocelot->map[SYS][last & REG_MASK] + 4) {
 			region->count++;
@@ -910,12 +921,6 @@  static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
 			if (!region)
 				return -ENOMEM;
 
-			/* enum ocelot_stat must be kept sorted in the same
-			 * order as layout[i].reg in order to have efficient
-			 * bulking
-			 */
-			WARN_ON(last >= layout[i].reg);
-
 			region->base = layout[i].reg;
 			region->first_stat = i;
 			region->count = 1;