Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b14bb0af authored by Umang Agrawal's avatar Umang Agrawal
Browse files

power: smb-lib: Fix mutex acquisition deadlock on PD hard reset



Mutex acquisition deadlock can happen while cancelling cc_dettach
work during pd_hard_reset from the function usbin_plugin_hard_reset
_locked on vbus rise which is called in the same lock context that
we try to acquire in the cc_dettach work routine.
Check if cc_dettach work is running during pd_hard_reset and use
trylock instead of mutex_lock to prevent any deadlock if mutext is
already held.

Change-Id: I5530deb9e654d3d12ba1b4bc6876f36127a0d5a5
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent eddc683b
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -4772,6 +4772,7 @@ static void rdstd_cc2_detach_work(struct work_struct *work)
{
	int rc;
	u8 stat4, stat5;
	bool lock = false;
	struct smb_charger *chg = container_of(work, struct smb_charger,
						rdstd_cc2_detach_work);

@@ -4834,8 +4835,27 @@ static void rdstd_cc2_detach_work(struct work_struct *work)
	rc = smblib_masked_write(chg, TYPE_C_INTRPT_ENB_SOFTWARE_CTRL_REG,
						EXIT_SNK_BASED_ON_CC_BIT, 0);
	smblib_reg_block_restore(chg, cc2_detach_settings);

	/*
	 * Mutex acquisition deadlock can happen while cancelling this work
	 * during pd_hard_reset from the function smblib_cc2_sink_removal_exit
	 * which is called in the same lock context that we try to acquire in
	 * this work routine.
	 * Check if this work is running during pd_hard_reset and use trylock
	 * instead of mutex_lock to prevent any deadlock if mutext is already
	 * held.
	 */
	if (chg->pd_hard_reset) {
		if (mutex_trylock(&chg->lock))
			lock = true;
	} else {
		mutex_lock(&chg->lock);
		lock = true;
	}

	smblib_usb_typec_change(chg);

	if (lock)
		mutex_unlock(&chg->lock);
	return;