Merge "bus: mhi: misc: Add check for dev_rp if it is iommu range or not"

This commit is contained in:
qctecmdr 2023-08-14 00:34:52 -07:00 • committed by Gerrit - the friendly Code Review server
commit 3686b916e5
2 changed files with 19 additions and 1 deletions

View file

@ -809,6 +809,12 @@ static inline void mhi_trigger_resume(struct mhi_controller *mhi_cntrl)
pm_wakeup_hard_event(&mhi_cntrl->mhi_dev->dev);
}
static inline bool is_valid_ring_ptr(struct mhi_ring *ring, dma_addr_t addr)
{
return ((addr >= ring->iommu_base &&
addr < ring->iommu_base + ring->len) && (addr % 16 == 0));
}
/* queue transfer buffer */
int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
void *buf, void *cb, size_t buf_len, enum MHI_FLAGS flags);

View file

@ -1403,6 +1403,12 @@ int mhi_process_tsync_ev_ring(struct mhi_controller *mhi_cntrl,
int ret = 0;
spin_lock_bh(&mhi_event->lock);
if (!is_valid_ring_ptr(ev_ring, er_ctxt->rp)) {
MHI_ERR("Event ring rp points outside of the event ring or unalign rp %llx\n",
er_ctxt->rp);
spin_unlock_bh(&mhi_event->lock);
return 0;
}
dev_rp = mhi_to_virtual(ev_ring, er_ctxt->rp);
if (ev_ring->rp == dev_rp) {
spin_unlock_bh(&mhi_event->lock);
@ -1496,8 +1502,14 @@ int mhi_process_bw_scale_ev_ring(struct mhi_controller *mhi_cntrl,
int ret = 0;
spin_lock_bh(&mhi_event->lock);
dev_rp = mhi_to_virtual(ev_ring, er_ctxt->rp);
if (!is_valid_ring_ptr(ev_ring, er_ctxt->rp)) {
MHI_ERR("Event ring rp points outside of the event ring or unalign rp %llx\n",
er_ctxt->rp);
spin_unlock_bh(&mhi_event->lock);
return 0;
}
dev_rp = mhi_to_virtual(ev_ring, er_ctxt->rp);
if (ev_ring->rp == dev_rp) {
spin_unlock_bh(&mhi_event->lock);
goto exit_bw_scale_process;