From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7466348C7C for ; Thu, 25 Jun 2026 16:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782403355; cv=none; b=uTiqmYvvcG/Ce0eYeoHJMdYxkZJRl3qXWauhh2/HVdrsA5Zmeudlmsw7ZM1+/jtnxWrVGluFoE03VLIHIbB7xW+e0goZauU0RG47sv5zdLS01mcit6jWlDZNYcVmPOzWUDdqQfrIr731wWDmEuvNSj35gVaYztLXp9RfkYboQKI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782403355; c=relaxed/simple; bh=L9c5Szdgt8qF07KpP6DJofk4aMPG49dmybsPbBc1Q4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aiEbPR/6Pd/VtVH1AkqJII+0rXo57QocG8Zm1Zan/cSmFyfGPAAhxr+b4VV27J3OB4NJ+BsANyQ9TotEBCz6GDOWc5xtBBQEFJzX5OixL8rSOjrwFVprNY/NbLuFM/E3f0Oo1xPvQiymHLF8RNAcHLy1n2crKTTcNMBfoPGdfwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kRm59YCW; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kRm59YCW" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2c7ebfbf2d4so545895ad.2 for ; Thu, 25 Jun 2026 09:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782403353; x=1783008153; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7uBKJbZacR7qpAxgkxKTYuFWT8lf0EijVUm+JTDcFsE=; b=kRm59YCWFYAvGQCkmCZDJRC4Cm8V/xJYTHnADBD819LZ524O1EJkiwRbBpBsjLRB2r NUwHmNcNMxEGb2oumraGN/uZv65o+6+m9dmuz6LLINRUSGSHH14xqhIeCrdVIk4BqoCX YI/ynEyfH5h2hpeJX/RuN/fwvcvG5KqRsRlArZZVrVoGyqyFfZGO1mPC/XMxPdnTBs21 HUV9LLBO90mkk64r8LO9Q3UHGNQd+GV3s3Mvb4oB8779zS7IcWiiLHIaTBt8iZPWV32O /k6LcUSKHx+y45TedvsBhPJEdBSt9Vb/YHH6CFfC7Vjgjy5w0/f6NXhnE4T5lAgLCYfh kzuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782403353; x=1783008153; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7uBKJbZacR7qpAxgkxKTYuFWT8lf0EijVUm+JTDcFsE=; b=Ce5nCbtwwG94m+34Rpx+/oP/vw3Mxmt3otzJooUbd2Pu2GhXPCW+/XFyUR88SB8QZ5 Pbdbkcvn4DFkUqF14QBpUfmo9SsIVNtI05Y0cgn61LSZ7A5QoOzl8OOowelizG0c98zy ztsSrePYNzK2PYhuVyWfIBa3i2OVXUlpMcKMbJL4VEs4jn4d/aqv9w8G6uiJv09K4pvm ahX29vkOPohA5xpu6TUD+OtHr0R3ElgH7H6WbqbDzqqD57sXXEz+1jmFlYpCLUObHKra p3QCgVwOx3mm8nLti/cFswzN1vEmGZq9qKq9IuDR578FOA21EcKcTX5dXby/fA+QAS+Y asUA== X-Forwarded-Encrypted: i=1; AHgh+RpsnXSfcNPBtAJtkKe5o5KSRzF6UWSCh2sFxyP8ylQV4U8fpgFqo6wujSQ/Vatp+WbNWyCRSborrRMJYIE=@vger.kernel.org X-Gm-Message-State: AOJu0YwJJoVISb9u7rbhU1H2wfkWLuH7qE+QtFL9WTvGcB1mat5vW1Dq G5XPIorWdmw4fVQw8f6yNLp/Oq1Q7P2ERIYDvJXhm5jjlHaCYfkPTG7Z X-Gm-Gg: AfdE7clny6LIPEp3emgI1a9skUuCOZMhxnyyEnzsrohf3LdihQOd3ZV22SBD7Kkva+u T5wus3VFY2kqEwU13bpQbe0Yx6JxpGEln8jQCuQZF3y3jfjMOhVNKgbbXAkTvOhC2yxrvtpkMcZ Bgp+S1e6I+UUvZtrENqEis5nIngku/dTsDwF7jArYFRhGq5WmbwizM0DMKrEirxtYU5CXn5qhir Xwwev0BzGoYSlP8XrpJuExZv3jXzF7RA805s8hFxp9b+KPvZFUMRuSa7bUIsVH5S+nZnRT0byKQ rgtf5MHRk+eHRKSOIpDOoGZenT0mOLHzB6ddwPUvIvY4skzNGGNnfwNPvwc6LAzcsPrW7FEMdpb jlaO3Z5L/Re5gw4T3cBc2O5eZ+L94HEvqkZWyuGi5G1Y63K7TPcxaGa+LhnCNO1mk8Ge869bkAs y/8JWFjx2UIsfUm54TmvpcrRCejT6eX4qY2xf+ X-Received: by 2002:a17:902:d483:b0:2c6:6424:c79f with SMTP id d9443c01a7336-2c7fc708aa6mr35566035ad.8.1782403352803; Thu, 25 Jun 2026 09:02:32 -0700 (PDT) Received: from liem-TUF-Gaming-FX505GM-FX86FM ([240e:39b:ee0:1b70:943:8348:4ae1:4072]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c7f5ac88cfsm24127925ad.2.2026.06.25.09.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 09:02:32 -0700 (PDT) From: Liem To: Oleksij Rempel Cc: Andi Shyti , Pengutronix Kernel Team , Frank Li , Sascha Hauer , Fabio Estevam , Biwen Li , Wolfram Sang , linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Liem Subject: [PATCH v2] i2c: imx: Fix slave registration error path and missing timer cleanup Date: Fri, 26 Jun 2026 00:02:19 +0800 Message-ID: <20260625160219.55116-1-liem16213@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260625071130.93544-1-liem16213@gmail.com> References: <20260625071130.93544-1-liem16213@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There are two issues that affect the i2c-imx slave handling: 1. In i2c_imx_reg_slave(), i2c_imx->slave is checked at the beginning and the function returns -EBUSY if it is non-NULL. If pm_runtime_resume_and_get() fails later, the error path returns without clearing i2c_imx->slave, leaving it non-NULL. Subsequent attempts to register a slave will then immediately fail with -EBUSY, making it impossible to register the slave again. Fix by setting i2c_imx->slave = NULL on the error path. 2. In i2c_imx_unreg_slave(), the slave pointer is set to NULL after disabling interrupts. However, a pending interrupt might already have started the hrtimer (i2c_imx_slave_timeout) before the pointer was cleared. If the hrtimer fires after i2c_imx->slave is set to NULL, the timer callback i2c_imx_slave_finish_op() will call i2c_imx_slave_event() with a NULL slave pointer, and the last_slave_event check loop in i2c_imx_slave_finish_op() may cause a system hang because last_slave_event is no longer updated. Fix by canceling the hrtimer and waiting for it to complete after disabling interrupts, before clearing the slave pointer. Both issues can trigger a kernel oops, system hang, or permanent slave registration failure under certain race conditions. Add the missing NULL assignment and the missing hrtimer cleanup to harden the slave path. Fixes: f7414cd6923f ("i2c: imx: support slave mode for imx I2C driver") Cc: stable@vger.kernel.org Signed-off-by: Liem --- v1 -> v2: - Instead of adding a NULL check in i2c_imx_slave_event(), cancel the hrtimer and wait for it to finish in i2c_imx_unreg_slave() after disabling interrupts, as suggested by . This avoids a potential hang in the last_slave_event loop in i2c_imx_slave_finish_op(). --- drivers/i2c/busses/i2c-imx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 28313d0fad37..04ffb927aba9 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -936,6 +936,7 @@ static int i2c_imx_reg_slave(struct i2c_client *client) /* Resume */ ret = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent); if (ret < 0) { + i2c_imx->slave = NULL; dev_err(&i2c_imx->adapter.dev, "failed to resume i2c controller"); return ret; } @@ -957,7 +958,7 @@ static int i2c_imx_unreg_slave(struct i2c_client *client) imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR); i2c_imx_reset_regs(i2c_imx); - + hrtimer_cancel(&i2c_imx->slave_timer); i2c_imx->slave = NULL; /* Suspend */ -- 2.53.0