From patchwork Tue Dec 17 09:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13911436 Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazon11013053.outbound.protection.outlook.com [40.107.162.53]) (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 E0ECC1DE891 for ; Tue, 17 Dec 2024 09:11:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.162.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734426719; cv=fail; b=D2JUdaV7T+DWSbz2gKq+KWZtGKPz+jJhmbumm/bhtaeMaJtJl6mzCSwpV/XHkKy7gdjk1R6UgXRMjGbvySduM7cl2MXIJIcL8OQwekl0UZ0YaAqCQEux33LeHbeH8C+L5QkE9uIbF8l/O/kt2PtLQhLtkcW4GpH1nlColwQtbD0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734426719; c=relaxed/simple; bh=3zk3VitVabxl2UmoEjNUlEIX9XlHXaWHXVN3kjvGTtM=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=F/SFddJ/B9IdG9YmMnttIwr3rut7h2c/D/V/CD7RXiMFPEg+T7TMx5Qg6Orh6FuKL9WUEPG7ePmggTjXluu1njDMuV/quCMJBM42OsHjXxdl1oi4/VPdwm6OXlZtO5noInNxw74h0V8gTLcOJzPzyhbmEHS2LN2jKitDe8Jyaa0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=fay9ijVm; arc=fail smtp.client-ip=40.107.162.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="fay9ijVm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lKOBSnpI78k98725pvLLDAY1Sb3kcgXfoXC3/ACTvxZPIs9huT+zXhlS4kk0f6hlDJuVjjmn0hko4KU1vBhkyC0KK7TYo+2A6jBedeBCB8qbqnAc0Gj3pwecGG3kHyfaB3c/59NIZ2xyCWbqmlH5whfmS9RutTdOOD7xPPCXH3lbLJFVTXLBO2Q9sP3UIT/JczvQdxWh7d+d384m/kaRAnpuLxNOET6TO+ZuNZHaVNuBdEduvBwyQ9kESAbDKQUJMbaKJUPj4S62E0jh2pz4qeICA3U8UaKebcMpfzS1WV/mN+AxQPU9RwdeIAEhylKLlfnHEu2I3hOOO1c7oIFgsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CuHn30tckrHqiTGGNrq8d/cvCZXDx5NmVuUEq/TvyP4=; b=KvwqJkvb6VObvmniuZBIxdEnnHXuWGnoS3jookZUM7OcSpd4TAEVDDaaOXJOzm0bNuVe4NZSqne+e51Iel3yOjJo2KfLB0zOYjS4ZQ68iXxsCe7AqLa3j2yD6ipXPVtfN0coTeN5n5pDosG+uk2JQO6VN9hQNix7YVMMBCP1JjjSb0OTqSJPB1woIwZqj9PDEUbTwMXOKy7RoZsM3tP8r2MRg9VKGWiGtIkjnC8jXv2P11drgSRKNdlv0X5bJ3Bh0p4vARbye9pDIongDv+dOYsD2b44s5S55L2YePC+7OPs2Z1+ifOKWJjr+3c1M+CwugXQYANBglzbKrNqYAl45g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CuHn30tckrHqiTGGNrq8d/cvCZXDx5NmVuUEq/TvyP4=; b=fay9ijVmSiTkxt7DPuHG2/TaaUh7RURaiOn8XdRP7nlKG6SdHq6RAjeB7Tz/uxRjHr6Ij1Qu+oYFTKSAecNh1CV+IItVUYFb5vlMoCphW6V2ZDV0GyTCX4t6z8yHLd6Q+8pnGYil2kQq8jcbppsYlEQVPN4a95c/fUOGnHs4yow/C1vtFsA+YXn3K1ovGw44asffZV/bHIaVxenurFH28laod8ajkZldfZp98KaDTxGrlRIsGcx8Ls/jGI2JylDCw1jhRzrzXMsWHG6s0GwjwO5CA1byPLm2z1vxI7isQidhQnN4mmhEj0tyaqX34f6BAwW9sA0Peq2ZmSRxL2zEoQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) by DU2PR04MB8888.eurprd04.prod.outlook.com (2603:10a6:10:2e3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.21; Tue, 17 Dec 2024 09:11:54 +0000 Received: from DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7]) by DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7%6]) with mapi id 15.20.8251.015; Tue, 17 Dec 2024 09:11:54 +0000 From: Xu Yang To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, andre.draszik@linaro.org, rdbabiera@google.com, m.felsch@pengutronix.de, dan.carpenter@linaro.org, emanuele.ghidoli@toradex.com, parth.pancholi@toradex.com, francesco.dolcini@toradex.com, u.kleine-koenig@baylibre.com Cc: linux-usb@vger.kernel.org, imx@lists.linux.dev, jun.li@nxp.com Subject: [PATCH v3 1/2] usb: typec: tcpci: fix NULL pointer issue on shared irq case Date: Tue, 17 Dec 2024 17:12:07 +0800 Message-Id: <20241217091208.2416971-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SGAP274CA0014.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::26) To DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8822:EE_|DU2PR04MB8888:EE_ X-MS-Office365-Filtering-Correlation-Id: 7c27e12d-ef43-4011-78c6-08dd1e7ad9d0 X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|7416014|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: PyZmobOX1vHz9pLak2kp3pGIsYBuxBAkRUTtw2ygjorAclXN5eMtKGffo3FnUjr9zgi3nwkvxsUYuRzmGbN3/0CrTz8LSZIQqi3YtEf85O9bFeVNFXYpw116ihgdxUMEoX/HrrZvNsnyhu75/0XuB7yAxR8slqJUy7E+QQ4Z8pAG2J79P0QuQdkiM/Zd3QLluwslWMicmRZqTGNlgT0RebJZySKBckWYBIybWaKrNrtdEGUIDDrTKh9Wu2oGAyqB02p4xbnhEZH7N9VUBXjU/hQZWuxuoQG2do0AQtky12F6pufcri0h6SPf7S8046DDCfdTiDMSiZ1eEjHw7m7aEOb6vld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RgpcRuBj21OCV2b5QotRrcAySJtkHu8mVsCEfOK99NufAJRMdiQ4IaeowamoIrXLAOdkK3Xc9QWNEAw9vw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8822.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(7416014)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YwGhzF252adsCF6bytNkvRT+LWs7J9wVyZ5SO2NtIwUfUwRloP0pZ83VKLwPWprgNo0wFv9132EddCOhGOQx4RI5A7xgNGomG+oJUuENIoMUKTuUIxTUqBUkU3wo7LVKUgMo/UcgEMWFRGgrYN88awVjvpu4RmM/m2WPnk2ustrZkdGLZe5SasOan4IsXef4QpI1HjXpr462tDkPtjsEMScubNapBraDkSwboQ5BksRkLu5GeIxxl/9yGieD6LWZ52hloQtUxmNjasPzkFOopyYyoZQb489BlYUWyA+vxjfxtFXlL/3T9ZI2Ug/PZU1hSlK9qOcmFwzceVe4j93rZ/K5zG8w4Y08JRjJIoOfKmYzImGUIBSQkfuWINJLj7/SO2zUEGLfTsTNFWrcuOqUEq/5UMkZiMJulnFZe1GeRXG7J2xvdtJKhDE1AmQzHyPy/6W0r0+noIpFRnfM//W0v7cQiYEkqUS4FTwsHuzNj8PkJkH7HaCITMBpDY88IhqtLwTR9iLJb+AyzlFA8oC7zRWeKtOgB3uX69Xvn8h98nRDNnwRjB63hXNEGZWHAuUDvA3i4rOg9irdjHESZoWsdhtI+p56Iwa8jnLHenwGuS0/6JmCXMqma36MEiu6u2GcnV8706yQx8trGsjgAu/jGhQenVoYqOaM5m6tqg78vfWEoAUyhcw/FvXoMJqXHDFAZ0g/Lh9kISkMfWcs4brkYwcdeC5hz+4nzkPFw0AbEwhBedSLlBa13fLy14PrItCufcWZ8kNtQR/yijDXpcEeBo4ZkE8Lqm5kTrW9ptJCbO5SZwCf0bk9hFWZzSZy64eLs0WtERCVx4Fv6+VhypwBgvgJS5qLHRqrSY0Wv//w6VD0KOWfvJ+fkXHAARMJ3HBE9WsLB6H2+0iVxRqHFIKaTCXPNI36k7ihosrPLmn9ULZtTc3m4aG3Aliqvt2QpvYYm2V2zpVR9WyxHiY94qgAhARecoTyLkL0ePyF3YlPZac4Cm/EnO3YTK68EUdw6gbpPW9p+OrrL0FzzbSNKNWSUQ7O3fVq98wNOxWlFT5O6f+zxb3Tz3lHc+MuvThCHxnBuI6GqBtCRJ2uq6o/f7ZzEIf5yCs0+pfXEeQ0h5Dkq2cx+mV1foHiCBvd9kGmEVKgE3OpYfm1SnI2Vr1hIavysPdjl7VJicsrEVuoULC9HE3WYqXYZ5MK2tPa93bnAPQQgqq4StjvQQJI+11mNIOyPDzwhA1PrKZZA2evoRwe8mEPMAPnjwEAh0P3aXwkeHIIF+PCgdAVYfqe7/ycJE2N0vU5ugbh5P4yG2IbxeXMusyAhaTLf4Mq9f6pK87oiOKktVZuAfOMmdSX5T8Lm4oq5Euik443ZyGccJYHKlvLFPMWc8QG6Dlz6Grg93wdGy3MMKv11mtEX8YHekgHFLWVaBHreKzIubSs2GgttToKOBoaNUXtQfnpEpTN9b7+1oOBGu0wusWC7cnedR9O9iXmWofUNV+reM3QtawnQnZ7d8pm9fAyU78beq1prtV4FxdWEzyDfez1wCyPAGmwZdaMyoCqxcOOhAdzgoALwPnmknzXto7dlTtAAuWi9ohiEiRZ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c27e12d-ef43-4011-78c6-08dd1e7ad9d0 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8822.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 09:11:54.8037 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Kp2yFzIly1jmVzZeTLbOMmDws/FkzYYcZPxP8A9ExspF74LCRC5kLuCBq5UYTa5Of8gJbovVNQO3Z5a9Ez44Xw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8888 The tcpci_irq() may meet below NULL pointer dereference issue: [ 2.641851] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 [ 2.641951] status 0x1, 0x37f [ 2.650659] Mem abort info: [ 2.656490] ESR = 0x0000000096000004 [ 2.660230] EC = 0x25: DABT (current EL), IL = 32 bits [ 2.665532] SET = 0, FnV = 0 [ 2.668579] EA = 0, S1PTW = 0 [ 2.671715] FSC = 0x04: level 0 translation fault [ 2.676584] Data abort info: [ 2.679459] ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000 [ 2.684936] CM = 0, WnR = 0, TnD = 0, TagAccess = 0 [ 2.689980] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 [ 2.695284] [0000000000000010] user address but active_mm is swapper [ 2.701632] Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP [ 2.707883] Modules linked in: [ 2.710936] CPU: 1 UID: 0 PID: 87 Comm: irq/111-2-0051 Not tainted 6.12.0-rc6-06316-g7f63786ad3d1-dirty #4 [ 2.720570] Hardware name: NXP i.MX93 11X11 EVK board (DT) [ 2.726040] pstate: 60400009 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 2.732989] pc : tcpci_irq+0x38/0x318 [ 2.736647] lr : _tcpci_irq+0x14/0x20 [ 2.740295] sp : ffff80008324bd30 [ 2.743597] x29: ffff80008324bd70 x28: ffff800080107894 x27: ffff800082198f70 [ 2.750721] x26: ffff0000050e6680 x25: ffff000004d172ac x24: ffff0000050f0000 [ 2.757845] x23: ffff000004d17200 x22: 0000000000000001 x21: ffff0000050f0000 [ 2.764969] x20: ffff000004d17200 x19: 0000000000000000 x18: 0000000000000001 [ 2.772093] x17: 0000000000000000 x16: ffff80008183d8a0 x15: ffff00007fbab040 [ 2.779217] x14: ffff00007fb918c0 x13: 0000000000000000 x12: 000000000000017a [ 2.786341] x11: 0000000000000001 x10: 0000000000000a90 x9 : ffff80008324bd00 [ 2.793465] x8 : ffff0000050f0af0 x7 : ffff00007fbaa840 x6 : 0000000000000031 [ 2.800589] x5 : 000000000000017a x4 : 0000000000000002 x3 : 0000000000000002 [ 2.807713] x2 : ffff80008324bd3a x1 : 0000000000000010 x0 : 0000000000000000 [ 2.814838] Call trace: [ 2.817273] tcpci_irq+0x38/0x318 [ 2.820583] _tcpci_irq+0x14/0x20 [ 2.823885] irq_thread_fn+0x2c/0xa8 [ 2.827456] irq_thread+0x16c/0x2f4 [ 2.830940] kthread+0x110/0x114 [ 2.834164] ret_from_fork+0x10/0x20 [ 2.837738] Code: f9426420 f9001fe0 d2800000 52800201 (f9400a60) This may happen on shared irq case. Such as two Type-C ports share one irq. After the first port finished tcpci_register_port(), it may trigger interrupt. However, if the interrupt comes by chance the 2nd port finishes devm_request_threaded_irq(), the 2nd port interrupt handler may be run at first. Then the above issue may happen. devm_request_threaded_irq() <-- port1 irq comes disable_irq(client->irq); tcpci_register_port() This will restore the logic to the state before commit (77e85107a771 "usb: typec: tcpci: support edge irq"). Fixes: 77e85107a771 ("usb: typec: tcpci: support edge irq") Cc: stable@vger.kernel.org Signed-off-by: Xu Yang --- Changes in v3: = no changes Changes in v2: - no changes --- drivers/usb/typec/tcpm/tcpci.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 2f15734a5043..db42f4bf3632 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -923,22 +923,20 @@ static int tcpci_probe(struct i2c_client *client) chip->data.set_orientation = err; + chip->tcpci = tcpci_register_port(&client->dev, &chip->data); + if (IS_ERR(chip->tcpci)) + return PTR_ERR(chip->tcpci); + err = devm_request_threaded_irq(&client->dev, client->irq, NULL, _tcpci_irq, IRQF_SHARED | IRQF_ONESHOT, dev_name(&client->dev), chip); - if (err < 0) + if (err < 0) { + tcpci_unregister_port(chip->tcpci); return err; + } - /* - * Disable irq while registering port. If irq is configured as an edge - * irq this allow to keep track and process the irq as soon as it is enabled. - */ - disable_irq(client->irq); - chip->tcpci = tcpci_register_port(&client->dev, &chip->data); - enable_irq(client->irq); - - return PTR_ERR_OR_ZERO(chip->tcpci); + return 0; } static void tcpci_remove(struct i2c_client *client)