]> git.baikalelectronics.ru Git - kernel.git/commitdiff
bus: mhi: core: Handle write lock properly in mhi_pm_m0_transition
authorHemant Kumar <hemantk@codeaurora.org>
Thu, 21 May 2020 17:02:48 +0000 (22:32 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 May 2020 07:35:44 +0000 (09:35 +0200)
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>
drivers/bus/mhi/core/pm.c

index 345f197130b8a9c674e236e49de16908739361bd..de5abb26bcae16ae25f178ff8152b7b67b6b205e 100644 (file)
@@ -288,14 +288,18 @@ int mhi_pm_m0_transition(struct mhi_controller *mhi_cntrl)
        for (i = 0; i < mhi_cntrl->max_chan; i++, mhi_chan++) {
                struct mhi_ring *tre_ring = &mhi_chan->tre_ring;
 
-               write_lock_irq(&mhi_chan->lock);
-               if (mhi_chan->db_cfg.reset_req)
+               if (mhi_chan->db_cfg.reset_req) {
+                       write_lock_irq(&mhi_chan->lock);
                        mhi_chan->db_cfg.db_mode = true;
+                       write_unlock_irq(&mhi_chan->lock);
+               }
+
+               read_lock_irq(&mhi_chan->lock);
 
                /* Only ring DB if ring is not empty */
                if (tre_ring->base && tre_ring->wp  != tre_ring->rp)
                        mhi_ring_chan_db(mhi_cntrl, mhi_chan);
-               write_unlock_irq(&mhi_chan->lock);
+               read_unlock_irq(&mhi_chan->lock);
        }
 
        mhi_cntrl->wake_put(mhi_cntrl, false);