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

bus: mhi: core: Handle write lock properly in mhi_pm_m0_transition

Take write lock only to protect db_mode member of mhi channel.
This allows rest of the mhi channels to just take read lock which
fine grains the locking. It prevents channel readers to starve if
they try to enter critical section after a writer.

Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20200521170249.21795-14-manivannan.sadhasivam@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hemant Kumar and committed by
Greg Kroah-Hartman
3bc1a5f4 30b78924

+7 -3
+7 -3
drivers/bus/mhi/core/pm.c
··· 288 288 for (i = 0; i < mhi_cntrl->max_chan; i++, mhi_chan++) { 289 289 struct mhi_ring *tre_ring = &mhi_chan->tre_ring; 290 290 291 - write_lock_irq(&mhi_chan->lock); 292 - if (mhi_chan->db_cfg.reset_req) 291 + if (mhi_chan->db_cfg.reset_req) { 292 + write_lock_irq(&mhi_chan->lock); 293 293 mhi_chan->db_cfg.db_mode = true; 294 + write_unlock_irq(&mhi_chan->lock); 295 + } 296 + 297 + read_lock_irq(&mhi_chan->lock); 294 298 295 299 /* Only ring DB if ring is not empty */ 296 300 if (tre_ring->base && tre_ring->wp != tre_ring->rp) 297 301 mhi_ring_chan_db(mhi_cntrl, mhi_chan); 298 - write_unlock_irq(&mhi_chan->lock); 302 + read_unlock_irq(&mhi_chan->lock); 299 303 } 300 304 301 305 mhi_cntrl->wake_put(mhi_cntrl, false);