Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 4c4dbb4a7363 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
Fixes: cb3c7fd4f839 ("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>

authored by

Roy Novich and committed by
Paolo Abeni
162bd18e 27c1eaa0

+9 -5
+2 -1
include/linux/dim.h
··· 236 236 * 237 237 * Calculate the delta between two samples (in data rates). 238 238 * Takes into consideration counter wrap-around. 239 + * Returned boolean indicates whether curr_stats are reliable. 239 240 */ 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, 241 242 struct dim_stats *curr_stats); 242 243 243 244 /**
+3 -2
lib/dim/dim.c
··· 54 54 } 55 55 EXPORT_SYMBOL(dim_park_tired); 56 56 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, 58 58 struct dim_stats *curr_stats) 59 59 { 60 60 /* u32 holds up to 71 minutes, should be enough */ ··· 66 66 start->comp_ctr); 67 67 68 68 if (!delta_us) 69 - return; 69 + return false; 70 70 71 71 curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us); 72 72 curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us); ··· 79 79 else 80 80 curr_stats->cpe_ratio = 0; 81 81 82 + return true; 82 83 } 83 84 EXPORT_SYMBOL(dim_calc_stats);
+2 -1
lib/dim/net_dim.c
··· 227 227 dim->start_sample.event_ctr); 228 228 if (nevents < DIM_NEVENTS) 229 229 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; 231 232 if (net_dim_decision(&curr_stats, dim)) { 232 233 dim->state = DIM_APPLY_NEW_PROFILE; 233 234 schedule_work(&dim->work);
+2 -1
lib/dim/rdma_dim.c
··· 88 88 nevents = curr_sample->event_ctr - dim->start_sample.event_ctr; 89 89 if (nevents < DIM_NEVENTS) 90 90 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; 92 93 if (rdma_dim_decision(&curr_stats, dim)) { 93 94 dim->state = DIM_APPLY_NEW_PROFILE; 94 95 schedule_work(&dim->work);