File tree 3 files changed +26
-1
lines changed 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -968,15 +968,21 @@ static int fill_stat_counter_hwcounters(struct sk_buff *msg,
968
968
if (!table_attr )
969
969
return - EMSGSIZE ;
970
970
971
- for (i = 0 ; i < st -> num_counters ; i ++ )
971
+ mutex_lock (& st -> lock );
972
+ for (i = 0 ; i < st -> num_counters ; i ++ ) {
973
+ if (test_bit (i , st -> is_disabled ))
974
+ continue ;
972
975
if (rdma_nl_stat_hwcounter_entry (msg , st -> descs [i ].name ,
973
976
st -> value [i ]))
974
977
goto err ;
978
+ }
979
+ mutex_unlock (& st -> lock );
975
980
976
981
nla_nest_end (msg , table_attr );
977
982
return 0 ;
978
983
979
984
err :
985
+ mutex_unlock (& st -> lock );
980
986
nla_nest_cancel (msg , table_attr );
981
987
return - EMSGSIZE ;
982
988
}
@@ -2104,6 +2110,9 @@ static int stat_get_doit_default_counter(struct sk_buff *skb,
2104
2110
goto err_stats ;
2105
2111
}
2106
2112
for (i = 0 ; i < num_cnts ; i ++ ) {
2113
+ if (test_bit (i , stats -> is_disabled ))
2114
+ continue ;
2115
+
2107
2116
v = stats -> value [i ] +
2108
2117
rdma_counter_get_hwstat_value (device , port , i );
2109
2118
if (rdma_nl_stat_hwcounter_entry (msg ,
Original file line number Diff line number Diff line change @@ -2994,11 +2994,20 @@ struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
2994
2994
if (!stats )
2995
2995
return NULL ;
2996
2996
2997
+ stats -> is_disabled = kcalloc (BITS_TO_LONGS (num_counters ),
2998
+ sizeof (* stats -> is_disabled ), GFP_KERNEL );
2999
+ if (!stats -> is_disabled )
3000
+ goto err ;
3001
+
2997
3002
stats -> descs = descs ;
2998
3003
stats -> num_counters = num_counters ;
2999
3004
stats -> lifespan = msecs_to_jiffies (lifespan );
3000
3005
3001
3006
return stats ;
3007
+
3008
+ err :
3009
+ kfree (stats );
3010
+ return NULL ;
3002
3011
}
3003
3012
EXPORT_SYMBOL (rdma_alloc_hw_stats_struct );
3004
3013
@@ -3008,6 +3017,10 @@ EXPORT_SYMBOL(rdma_alloc_hw_stats_struct);
3008
3017
*/
3009
3018
void rdma_free_hw_stats_struct (struct rdma_hw_stats * stats )
3010
3019
{
3020
+ if (!stats )
3021
+ return ;
3022
+
3023
+ kfree (stats -> is_disabled );
3011
3024
kfree (stats );
3012
3025
}
3013
3026
EXPORT_SYMBOL (rdma_free_hw_stats_struct );
Original file line number Diff line number Diff line change @@ -565,6 +565,8 @@ struct rdma_stat_desc {
565
565
* their own value during their allocation routine.
566
566
* @descs - Array of pointers to static descriptors used for the counters
567
567
* in directory.
568
+ * @is_disabled - A bitmap to indicate each counter is currently disabled
569
+ * or not.
568
570
* @num_counters - How many hardware counters there are. If name is
569
571
* shorter than this number, a kernel oops will result. Driver authors
570
572
* are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
@@ -577,6 +579,7 @@ struct rdma_hw_stats {
577
579
unsigned long timestamp ;
578
580
unsigned long lifespan ;
579
581
const struct rdma_stat_desc * descs ;
582
+ unsigned long * is_disabled ;
580
583
int num_counters ;
581
584
u64 value [];
582
585
};
You can’t perform that action at this time.
0 commit comments