Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796010282; b=XuGNvqiPiwOx9GLdh0/UNldnhP41mHUiqdtzJEZ7kwaAVKPZrt4ZphIiJ0K9QWeGcEGo nCAEgV5WBPA7R5vHda3ADWQml9SveBlc0hDcx3IC7PfrT9UuUnuuGJxZT2fPoHEpMDP7Y nvccqoepfJW/shzfwq328mkX6LCjimiF3LpH6+UGGZgyFYZzm6tjhkkrtveqgh8zPm83p 0OY9Q7VjgOqrW1CbGm+Te58BGJTDydbe7o5XHrfJ5KTdO1YIxWEmZz2W9XE1aAEqPZkls N8L6dtYqco7dZzhZ9Mv7s/KkxPq6Zp8zDNar/UJnG1t3+F7jfBnEfBMqoZ+yah9Q8cg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010282; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=4IKQASxgljurJy3BgoLL6NJlyWbePkfmjXXJBKe5LBc=; b=QP3qk7xkr8a3+7ZjiuwJtxe8F+hF3LJm0jSeZdZDX8pP+EWYHI4TPky52vuP3gfQAufc kR4RWJkXVP8GeGwT76qhtV+CfH6f+ZTBr8QByXXRtKshEfUe6TDK1W63B3lJ+y3n345+T trXpaPBvt5c0v7qSCHYtVJOyMuApvHdbhgycR7fDzKjMrpEph2Xylnef/bRXqCLTy9yT3 ii3SVJdnn6sVzLvqopd8xKd5nW9wvRcCn/nypRT6CLN7XL4QFHTpT64dxmWtiLmM8O5N4 dwPaS3c6brZs8hU1RgOFDT5ldtI3uyKT81MoUqiG8YuyfYSC5XhF+SU+xBWRSHGOg2A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DElUd00e; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DDB6606A31C for ; Mon, 30 Nov 2026 03:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DElUd00e Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EDE81F00898; Mon, 30 Nov 2026 03:44:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796010281; bh=4IKQASxgljurJy3BgoLL6NJlyWbePkfmjXXJBKe5LBc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=DElUd00ejMoUZdlGxZs6l8X6r9YpL2JxgjvEo6gJpzQ8FO8L816SpE4WG1Y7/lKqj 75ENdm4ls4w3K2ZB2Sx3BsoVorboBUbST3LjA6RuLboXd2KXTev0ihE8WLPLNwSJY/ LWetOUseMC2FMxEi7ArcQmBsXRbNKrjNGSpmXEy21BJMAhloWse1YhwINoD6L8hFR/ 9cVJWiD0+9EXraySYRf20B9c6x4NtaS7F9wpCMLPxhnVXSInl+0ghiChSEgleGAuZQ NLW6hOirHH8wKPRa+Sob8YsluLGwvcj+SJvHACvtyVj3VmRlQsu5VVNalBgwAkTNXN fPp+31LUM56Aw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RESEND v12 2/3] i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support Reply-To: sashiko-reviews@lists.linux.dev To: "Zi-Yu Chen" , devicetree@vger.kernel.org Cc: robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261130032346.1720769-3-zychennvt@gmail.com> References: <20261130032346.1720769-1-zychennvt@gmail.com> <20261130032346.1720769-3-zychennvt@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 03:44:40 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 11 potential issues to consider: - [High] i2c: ma35d1: failure to clear STA and STO bits in ma35d1_i2c_write_ctl() - [High] i2c: ma35d1: NULL i2c->target dereference and race in ma35d1_i2c_irq_target_trx() - [Medium] i2c: ma35d1: clearing of AA bit during controller start breaks target mode - [Medium] i2c: ma35d1: premature wakeup on arbitration loss corrupts active target xfer - [Medium] i2c: ma35d1: unhandled 0xc8/0xf8 statuses and missing target read STOP event - [Medium] i2c: ma35d1: ignored I2C_SLAVE_WRITE_RECEIVED error in ma35d1_i2c_irq_target_trx() - [Medium] i2c: ma35d1: uncleared MA35_WKSTS in ma35d1_i2c_irq() causes resume IRQ storm - [Medium] i2c: ma35d1: stale target_reject state after ma35d1_i2c_reset() - [Low] i2c: ma35d1: missing I2C_FUNC_SLAVE flag in ma35d1_i2c_func() - [Low] i2c: ma35d1: missing pm_runtime_dont_use_autosuspend() in ma35d1_i2c_pm_cleanup() - [Low] i2c: ma35d1: mishandled pm_runtime_put_sync() return in ma35d1_unreg_target() -- commit 0a5481a7c6218eeb6b2a9112888fe1a57dc147c6 Author: Zi-Yu Chen i2c: ma35d1: Add Nuvoton MA35D1 I2C driver support This commit adds the I2C bus driver for the Nuvoton MA35D1 SoC with controller and target mode support. > diff --git a/drivers/i2c/busses/i2c-ma35d1.c b/drivers/i2c/busses/i2c-ma3= 5d1.c > new file mode 100644 > index 0000000000000..29bed9eb28f67 > --- /dev/null > +++ b/drivers/i2c/busses/i2c-ma35d1.c [ ... ] > +static void ma35d1_i2c_write_ctl(struct ma35d1_i2c *i2c, unsigned int ct= l) > +{ > + unsigned int val; > + > + guard(spinlock_irqsave)(&i2c->lock); > + val =3D readl(i2c->regs + MA35_CTL0); > + val &=3D ~(MA35_CTL_SI_AA); > + val |=3D ctl; > + writel(val, i2c->regs + MA35_CTL0); > +} [Severity: High] Does ma35d1_i2c_write_ctl() also need to clear MA35_CTL_STA and MA35_CTL_STO from val before ORing in ctl? After ma35d1_i2c_doxfer() sets MA35_CTL_STA, the MA35_M_START handler writes the target address and calls ma35d1_i2c_write_ctl(i2c, MA35_CTL_SI) to clear STA and SI and shift out the address byte. Because val &=3D ~(MA35_CTL_SI_AA) leaves MA35_CTL_STA set in MA35_CTL0, the controller keeps re-asserting START instead of transmitting the address, causing controller transfers to time out and reset. [Severity: Medium] When i2c->target is registered, does clearing MA35_CTL_AA here on ma35d1_i2c_write_ctl(i2c, MA35_CTL_STA) in ma35d1_i2c_doxfer() and ma35d1_i2c_write_ctl(i2c, MA35_CTL_SI) in MA35_M_START prevent the controller from ACKing its own target address if multi-master arbitration is lost? Without MA35_CTL_AA set during the START and address phase, the hardware will not enter the MA35_S_RECE_ARB_LOST or MA35_ADDR_TRAN_ARB_LOST states handled in ma35d1_i2c_irq_target_trx(). [ ... ] > +static void ma35d1_i2c_reset(struct ma35d1_i2c *i2c) > +{ > + unsigned int clkdiv, slvaddr; > + > + clkdiv =3D readl(i2c->regs + MA35_CLKDIV); > + slvaddr =3D readl(i2c->regs + MA35_ADDR0); > + > + disable_irq(i2c->irq); > + i2c->msg =3D NULL; > + reset_control_assert(i2c->rst); > + usleep_range(10, 20); > + reset_control_deassert(i2c->rst); > + enable_irq(i2c->irq); > + > + writel(clkdiv, (i2c->regs + MA35_CLKDIV)); > + ma35d1_i2c_write_ctl(i2c, MA35_CTL_I2CEN | MA35_CTL_INTEN); > + > + if (i2c->target) > + writel(slvaddr, i2c->regs + MA35_ADDR0); > +} [Severity: Medium] Should ma35d1_i2c_reset() also reset i2c->target_reject =3D false (and restore MA35_CTL_AA when i2c->target is active), or should MA35_S_RECE_ADDR_ACK and MA35_S_TRAN_ADDR_ACK clear i2c->target_reject at the start of a target transfer? If a target write sets i2c->target_reject =3D true and a controller transfer then times out into ma35d1_i2c_reset(), the hardware reset aborts the target transaction before MA35_S_RECE_DATA_NACK or MA35_S_REPEAT_START_STOP can clear i2c->target_reject. The next target transaction sees the stale true value and clears MA35_CTL_AA at the end of ma35d1_i2c_irq_target_trx(). [ ... ] > +static irqreturn_t ma35d1_i2c_irq_target_trx(struct ma35d1_i2c *i2c, > + unsigned long i2c_status) > +{ > + unsigned char byte =3D 0; > + int ret; > + > + switch (i2c_status) { > + case MA35_S_RECE_ARB_LOST: > + /* > + * Arbitration lost during address transmission phase. > + * The hardware switches to Target Transmitter mode when > + * our own SLA+W is detected on the bus. > + */ > + i2c->err =3D -EAGAIN; > + ma35d1_i2c_controller_complete(i2c); > + ret =3D i2c_slave_event(i2c->target, I2C_SLAVE_WRITE_REQUESTED, > + &byte); > + if (ret) > + i2c->target_reject =3D true; > + break; > + > + case MA35_S_RECE_ADDR_ACK: > + /* Own SLA+W has been receive; ACK has been return */ > + ret =3D i2c_slave_event(i2c->target, I2C_SLAVE_WRITE_REQUESTED, > + &byte); > + if (ret) > + i2c->target_reject =3D true; > + break; > + > + case MA35_S_TRAN_DATA_NACK: > + case MA35_S_RECE_DATA_NACK: > + /* > + * Data byte or last data in I2CDAT has been transmitted and NACK rece= ived, > + * or previously addressed with own SLA address and NACK returned. > + */ > + i2c->target_reject =3D false; > + break; > + > + case MA35_S_RECE_DATA_ACK: > + /* > + * Previously address with own SLA address Data has been received; > + * ACK has been returned > + */ > + byte =3D readb(i2c->regs + MA35_DAT); > + i2c_slave_event(i2c->target, I2C_SLAVE_WRITE_RECEIVED, &byte); > + break; [Severity: Medium] As reported by Andi Shyti on v10 [1], should MA35_S_RECE_DATA_ACK check the return value of i2c_slave_event() and set i2c->target_reject =3D true on error? Otherwise the controller re-arms MA35_CTL_SI_AA and continues ACKing subsequent bytes after the target backend signals an error or full buffer. > + > + case MA35_ADDR_TRAN_ARB_LOST: > + /* > + * Arbitration lost during address transmission phase. > + * The hardware switches to Target Receiver mode when > + * our own SLA+R is detected on the bus. > + */ > + i2c->err =3D -EAGAIN; > + ma35d1_i2c_controller_complete(i2c); > + i2c_slave_event(i2c->target, I2C_SLAVE_READ_REQUESTED, &byte); > + writel(byte, i2c->regs + MA35_DAT); > + break; [Severity: Medium] Can waking up ma35d1_i2c_doxfer() via ma35d1_i2c_controller_complete() before updating MA35_CTL0 in MA35_S_RECE_ARB_LOST, MA35_ADDR_TRAN_ARB_LOST, and MA35_M_ARB_LOST race with ma35d1_i2c_xfer() and automatic retries? CPU0 CPU1 () ma35d1_i2c_xfer() ma35d1_i2c_doxfer() wait_event_timeout() ma35d1_i2c_irq_target_trx() case MA35_S_RECE_ARB_LOST: i2c->err =3D -EAGAIN; ma35d1_i2c_controller_complete() /* woken up, STO is 0 */ if (i2c->target) ma35d1_i2c_write_ctl(MA35_CTL_AA) return -EAGAIN; __i2c_transfer() /* retries =3D 2 */ ma35d1_i2c_xfer() ma35d1_i2c_doxfer() ma35d1_i2c_write_ctl(MA35_CTL_STA) i2c_slave_event(...) ma35d1_i2c_write_ctl(...) In MA35_S_RECE_ARB_LOST and MA35_ADDR_TRAN_ARB_LOST the hardware has just entered target mode at the start of an incoming transfer, so returning -EAGAIN immediately causes __i2c_transfer() to retry ma35d1_i2c_doxfer() and assert MA35_CTL_STA in the middle of the active target transaction. In MA35_M_ARB_LOST, if CPU0 runs ma35d1_i2c_write_ctl(i2c, MA35_CTL_AA) in ma35d1_i2c_xfer() before CPU1 runs ma35d1_i2c_write_ctl(i2c, MA35_CTL_SI), CPU1 clears MA35_CTL_AA and leaves target mode disabled. Also, the comments on MA35_S_RECE_ARB_LOST and MA35_ADDR_TRAN_ARB_LOST have Target Transmitter and Target Receiver swapped. > + > + case MA35_S_TRAN_ADDR_ACK: > + /* Own SLA+R has been receive; ACK has been return */ > + i2c_slave_event(i2c->target, I2C_SLAVE_READ_REQUESTED, &byte); > + writel(byte, i2c->regs + MA35_DAT); > + break; > + > + case MA35_S_TRAN_DATA_ACK: > + i2c_slave_event(i2c->target, I2C_SLAVE_READ_PROCESSED, &byte); > + writel(byte, i2c->regs + MA35_DAT); > + break; > + > + case MA35_S_REPEAT_START_STOP: > + /* > + * A STOP or repeated START has been received > + * while still addressed as Target/Receiver > + */ > + i2c_slave_event(i2c->target, I2C_SLAVE_STOP, &byte); > + i2c->target_reject =3D false; > + break; > + > + default: > + dev_err(i2c->dev, "Status 0x%02lx is NOT processed\n", > + i2c_status); > + ma35d1_i2c_restore_idle(i2c); > + return IRQ_NONE; > + } > + if (i2c->target_reject) > + ma35d1_i2c_write_ctl(i2c, MA35_CTL_SI); > + else > + ma35d1_i2c_write_ctl(i2c, MA35_CTL_SI_AA); > + return IRQ_HANDLED; > +} [Severity: Medium] What happens when the controller reports MA35_S_TRAN_LAST_DATA_ACK (0xc8) or MA35_BUS_RELEASED (0xf8), which are defined at the top of the file but not handled in this switch? Both statuses fall outside ma35d1_is_controller_status() and land in default: here, logging an error, calling ma35d1_i2c_restore_idle() (which aborts any active controller transfer with -EIO), and returning IRQ_NONE. In addition, when an external controller ends a target read with NACK (MA35_S_TRAN_DATA_NACK) or after MA35_S_TRAN_LAST_DATA_ACK, the hardware is no longer addressed and does not raise MA35_S_REPEAT_START_STOP on the subsequent STOP, so the target backend never receives I2C_SLAVE_STOP after a read transaction. [ ... ] > +static irqreturn_t ma35d1_i2c_irq(int irqno, void *dev_id) > +{ > + struct ma35d1_i2c *i2c =3D dev_id; > + unsigned long status; > + > + status =3D readl(i2c->regs + MA35_STATUS0); > + > + if (status =3D=3D MA35_BUS_ERROR) { > + dev_err(i2c->dev, "bus error\n"); > + ma35d1_i2c_restore_idle(i2c); > + return IRQ_HANDLED; > + } > + > + if (ma35d1_is_controller_status(status)) > + return ma35d1_i2c_irq_controller_trx(i2c, status); > + else > + return ma35d1_i2c_irq_target_trx(i2c, status); > +} [Severity: Medium] Can an I2C target wakeup event cause an interrupt storm during system resume because ma35d1_i2c_irq() never clears MA35_WKSTS? ma35d1_i2c_suspend() enables wake-up in MA35_WKCTL and calls enable_irq_wake(i2c->irq). On resume, dpm_resume_noirq() unmasks i2c->irq before ma35d1_i2c_resume() runs in dpm_resume(), so the latched wakeup flag in MA35_WKSTS keeps the level-triggered interrupt asserted while ma35d1_i2c_irq() only reads MA35_STATUS0. [ ... ] > +static int ma35d1_unreg_target(struct i2c_client *target) > +{ > + struct ma35d1_i2c *i2c =3D i2c_get_adapdata(target->adapter); > + int ret; > + > + if (!i2c->target) > + return -EINVAL; > + > + writel(0, i2c->regs + MA35_ADDR0); > + /* Clear AA bit */ > + ma35d1_i2c_write_ctl(i2c, 0); > + > + synchronize_irq(i2c->irq); > + i2c->target =3D NULL; > + > + ret =3D pm_runtime_put_sync(i2c->dev); > + if (ret < 0) > + dev_err(i2c->dev, "failed to suspend i2c controller"); > + > + return 0; > +} [Severity: High] Can ma35d1_i2c_irq_target_trx() dereference a NULL i2c->target in i2c_slave_event() or re-enable MA35_CTL_AA during ma35d1_unreg_target()? CPU0 CPU1 () ma35d1_unreg_target() ma35d1_i2c_irq_target_trx() i2c_slave_event(i2c->target, ...) writel(0, i2c->regs + MA35_ADDR0) ma35d1_i2c_write_ctl(i2c, 0) ma35d1_i2c_write_ctl(MA35_CTL_SI_AA) synchronize_irq(i2c->irq) i2c->target =3D NULL ma35d1_i2c_irq_target_trx() i2c_slave_event(NULL, ...) <-- NULL pointer dereference Even if no IRQ is running when ma35d1_i2c_write_ctl(i2c, 0) executes, an external controller that already addressed this device before MA35_ADDR0 and MA35_CTL_AA were cleared will still raise a target interrupt on the in-flight byte or STOP condition after i2c->target is set to NULL, and ma35d1_i2c_irq_target_trx() never checks i2c->target before calling i2c_slave_event() or re-setting MA35_CTL_AA. [Severity: Low] Should ma35d1_unreg_target() call pm_runtime_put_autosuspend(i2c->dev) like ma35d1_i2c_xfer() instead of checking pm_runtime_put_sync() for ret < 0? pm_runtime_put_sync() returns negative values such as -ENOSYS (when CONFIG_PM is disabled) or -EBUSY even when the usage count was decremented normally, logging a false error (which is also missing a trailing newline). > + > +/* Declare Our I2C Functionality */ > +static u32 ma35d1_i2c_func(struct i2c_adapter *adap) > +{ > + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; > +} [Severity: Low] Should ma35d1_i2c_func() also advertise I2C_FUNC_SLAVE since the driver selects I2C_SLAVE and implements .reg_target and .unreg_target? [ ... ] > +static void ma35d1_i2c_pm_cleanup(void *data) > +{ > + struct device *dev =3D data; > + > + pm_runtime_get_sync(dev); > + pm_runtime_disable(dev); > + pm_runtime_put_noidle(dev); > +} [Severity: Low] Should ma35d1_i2c_pm_cleanup() also call pm_runtime_dont_use_autosuspend(de= v) to pair with pm_runtime_use_autosuspend(dev) in ma35d1_i2c_probe()? [1] https://lore.kernel.org/r/aro-QitaRwK87gdO@zenone.zhora.eu --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130032346.1720= 769-1-zychennvt@gmail.com?part=3D2