]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
soundwire: intel: fix potential race condition during power down
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Wed, 18 Aug 2021 02:49:52 +0000 (10:49 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 5 Nov 2021 09:18:43 +0000 (10:18 +0100)
BugLink: https://bugs.launchpad.net/bugs/1947781
[ Upstream commit ea6942dad4b2a7e1735aa0f10f3d0b04b847750f ]

The power down sequence sets the link_up flag as false outside of the
mutex_lock. This is potentially unsafe.

In additional the flow in that sequence can be improved by first
testing if the link was powered, setting the link_up flag as false and
proceeding with the power down. In case the CPA bits cannot be
cleared, we only flag an error since we cannot deal with interrupts
any longer.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20210818024954.16873-2-yung-chuan.liao@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/soundwire/intel.c

index 66adb258a425825476d8232c9424fa44cae832d0..5118c2fe832f67c64fb93e31efb86cb18899ae48 100644 (file)
@@ -537,12 +537,14 @@ static int intel_link_power_down(struct sdw_intel *sdw)
 
        mutex_lock(sdw->link_res->shim_lock);
 
-       intel_shim_master_ip_to_glue(sdw);
-
        if (!(*shim_mask & BIT(link_id)))
                dev_err(sdw->cdns.dev,
                        "%s: Unbalanced power-up/down calls\n", __func__);
 
+       sdw->cdns.link_up = false;
+
+       intel_shim_master_ip_to_glue(sdw);
+
        *shim_mask &= ~BIT(link_id);
 
        if (!*shim_mask) {
@@ -559,20 +561,21 @@ static int intel_link_power_down(struct sdw_intel *sdw)
                link_control &=  spa_mask;
 
                ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask);
+               if (ret < 0) {
+                       dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__);
+
+                       /*
+                        * we leave the sdw->cdns.link_up flag as false since we've disabled
+                        * the link at this point and cannot handle interrupts any longer.
+                        */
+               }
        }
 
        link_control = intel_readl(shim, SDW_SHIM_LCTL);
 
        mutex_unlock(sdw->link_res->shim_lock);
 
-       if (ret < 0) {
-               dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__);
-
-               return ret;
-       }
-
-       sdw->cdns.link_up = false;
-       return 0;
+       return ret;
 }
 
 static void intel_shim_sync_arm(struct sdw_intel *sdw)