Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Jorge Marques <jorge.marques@analog.com>,
	Frank Li <Frank.Li@nxp.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-i3c@lists.infradead.org
Subject: [PATCH AUTOSEL 6.16-6.1] i3c: master: Initialize ret in i3c_i2c_notifier_call()
Date: Fri,  8 Aug 2025 11:30:47 -0400	[thread overview]
Message-ID: <20250808153054.1250675-7-sashal@kernel.org> (raw)
In-Reply-To: <20250808153054.1250675-1-sashal@kernel.org>

From: Jorge Marques <jorge.marques@analog.com>

[ Upstream commit 290ce8b2d0745e45a3155268184523a8c75996f1 ]

Set ret to -EINVAL if i3c_i2c_notifier_call() receives an invalid
action, resolving uninitialized warning.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/r/20250622-i3c-master-ret-uninitialized-v1-1-aabb5625c932@analog.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

**YES**

This commit should be backported to stable kernel trees. Here's my
extensive analysis:

## Bug Analysis

The commit fixes a serious uninitialized variable bug in
`i3c_i2c_notifier_call()`. Looking at the code:

1. **The Bug**: The function declares `int ret` at line 2449 but doesn't
   initialize it. The switch statement only handles two cases
   (`BUS_NOTIFY_ADD_DEVICE` and `BUS_NOTIFY_DEL_DEVICE`), leaving `ret`
   uninitialized for any other action values.

2. **When It Triggers**: Since this notifier is registered with
   `bus_register_notifier(&i2c_bus_type, &i2cdev_notifier)`, it receives
   ALL bus notification events for I2C devices, including:
   - `BUS_NOTIFY_REMOVED_DEVICE`
   - `BUS_NOTIFY_BIND_DRIVER`
   - `BUS_NOTIFY_BOUND_DRIVER`
   - `BUS_NOTIFY_UNBIND_DRIVER`
   - `BUS_NOTIFY_UNBOUND_DRIVER`
   - `BUS_NOTIFY_DRIVER_NOT_BOUND`

3. **Impact**: When any of these unhandled actions occur, the function
   returns an uninitialized stack value, which could:
   - Accidentally return `NOTIFY_STOP` or `NOTIFY_BAD`, halting the
     notification chain
   - Cause unpredictable behavior in the device/driver binding process
   - Lead to intermittent, hard-to-debug failures

## Backport Criteria Analysis

1. **Fixes a real bug**: ✓ Yes - fixes an uninitialized variable that
   causes undefined behavior
2. **Small and contained**: ✓ Yes - adds only 2 lines (default case
   returning -EINVAL)
3. **No side effects**: ✓ Correct - the fix properly handles unexpected
   actions by returning an error
4. **No architectural changes**: ✓ Correct - simple bug fix, no design
   changes
5. **Critical subsystem**: ✓ Yes - affects I3C/I2C device management and
   driver binding
6. **Follows stable rules**: ✓ Yes - important bugfix with minimal risk

## Additional Context

- The bug was introduced in commit 72a4501b5d08 ("i3c: support
  dynamically added i2c devices") in January 2022
- The I3C subsystem has had other uninitialized variable fixes (e.g.,
  commit 6cbf8b38dfe3)
- This is a classic compiler warning fix that prevents real runtime
  issues
- The fix is conservative, returning -EINVAL for unexpected actions
  rather than silently ignoring them

This is exactly the type of bug that stable kernels should fix: a real
issue with unpredictable runtime consequences, fixed with a minimal,
safe change.

 drivers/i3c/master.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index e53c69d24873..dfa0bad991cf 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2467,6 +2467,8 @@ static int i3c_i2c_notifier_call(struct notifier_block *nb, unsigned long action
 	case BUS_NOTIFY_DEL_DEVICE:
 		ret = i3c_master_i2c_detach(adap, client);
 		break;
+	default:
+		ret = -EINVAL;
 	}
 	i3c_bus_maintenance_unlock(&master->bus);
 
-- 
2.39.5


  parent reply	other threads:[~2025-08-08 15:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 15:30 [PATCH AUTOSEL 6.16-6.6] apparmor: shift ouid when mediating hard links in userns Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] md: dm-zoned-target: Initialize return variable r to avoid uninitialized use Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.4] i3c: don't fail if GETHDRCAP is unsupported Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] dm-mpath: don't print the "loaded" message if registering fails Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 Sasha Levin
2025-08-11 16:46   ` Meagan Lloyd
2025-08-16 13:07     ` Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.4] i3c: add missing include to internal header Sasha Levin
2025-08-08 15:30 ` Sasha Levin [this message]
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.4] PCI: pnv_php: Work around switches with broken presence detection Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.1] module: Prevent silent truncation of module name in delete_module(2) Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.1] apparmor: use the condition in AA_BUG_FMT even with debug disabled Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.6] powerpc/eeh: Make EEH driver device hotplug safe Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.12] apparmor: fix x_table_lookup when stacking is not the first entry Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-6.1] dm-table: fix checking for rq stackable devices Sasha Levin
2025-08-08 15:30 ` [PATCH AUTOSEL 6.16-5.10] PCI: pnv_php: Clean up allocated IRQs on unplug Sasha Levin
2025-08-08 15:59   ` Timothy Pearson
2025-08-08 17:04     ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250808153054.1250675-7-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=jorge.marques@analog.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox