diff mbox series

[1/2] platform/mellanox: mlxbf-pmc: mlxbf_pmc_event_list(): make size ptr optional

Message ID 182de8ec6b9c33152f2ba6b248c35b0311abf5e4.1708635408.git.luizcap@redhat.com (mailing list archive)
State Accepted, archived
Headers show
Series platform/mellanox: mlxbf-pmc: Fix module loading | expand

Commit Message

Luiz Capitulino Feb. 22, 2024, 8:57 p.m. UTC
The mlxbf_pmc_event_list() function returns a pointer to an array of
supported events and the array size. The array size is returned via
a pointer passed as an argument, which is mandatory.

However, we want to be able to use mlxbf_pmc_event_list() just to check
if a block name is implemented/supported. For this usage passing the size
argument is not necessary so let's make it optional.

Signed-off-by: Luiz Capitulino <luizcap@redhat.com>
---
 drivers/platform/mellanox/mlxbf-pmc.c | 40 +++++++++++++++------------
 1 file changed, 22 insertions(+), 18 deletions(-)

Comments

Hans de Goede Feb. 26, 2024, 10:49 a.m. UTC | #1
Hi,

On 2/22/24 21:57, Luiz Capitulino wrote:
> The mlxbf_pmc_event_list() function returns a pointer to an array of
> supported events and the array size. The array size is returned via
> a pointer passed as an argument, which is mandatory.
> 
> However, we want to be able to use mlxbf_pmc_event_list() just to check
> if a block name is implemented/supported. For this usage passing the size
> argument is not necessary so let's make it optional.
> 
> Signed-off-by: Luiz Capitulino <luizcap@redhat.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>  drivers/platform/mellanox/mlxbf-pmc.c | 40 +++++++++++++++------------
>  1 file changed, 22 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
> index 250405bb59a7..b71636eb3db1 100644
> --- a/drivers/platform/mellanox/mlxbf-pmc.c
> +++ b/drivers/platform/mellanox/mlxbf-pmc.c
> @@ -966,32 +966,33 @@ static bool mlxbf_pmc_valid_range(unsigned int blk_num, u32 offset)
>  }
>  
>  /* Get the event list corresponding to a certain block */
> -static const struct mlxbf_pmc_events *mlxbf_pmc_event_list(const char *blk, size_t *size)
> +static const struct mlxbf_pmc_events *mlxbf_pmc_event_list(const char *blk, size_t *psize)
>  {
>  	const struct mlxbf_pmc_events *events;
> +	size_t size;
>  
>  	if (strstr(blk, "tilenet")) {
>  		events = mlxbf_pmc_hnfnet_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_hnfnet_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_hnfnet_events);
>  	} else if (strstr(blk, "tile")) {
>  		events = mlxbf_pmc_hnf_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_hnf_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_hnf_events);
>  	} else if (strstr(blk, "triogen")) {
>  		events = mlxbf_pmc_smgen_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
>  	} else if (strstr(blk, "trio")) {
>  		switch (pmc->event_set) {
>  		case MLXBF_PMC_EVENT_SET_BF1:
>  			events = mlxbf_pmc_trio_events_1;
> -			*size = ARRAY_SIZE(mlxbf_pmc_trio_events_1);
> +			size = ARRAY_SIZE(mlxbf_pmc_trio_events_1);
>  			break;
>  		case MLXBF_PMC_EVENT_SET_BF2:
>  			events = mlxbf_pmc_trio_events_2;
> -			*size = ARRAY_SIZE(mlxbf_pmc_trio_events_2);
> +			size = ARRAY_SIZE(mlxbf_pmc_trio_events_2);
>  			break;
>  		default:
>  			events = NULL;
> -			*size = 0;
> +			size = 0;
>  			break;
>  		}
>  	} else if (strstr(blk, "mss")) {
> @@ -999,43 +1000,46 @@ static const struct mlxbf_pmc_events *mlxbf_pmc_event_list(const char *blk, size
>  		case MLXBF_PMC_EVENT_SET_BF1:
>  		case MLXBF_PMC_EVENT_SET_BF2:
>  			events = mlxbf_pmc_mss_events_1;
> -			*size = ARRAY_SIZE(mlxbf_pmc_mss_events_1);
> +			size = ARRAY_SIZE(mlxbf_pmc_mss_events_1);
>  			break;
>  		case MLXBF_PMC_EVENT_SET_BF3:
>  			events = mlxbf_pmc_mss_events_3;
> -			*size = ARRAY_SIZE(mlxbf_pmc_mss_events_3);
> +			size = ARRAY_SIZE(mlxbf_pmc_mss_events_3);
>  			break;
>  		default:
>  			events = NULL;
> -			*size = 0;
> +			size = 0;
>  			break;
>  		}
>  	} else if (strstr(blk, "ecc")) {
>  		events = mlxbf_pmc_ecc_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_ecc_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_ecc_events);
>  	} else if (strstr(blk, "pcie")) {
>  		events = mlxbf_pmc_pcie_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_pcie_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_pcie_events);
>  	} else if (strstr(blk, "l3cache")) {
>  		events = mlxbf_pmc_l3c_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_l3c_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_l3c_events);
>  	} else if (strstr(blk, "gic")) {
>  		events = mlxbf_pmc_smgen_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
>  	} else if (strstr(blk, "smmu")) {
>  		events = mlxbf_pmc_smgen_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
>  	} else if (strstr(blk, "llt_miss")) {
>  		events = mlxbf_pmc_llt_miss_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_llt_miss_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_llt_miss_events);
>  	} else if (strstr(blk, "llt")) {
>  		events = mlxbf_pmc_llt_events;
> -		*size = ARRAY_SIZE(mlxbf_pmc_llt_events);
> +		size = ARRAY_SIZE(mlxbf_pmc_llt_events);
>  	} else {
>  		events = NULL;
> -		*size = 0;
> +		size = 0;
>  	}
>  
> +	if (psize)
> +		*psize = size;
> +
>  	return events;
>  }
>
diff mbox series

Patch

diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
index 250405bb59a7..b71636eb3db1 100644
--- a/drivers/platform/mellanox/mlxbf-pmc.c
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -966,32 +966,33 @@  static bool mlxbf_pmc_valid_range(unsigned int blk_num, u32 offset)
 }
 
 /* Get the event list corresponding to a certain block */
-static const struct mlxbf_pmc_events *mlxbf_pmc_event_list(const char *blk, size_t *size)
+static const struct mlxbf_pmc_events *mlxbf_pmc_event_list(const char *blk, size_t *psize)
 {
 	const struct mlxbf_pmc_events *events;
+	size_t size;
 
 	if (strstr(blk, "tilenet")) {
 		events = mlxbf_pmc_hnfnet_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_hnfnet_events);
+		size = ARRAY_SIZE(mlxbf_pmc_hnfnet_events);
 	} else if (strstr(blk, "tile")) {
 		events = mlxbf_pmc_hnf_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_hnf_events);
+		size = ARRAY_SIZE(mlxbf_pmc_hnf_events);
 	} else if (strstr(blk, "triogen")) {
 		events = mlxbf_pmc_smgen_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
+		size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
 	} else if (strstr(blk, "trio")) {
 		switch (pmc->event_set) {
 		case MLXBF_PMC_EVENT_SET_BF1:
 			events = mlxbf_pmc_trio_events_1;
-			*size = ARRAY_SIZE(mlxbf_pmc_trio_events_1);
+			size = ARRAY_SIZE(mlxbf_pmc_trio_events_1);
 			break;
 		case MLXBF_PMC_EVENT_SET_BF2:
 			events = mlxbf_pmc_trio_events_2;
-			*size = ARRAY_SIZE(mlxbf_pmc_trio_events_2);
+			size = ARRAY_SIZE(mlxbf_pmc_trio_events_2);
 			break;
 		default:
 			events = NULL;
-			*size = 0;
+			size = 0;
 			break;
 		}
 	} else if (strstr(blk, "mss")) {
@@ -999,43 +1000,46 @@  static const struct mlxbf_pmc_events *mlxbf_pmc_event_list(const char *blk, size
 		case MLXBF_PMC_EVENT_SET_BF1:
 		case MLXBF_PMC_EVENT_SET_BF2:
 			events = mlxbf_pmc_mss_events_1;
-			*size = ARRAY_SIZE(mlxbf_pmc_mss_events_1);
+			size = ARRAY_SIZE(mlxbf_pmc_mss_events_1);
 			break;
 		case MLXBF_PMC_EVENT_SET_BF3:
 			events = mlxbf_pmc_mss_events_3;
-			*size = ARRAY_SIZE(mlxbf_pmc_mss_events_3);
+			size = ARRAY_SIZE(mlxbf_pmc_mss_events_3);
 			break;
 		default:
 			events = NULL;
-			*size = 0;
+			size = 0;
 			break;
 		}
 	} else if (strstr(blk, "ecc")) {
 		events = mlxbf_pmc_ecc_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_ecc_events);
+		size = ARRAY_SIZE(mlxbf_pmc_ecc_events);
 	} else if (strstr(blk, "pcie")) {
 		events = mlxbf_pmc_pcie_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_pcie_events);
+		size = ARRAY_SIZE(mlxbf_pmc_pcie_events);
 	} else if (strstr(blk, "l3cache")) {
 		events = mlxbf_pmc_l3c_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_l3c_events);
+		size = ARRAY_SIZE(mlxbf_pmc_l3c_events);
 	} else if (strstr(blk, "gic")) {
 		events = mlxbf_pmc_smgen_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
+		size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
 	} else if (strstr(blk, "smmu")) {
 		events = mlxbf_pmc_smgen_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
+		size = ARRAY_SIZE(mlxbf_pmc_smgen_events);
 	} else if (strstr(blk, "llt_miss")) {
 		events = mlxbf_pmc_llt_miss_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_llt_miss_events);
+		size = ARRAY_SIZE(mlxbf_pmc_llt_miss_events);
 	} else if (strstr(blk, "llt")) {
 		events = mlxbf_pmc_llt_events;
-		*size = ARRAY_SIZE(mlxbf_pmc_llt_events);
+		size = ARRAY_SIZE(mlxbf_pmc_llt_events);
 	} else {
 		events = NULL;
-		*size = 0;
+		size = 0;
 	}
 
+	if (psize)
+		*psize = size;
+
 	return events;
 }