Skip to content

Commit 162bd18

Browse files
royno-nvidiaPaolo Abeni
authored andcommitted
linux/dim: Do nothing if no time delta between samples
Add return value for dim_calc_stats. This is an indication for the caller if curr_stats was assigned by the function. Avoid using curr_stats uninitialized over {rdma/net}_dim, when no time delta between samples. Coverity reported this potential use of an uninitialized variable. Fixes: 4c4dbb4 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux") Fixes: cb3c7fd ("net/mlx5e: Support adaptive RX coalescing") Signed-off-by: Roy Novich <royno@nvidia.com> Reviewed-by: Aya Levin <ayal@nvidia.com> Reviewed-by: Saeed Mahameed <saeedm@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Reviewed-by: Leon Romanovsky <leonro@nvidia.com> Reviewed-by: Michal Kubiak <michal.kubiak@intel.com> Link: https://lore.kernel.org/r/20230507135743.138993-1-tariqt@nvidia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 27c1eaa commit 162bd18

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

include/linux/dim.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ void dim_park_tired(struct dim *dim);
236236
*
237237
* Calculate the delta between two samples (in data rates).
238238
* Takes into consideration counter wrap-around.
239+
* Returned boolean indicates whether curr_stats are reliable.
239240
*/
240-
void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
241+
bool dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
241242
struct dim_stats *curr_stats);
242243

243244
/**

lib/dim/dim.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void dim_park_tired(struct dim *dim)
5454
}
5555
EXPORT_SYMBOL(dim_park_tired);
5656

57-
void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
57+
bool dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
5858
struct dim_stats *curr_stats)
5959
{
6060
/* u32 holds up to 71 minutes, should be enough */
@@ -66,7 +66,7 @@ void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
6666
start->comp_ctr);
6767

6868
if (!delta_us)
69-
return;
69+
return false;
7070

7171
curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
7272
curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
@@ -79,5 +79,6 @@ void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
7979
else
8080
curr_stats->cpe_ratio = 0;
8181

82+
return true;
8283
}
8384
EXPORT_SYMBOL(dim_calc_stats);

lib/dim/net_dim.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ void net_dim(struct dim *dim, struct dim_sample end_sample)
227227
dim->start_sample.event_ctr);
228228
if (nevents < DIM_NEVENTS)
229229
break;
230-
dim_calc_stats(&dim->start_sample, &end_sample, &curr_stats);
230+
if (!dim_calc_stats(&dim->start_sample, &end_sample, &curr_stats))
231+
break;
231232
if (net_dim_decision(&curr_stats, dim)) {
232233
dim->state = DIM_APPLY_NEW_PROFILE;
233234
schedule_work(&dim->work);

lib/dim/rdma_dim.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ void rdma_dim(struct dim *dim, u64 completions)
8888
nevents = curr_sample->event_ctr - dim->start_sample.event_ctr;
8989
if (nevents < DIM_NEVENTS)
9090
break;
91-
dim_calc_stats(&dim->start_sample, curr_sample, &curr_stats);
91+
if (!dim_calc_stats(&dim->start_sample, curr_sample, &curr_stats))
92+
break;
9293
if (rdma_dim_decision(&curr_stats, dim)) {
9394
dim->state = DIM_APPLY_NEW_PROFILE;
9495
schedule_work(&dim->work);

0 commit comments

Comments
 (0)