IB/hfi1: Add a safe wrapper for _rcd_get_by_index
hfi1_rcd_get_by_index assumes that the given index is in the correct range. In most cases this is correct because the index is bounded by a loop. For these cases, adding a range check to the function is redundant. For the use case that is not bounded by the loop range, a _safe wrapper function is needed to validate the index before accessing the rcd array. Add a _safe wrapper to _get_by_index to validate the index range. Update appropriate call sites with the new _safe function. Reviewed-by: Ira Weiny <ira.weiny@intel.com> Signed-off-by: Michael J. Ruhl <michael.j.ruhl@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:

committed by
Doug Ledford

parent
442e55661d
commit
d59075ad1e
@@ -243,7 +243,7 @@ static int _ctx_stats_seq_show(struct seq_file *s, void *v)
|
||||
spos = v;
|
||||
i = *spos;
|
||||
|
||||
rcd = hfi1_rcd_get_by_index(dd, i);
|
||||
rcd = hfi1_rcd_get_by_index_safe(dd, i);
|
||||
if (!rcd)
|
||||
return SEQ_SKIP;
|
||||
|
||||
@@ -402,7 +402,7 @@ static int _rcds_seq_show(struct seq_file *s, void *v)
|
||||
loff_t *spos = v;
|
||||
loff_t i = *spos;
|
||||
|
||||
rcd = hfi1_rcd_get_by_index(dd, i);
|
||||
rcd = hfi1_rcd_get_by_index_safe(dd, i);
|
||||
if (rcd)
|
||||
seqfile_dump_rcd(s, rcd);
|
||||
hfi1_rcd_put(rcd);
|
||||
|
Reference in New Issue
Block a user