Skip to content

Commit 2b0634c

Browse files
committed
Merge tag 'mhi-fixes-for-v6.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/mani/mhi into char-misc-next
Manivannan writes: MHI Endpoint ============ - Increment the rd_offset after writing the buffer to avoid MHI host accessing the incomplete/wrong buffer element. * tag 'mhi-fixes-for-v6.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/mani/mhi: bus: mhi: ep: Update read pointer only after buffer is written
2 parents 4a6e232 + 6f18d17 commit 2b0634c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/bus/mhi/ep/ring.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,23 @@ int mhi_ep_ring_add_element(struct mhi_ep_ring *ring, struct mhi_ring_element *e
131131
}
132132

133133
old_offset = ring->rd_offset;
134-
mhi_ep_ring_inc_index(ring);
135134

136135
dev_dbg(dev, "Adding an element to ring at offset (%zu)\n", ring->rd_offset);
136+
buf_info.host_addr = ring->rbase + (old_offset * sizeof(*el));
137+
buf_info.dev_addr = el;
138+
buf_info.size = sizeof(*el);
139+
140+
ret = mhi_cntrl->write_sync(mhi_cntrl, &buf_info);
141+
if (ret)
142+
return ret;
143+
144+
mhi_ep_ring_inc_index(ring);
137145

138146
/* Update rp in ring context */
139147
rp = cpu_to_le64(ring->rd_offset * sizeof(*el) + ring->rbase);
140148
memcpy_toio((void __iomem *) &ring->ring_ctx->generic.rp, &rp, sizeof(u64));
141149

142-
buf_info.host_addr = ring->rbase + (old_offset * sizeof(*el));
143-
buf_info.dev_addr = el;
144-
buf_info.size = sizeof(*el);
145-
146-
return mhi_cntrl->write_sync(mhi_cntrl, &buf_info);
150+
return ret;
147151
}
148152

149153
void mhi_ep_ring_init(struct mhi_ep_ring *ring, enum mhi_ep_ring_type type, u32 id)

0 commit comments

Comments
 (0)