[PATCH 10/10] i2c: octeon: Guard to_pci_dev() with dev_is_pci() in octeon_i2c_set_clock()

From: Lee Jones

Date: Thu Dec 03 2026 - 13:33:54 EST


octeon_i2c_set_clock() unconditionally passes i2c->dev to to_pci_dev()
and inspects pdev->subsystem_device. When invoked from the OCTEON
platform driver, i2c->dev belongs to a struct platform_device rather
than a struct pci_dev, resulting in an out-of-bounds slab read.

Check dev_is_pci(i2c->dev) before calling to_pci_dev().

Fixes: 114c69f4be3f ("i2c: thunderx: Clock divisor logic changes")
Closes: https://sashiko.dev/#/bug/linux-b92a3410-8945-4cb5-b326-12bdf64a66f5
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/i2c/busses/i2c-octeon-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c
index 93a49e4637ec..206476007351 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -833,7 +833,8 @@ void octeon_i2c_set_clock(struct octeon_i2c *i2c)
unsigned int thp, mdiv_min, mdiv = 2, ndiv = 0, ds = 10;
unsigned int delta_hz = INITIAL_DELTA_HZ;

- is_plat_otx2 = octeon_i2c_is_otx2(to_pci_dev(i2c->dev));
+ is_plat_otx2 = dev_is_pci(i2c->dev) &&
+ octeon_i2c_is_otx2(to_pci_dev(i2c->dev));

if (is_plat_otx2) {
thp = TWSI_MASTER_CLK_REG_OTX2_VAL;
--
2.56.1.911.g883d8bcb20-goog