From nobody Thu Oct 2 18:05:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 918AD1B4141; Sun, 14 Sep 2025 12:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757854608; cv=none; b=fkXMI0ZZHzzzKEpZ1PYx9fKl4HQiL7aXpF37AX84CZKyOEM4SiVyqai4iehVuiTeZ1nn9IPMc+Z11yXKPYaD8sHxDdE49/5nyd63CdbgDpqQCwUXV4FUqArDxx4ZDgeK7S0QHzWwKYd2LxGkx1SeZaEdJyYATrGE/tm9mAVYLfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757854608; c=relaxed/simple; bh=5qN1hUYg/yBslXEFHt0WeCqqqta8eTqmgCNW+CF8HKk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CdSZMyzkadiB7hDrgnvUWEBhabB7g/ehKAbwXMw8esn95v5IumaL+XVQ2IdoBYr90bJ383SiRpRbrHjSFTCWpvXaA2p+BaA0ePDAtFgfvPVQwXGAbTY0yH71k7q+zNrRv2WBmjufLZRNE1rzzG6Yj6Ja1hkg1wU4gtlsaILoE8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aE81kzam; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aE81kzam" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2BED9C4CEF7; Sun, 14 Sep 2025 12:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757854608; bh=5qN1hUYg/yBslXEFHt0WeCqqqta8eTqmgCNW+CF8HKk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aE81kzamKD2tlYSp9L3Eur2qhzhRfskxp8Ahe5hLEYWCSvfPxZEVXRqeF7SrWx40A RnabcaX+lcJRj887aGkveANQnTxdmho0q1sHRFpxYgYzUS8a2V4lIdh6ukOWPqYWlV BnkbC/l5KR3WShVdU1NulN39PJAFj4nC3Q0Q8MJ9n8RgLeU2hEZudN/MN5POBKx0VE fYYDvBJQVxrTwuj0mfO9Js760EjYwMiMm42aEUf59ArgFT5nUHmROzvV0bbE1RTvpC ta/sgKXaGkBUWPRCfoftidGzBiXLs4FyfrNLn6eyvJEo5bZVArF26kScxwvgE0zjp9 M62l7jAV7LiaQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CC85CAC582; Sun, 14 Sep 2025 12:56:48 +0000 (UTC) From: Sven Peter Date: Sun, 14 Sep 2025 12:56:06 +0000 Subject: [PATCH 01/11] usb: typec: tipd: Clear interrupts first Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250914-apple-usb3-tipd-v1-1-4e99c8649024@kernel.org> References: <20250914-apple-usb3-tipd-v1-0-4e99c8649024@kernel.org> In-Reply-To: <20250914-apple-usb3-tipd-v1-0-4e99c8649024@kernel.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Janne Grunau , Neal Gompa , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Sven Peter , stable@kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3434; i=sven@kernel.org; h=from:subject:message-id; bh=5qN1hUYg/yBslXEFHt0WeCqqqta8eTqmgCNW+CF8HKk=; b=owGbwMvMwCHmIlirolUq95LxtFoSQ8ax3eXmpxaJGW7hWvku6r/UlmL1WZzVa39n3rHYbfzm/ 3ydczOzOkpZGMQ4GGTFFFm277c3ffLwjeDSTZfew8xhZQIZwsDFKQATOSDKyHAtf1se//3Tsldn r9gafFjd2yItkudRSr397lsdIsVTwv4z/NPp7X316dnxSfaHhG4uzFl0/m7i9U+SGfoHNCqzLvR KP+EAAA== X-Developer-Key: i=sven@kernel.org; a=openpgp; fpr=A1E3E34A2B3C820DBC4955E5993B08092F131F93 X-Endpoint-Received: by B4 Relay for sven@kernel.org/default with auth_id=407 Right now the interrupt handler first reads all updated status registers and only then clears the interrupts. It's possible that a duplicate interrupt for a changed register or plug state comes in after the interrupts have been processed but before they have been cleared: * plug is inserted, TPS_REG_INT_PLUG_EVENT is set * TPS_REG_INT_EVENT1 is read * tps6598x_handle_plug_event() has run and registered the plug * plug is removed again, TPS_REG_INT_PLUG_EVENT is set (again) * TPS_REG_INT_CLEAR1 is written, TPS_REG_INT_PLUG_EVENT is cleared We then have no plug connected and no pending interrupt but the tipd core still thinks there is a plug. It's possible to trigger this with e.g. a slightly broken Type-C to USB A converter. Fix this by first clearing the interrupts and only then reading the updated registers. Fixes: 45188f27b3d0 ("usb: typec: tipd: Add support for Apple CD321X") Fixes: 0a4c005bd171 ("usb: typec: driver for TI TPS6598x USB Power Delivery= controllers") Cc: stable@kernel.org Reviewed-by: Heikki Krogerus Reviewed-by: Neal Gompa Signed-off-by: Sven Peter --- drivers/usb/typec/tipd/core.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index dcf141ada07812295a6f07e41d77f95f98116010..1c80296c3b273e24ceacb3feff4= 32c4f6e6835cc 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -545,24 +545,23 @@ static irqreturn_t cd321x_interrupt(int irq, void *da= ta) if (!event) goto err_unlock; =20 + tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); + if (!tps6598x_read_status(tps, &status)) - goto err_clear_ints; + goto err_unlock; =20 if (event & APPLE_CD_REG_INT_POWER_STATUS_UPDATE) if (!tps6598x_read_power_status(tps)) - goto err_clear_ints; + goto err_unlock; =20 if (event & APPLE_CD_REG_INT_DATA_STATUS_UPDATE) if (!tps6598x_read_data_status(tps)) - goto err_clear_ints; + goto err_unlock; =20 /* Handle plug insert or removal */ if (event & APPLE_CD_REG_INT_PLUG_EVENT) tps6598x_handle_plug_event(tps, status); =20 -err_clear_ints: - tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); - err_unlock: mutex_unlock(&tps->lock); =20 @@ -668,25 +667,24 @@ static irqreturn_t tps6598x_interrupt(int irq, void *= data) if (!(event1[0] | event1[1] | event2[0] | event2[1])) goto err_unlock; =20 + tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); + tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); + if (!tps6598x_read_status(tps, &status)) - goto err_clear_ints; + goto err_unlock; =20 if ((event1[0] | event2[0]) & TPS_REG_INT_POWER_STATUS_UPDATE) if (!tps6598x_read_power_status(tps)) - goto err_clear_ints; + goto err_unlock; =20 if ((event1[0] | event2[0]) & TPS_REG_INT_DATA_STATUS_UPDATE) if (!tps6598x_read_data_status(tps)) - goto err_clear_ints; + goto err_unlock; =20 /* Handle plug insert or removal */ if ((event1[0] | event2[0]) & TPS_REG_INT_PLUG_EVENT) tps6598x_handle_plug_event(tps, status); =20 -err_clear_ints: - tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); - tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); - err_unlock: mutex_unlock(&tps->lock); =20 --=20 2.34.1