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

Commit 02ee091e authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

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

parents d47b8f65 b14bb0af
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -4757,6 +4757,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);

@@ -4819,8 +4820,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;