mirror of https://gitee.com/openkylin/linux.git
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:
parent
442e55661d
commit
d59075ad1e
|
@ -13065,7 +13065,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
|
||||||
me->type = IRQ_SDMA;
|
me->type = IRQ_SDMA;
|
||||||
} else if (first_rx <= i && i < last_rx) {
|
} else if (first_rx <= i && i < last_rx) {
|
||||||
idx = i - first_rx;
|
idx = i - first_rx;
|
||||||
rcd = hfi1_rcd_get_by_index(dd, idx);
|
rcd = hfi1_rcd_get_by_index_safe(dd, idx);
|
||||||
if (rcd) {
|
if (rcd) {
|
||||||
/*
|
/*
|
||||||
* Set the interrupt register and mask for this
|
* Set the interrupt register and mask for this
|
||||||
|
|
|
@ -243,7 +243,7 @@ static int _ctx_stats_seq_show(struct seq_file *s, void *v)
|
||||||
spos = v;
|
spos = v;
|
||||||
i = *spos;
|
i = *spos;
|
||||||
|
|
||||||
rcd = hfi1_rcd_get_by_index(dd, i);
|
rcd = hfi1_rcd_get_by_index_safe(dd, i);
|
||||||
if (!rcd)
|
if (!rcd)
|
||||||
return SEQ_SKIP;
|
return SEQ_SKIP;
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ static int _rcds_seq_show(struct seq_file *s, void *v)
|
||||||
loff_t *spos = v;
|
loff_t *spos = v;
|
||||||
loff_t i = *spos;
|
loff_t i = *spos;
|
||||||
|
|
||||||
rcd = hfi1_rcd_get_by_index(dd, i);
|
rcd = hfi1_rcd_get_by_index_safe(dd, i);
|
||||||
if (rcd)
|
if (rcd)
|
||||||
seqfile_dump_rcd(s, rcd);
|
seqfile_dump_rcd(s, rcd);
|
||||||
hfi1_rcd_put(rcd);
|
hfi1_rcd_put(rcd);
|
||||||
|
|
|
@ -866,7 +866,7 @@ static inline void set_nodma_rtail(struct hfi1_devdata *dd, u16 ctxt)
|
||||||
* interrupt handler for all statically allocated kernel contexts.
|
* interrupt handler for all statically allocated kernel contexts.
|
||||||
*/
|
*/
|
||||||
if (ctxt >= dd->first_dyn_alloc_ctxt) {
|
if (ctxt >= dd->first_dyn_alloc_ctxt) {
|
||||||
rcd = hfi1_rcd_get_by_index(dd, ctxt);
|
rcd = hfi1_rcd_get_by_index_safe(dd, ctxt);
|
||||||
if (rcd) {
|
if (rcd) {
|
||||||
rcd->do_interrupt =
|
rcd->do_interrupt =
|
||||||
&handle_receive_interrupt_nodma_rtail;
|
&handle_receive_interrupt_nodma_rtail;
|
||||||
|
@ -895,7 +895,7 @@ static inline void set_dma_rtail(struct hfi1_devdata *dd, u16 ctxt)
|
||||||
* interrupt handler for all statically allocated kernel contexts.
|
* interrupt handler for all statically allocated kernel contexts.
|
||||||
*/
|
*/
|
||||||
if (ctxt >= dd->first_dyn_alloc_ctxt) {
|
if (ctxt >= dd->first_dyn_alloc_ctxt) {
|
||||||
rcd = hfi1_rcd_get_by_index(dd, ctxt);
|
rcd = hfi1_rcd_get_by_index_safe(dd, ctxt);
|
||||||
if (rcd) {
|
if (rcd) {
|
||||||
rcd->do_interrupt =
|
rcd->do_interrupt =
|
||||||
&handle_receive_interrupt_dma_rtail;
|
&handle_receive_interrupt_dma_rtail;
|
||||||
|
|
|
@ -1398,6 +1398,8 @@ void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
|
||||||
void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
|
void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
|
||||||
int hfi1_rcd_put(struct hfi1_ctxtdata *rcd);
|
int hfi1_rcd_put(struct hfi1_ctxtdata *rcd);
|
||||||
void hfi1_rcd_get(struct hfi1_ctxtdata *rcd);
|
void hfi1_rcd_get(struct hfi1_ctxtdata *rcd);
|
||||||
|
struct hfi1_ctxtdata *hfi1_rcd_get_by_index_safe(struct hfi1_devdata *dd,
|
||||||
|
u16 ctxt);
|
||||||
struct hfi1_ctxtdata *hfi1_rcd_get_by_index(struct hfi1_devdata *dd, u16 ctxt);
|
struct hfi1_ctxtdata *hfi1_rcd_get_by_index(struct hfi1_devdata *dd, u16 ctxt);
|
||||||
int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread);
|
int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread);
|
||||||
int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread);
|
int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread);
|
||||||
|
|
|
@ -283,6 +283,27 @@ static int allocate_rcd_index(struct hfi1_devdata *dd,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hfi1_rcd_get_by_index_safe - validate the ctxt index before accessing the
|
||||||
|
* array
|
||||||
|
* @dd: pointer to a valid devdata structure
|
||||||
|
* @ctxt: the index of an possilbe rcd
|
||||||
|
*
|
||||||
|
* This is a wrapper for hfi1_rcd_get_by_index() to validate that the given
|
||||||
|
* ctxt index is valid.
|
||||||
|
*
|
||||||
|
* The caller is responsible for making the _put().
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct hfi1_ctxtdata *hfi1_rcd_get_by_index_safe(struct hfi1_devdata *dd,
|
||||||
|
u16 ctxt)
|
||||||
|
{
|
||||||
|
if (ctxt < dd->num_rcv_contexts)
|
||||||
|
return hfi1_rcd_get_by_index(dd, ctxt);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hfi1_rcd_get_by_index
|
* hfi1_rcd_get_by_index
|
||||||
* @dd: pointer to a valid devdata structure
|
* @dd: pointer to a valid devdata structure
|
||||||
|
|
Loading…
Reference in New Issue