From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796007704; b=g6Dl9Gfad5W5HEwoZpQ4KQOqcEmkH7cbTHc8zx4IQtnIm3d0PoifdQx/r81dvShntdgl WvBr9YrulUtUCChqC1/Rcv8QfuuhweE8sj76ZJb6wpjGcC9l54LYIAbVdYYSdOxsFyOvC 2EG86+z+INBceRGX0FDv+9w6/TFOfbtksdTBSWTre0mJQPfbeXF+TcgRk8aTiXmiqRk+S BBM13n4XUmQnUIohniL7HGLjYL6XRmkljXGrfzFAr/xYd6OSt3X7ypffXjeExlLfbDlPh Zpb51hnfemiN03r1+K5fIugi2lC6J67UmibI3siL8/h9Tsy9OnfeoMvTXXMoobx0jpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796007704; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=QXcvzgYycmAdadKciZbymuyVoVW6DB0DNo43JNIl0G4=; b=2X0lRRPZX0GxP9jsJ+WZjQwQn8JizH5riX/2eQxOLdCM/G8NsQcQgCxNjEvfynEtXxzX ksS3XwgizoQVNiEdKMhO1PriPOVhyBQDhkoLtLfCfAM/6O5xQ62+KUl4e14QDjDCSCyDL p9GgYGwYdwXYHl3gASR5E6arMEgjiw8pazHLxowtKeUan60wbbVvsaJ3RnUrRDhk8caUq uAinZtwPPgAgPwpJfVxolym2ed2AJ8KIy5Tly6nYlMK1agBmRJmO6pbq9mZCIcTuoy+r+ TcLZVzrTjJMqv2WgzTcoBHoG0T0l9Hignp+8zKpVvStv2cte9A24SHwjrDt3oj8lRLA== 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=OeSPIePS; 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 0D049606A31D for ; Mon, 30 Nov 2026 03:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OeSPIePS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A2951F00896; Mon, 30 Nov 2026 03:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796007703; bh=QXcvzgYycmAdadKciZbymuyVoVW6DB0DNo43JNIl0G4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=OeSPIePSFEaa+vEVyuZJgmAdl082Pt6ugsDaheygX5ekFhGnEtcEEWXX76mlkJ8GG DVIE96o6puIHAaXgXEhgbNNekGKrK/c/nZX/I6Cisgli+e57F8onvFZG5zhioekqdz OkLswq0qFpydW730HUEIcGhH4htGiT7R33kUjUz4aC26pYuKGpCWKhCW2Wb8UQlspI wZ7lGklz/T3Y+Cqt255wXc8ZGqqrg16FZ1KhmSVi1xt1GknOOSsui4N6/WPvkM6YTf zXTJBsFQAOuEqkDA24h3vH89N6m6msiCnN9SRRJ0xEY422EUdTmMuuRVgyHNJkIwPR zeAlixMO7aalA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 2/5] spi: dw-g2: Add support for Synopsys DWC SSI v2.02a controller Reply-To: sashiko-reviews@lists.linux.dev To: "Prakriti Sharma" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <8c1c5762858dd88b23e4b73dd28913f495ff7580.1795683279.git.prakriti@synopsys.com> References: <8c1c5762858dd88b23e4b73dd28913f495ff7580.1795683279.git.prakriti@synopsys.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 03:01:42 +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 7 potential issues to consider: - [High] spi: dw-g2: premature transfer abort in dw_spi_g2_cmd_only() and wait_idle() - [High] spi: dw-g2: missing ctlr->handle_err leaves IRQ transfer active on timeout - [High] spi: dw-g2: unlocked concurrent execution of dw_spi_g2_irq() across IRQs - [Medium] spi: dw-g2: missing SPI_CPOL and SPI_CPHA setup in dw_spi_g2_build_ctrlr0() - [Medium] spi: dw-g2: missing ctlr->max_speed_hz setup in dw_spi_g2_init() - [Medium] spi: dw-g2: missing ctlr->max_speed_hz and clobbered caps in dw_spi_g2_init() - [Low] spi: dw-g2: redundant TXEI interrupt on short transfers in dw_spi_g2_transfer_one() -- commit 164e383f9dc370e3fcd8dcc242bc57e332d6ec75 Author: Prakriti Sharma spi: dw-g2: Add support for Synopsys DWC SSI v2.02a controller This commit introduces a platform driver for the Synopsys DesignWare SSI Gen2 (v2.02a) MMIO SPI controller with interrupt-driven standard transfers and spi-mem command-only and short register operations. > diff --git a/drivers/spi/spi-dw-g2-core.c b/drivers/spi/spi-dw-g2-core.c > new file mode 100644 > index 0000000000000..b2a3e3e8670eb > --- /dev/null > +++ b/drivers/spi/spi-dw-g2-core.c > @@ -0,0 +1,925 @@ [ ... ] > +static u32 dw_spi_g2_build_ctrlr0(struct dw_spi_g2 *dws, u8 tmod, u8 frf) > +{ [ ... ] > + ctrlr0 |=3D > + FIELD_PREP(DW_SPI_G2_CTRLR0_DFS_MASK, DW_SPI_G2_DFS_ENCODE(dfs)); > + ctrlr0 |=3D FIELD_PREP(DW_SPI_G2_CTRLR0_TMOD_MASK, tmod); > + ctrlr0 |=3D FIELD_PREP(DW_SPI_G2_CTRLR0_FRF_MASK, frf); > + > + return ctrlr0; > +} [Severity: Medium] Should dw_spi_g2_build_ctrlr0() also encode DW_SPI_G2_CTRLR0_SCPOL and DW_SPI_G2_CTRLR0_SCPHA from dws->curr_spi->mode? dw_spi_g2_transfer_one() ORs those bits in after calling dw_spi_g2_build_ctrlr0(), but dw_spi_g2_cmd_only_setup() and dw_spi_g2_reg_op_setup() write the return value directly to DW_SPI_G2_CTRLR0(dws->cs). Any spi-mem flash device configured for SPI Mode 1, 2, or 3 will have its transactions clocked in Mode 0. [ ... ] > +static int dw_spi_g2_cmd_only(struct dw_spi_g2 *dws, > + const struct spi_mem_op *op) > +{ [ ... ] > + for (i =3D 0; i < len; i++) > + dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, buf[i]); > + > + dw_spi_g2_cs_assert(dws, dws->cs); > + ret =3D dw_spi_g2_wait_idle(dws); > + > + dw_spi_g2_transfer_end(dws); > + dw_spi_g2_controller_reset(dws); > + > + return ret; > +} [Severity: High] Can dw_spi_g2_wait_idle() return before the TX FIFO starts shifting out, causing dw_spi_g2_transfer_end() to abort the command? dw_spi_g2_wait_idle() only checks !(sr & DW_SPI_G2_SR_BUSY): drivers/spi/spi-dw-g2.h:dw_spi_g2_wait_idle() { u32 sr; return readl_poll_timeout(dws->regs + DW_SPI_G2_SR, sr, !(sr & DW_SPI_G2_SR_BUSY), 1, DW_SPI_G2_TIMEOUT_US); } As the comment in dw_spi_g2_reg_op() notes for the same prefill and CS assertion pattern, polling only !DW_SPI_G2_SR_BUSY without DW_SPI_G2_SR_TFE can return early before DW_SPI_G2_SER propagates into the ssi_clk domain. When that happens in dw_spi_g2_cmd_only() or dw_spi_g2_xfer_fifo(), disabling SSIENR and deasserting CS flushes the queued bytes from the TX FIFO and drops the SPI command. [ ... ] > +static int dw_spi_g2_transfer_one(struct spi_controller *ctlr, > + struct spi_device *spi, > + struct spi_transfer *xfer) > +{ [ ... ] > + dw_spi_g2_writel(dws->regs, DW_SPI_G2_CTRLR0(dws->cs), ctrlr0); > + dw_spi_g2_writel(dws->regs, DW_SPI_G2_CTRLR1(dws->cs), 0); > + dw_spi_g2_writel(dws->regs, DW_SPI_G2_SPI_CTRLR0(dws->cs), 0); > + dw_spi_g2_writel(dws->regs, DW_SPI_G2_BAUDR(dws->cs), > + dw_spi_g2_baudr(dws, xfer->speed_hz)); [Severity: Medium] Can xfer->speed_hz be 0 here when a device relies on the controller's default maximum speed? Because dw_spi_g2_init() does not set ctlr->max_speed_hz =3D dws->max_freq, the SPI core leaves spi->max_speed_hz and xfer->speed_hz at 0 when a peripheral does not specify a maximum frequency (and does not clamp higher speeds to dws->max_freq). dw_spi_g2_baudr(dws, 0) then returns DW_SPI_G2_MAX_BAUDR (65534), dropping the bus clock to its slowest possible divider instead of dws->max_freq. In addition, dw_spi_g2_mmio_probe() calls of_alias_get_id(pdev->dev.of_node, "spi"), which is undocumented in the DT binding and already handled by spi_register_controller(). > + > + dw_spi_g2_target_enable(dws, dws->cs); > + dw_spi_g2_enable(dws, true); > + > + /* Ensure irq_xfer is visible before unmasking TXEI/RXFI. */ > + smp_wmb(); > + dws->irq_xfer =3D true; > + > + dw_spi_g2_irq_xfer_setup(dws); > + dw_spi_g2_irq_writer(dws); > + dw_spi_g2_umask_intr(dws, DW_SPI_G2_IMR_XFER_ERR); [Severity: Low] Does unmasking DW_SPI_G2_ISR_TXEI unconditionally after dw_spi_g2_irq_writer() trigger an extra interrupt on every transfer that fits in the TX FIFO? When xfer->len <=3D dws->fifo_len, dw_spi_g2_irq_writer() pushes the entire transfer into the TX FIFO and decrements dws->irq_tx_rem to 0 before interrupts are unmasked. Unmasking DW_SPI_G2_ISR_TXEI anyway causes a TXEI interrupt to fire only for dw_spi_g2_irq() to see !dws->irq_tx_rem and mask DW_SPI_G2_ISR_TXEI. [ ... ] > +int dw_spi_g2_init(struct dw_spi_g2 *dws) > +{ [ ... ] > + dws->fifo_len =3D dw_spi_g2_detect_fifo_len(dws); > + dws->caps =3D 0; > + > + if (!dws->max_freq) > + dws->max_freq =3D DW_SPI_G2_DEF_MAX_FREQ; [Severity: Medium] Does dw_spi_g2_init() clobber dws->caps and leave ctlr->max_speed_hz unset? dw_spi_g2_mmio_probe() reads DW_SPI_G2_HW_CAPABILITIES into dws->caps =3D dws->hw_caps and programs DW_SPI_G2_DEDICATED_CS_EN right before calling dw_spi_g2_init(), which zeroes both DW_SPI_G2_DEDICATED_CS_EN and dws->caps. Also, ctlr->max_speed_hz is never initialized from dws->max_freq, so transfers without an explicit speed fall back to dw_spi_g2_baudr(dws, 0) (DW_SPI_G2_MAX_BAUDR) in dw_spi_g2_transfer_one() and override the baud rate programmed by dw_spi_g2_setup(). > + > + ctlr->mode_bits =3D SPI_CPOL | SPI_CPHA | > + SPI_TX_DUAL | SPI_RX_DUAL | > + SPI_TX_QUAD | SPI_RX_QUAD | SPI_TX_OCTAL | SPI_RX_OCTAL; > + > + ctlr->bits_per_word_mask =3D SPI_BPW_MASK(8); > + ctlr->flags =3D 0; > + > + ctlr->setup =3D dw_spi_g2_setup; > + ctlr->set_cs =3D dw_spi_g2_set_cs; > + ctlr->transfer_one =3D dw_spi_g2_transfer_one; > + ctlr->mem_ops =3D &dw_spi_g2_mem_ops; [Severity: High] What stops the in-flight IRQ transfer if spi_transfer_wait() times out? Without a ctlr->handle_err callback to mask interrupts, clear dws->irq_xfer, and disable the controller, a timed-out message is finalized by the SPI core while DW_SPI_G2_IMR_XFER_ERR remains unmasked and dws->irq_tx / dws->irq_rx still point to the caller's transfer buffers: CPU0 CPU1 spi_transfer_one_message() dw_spi_g2_transfer_one() dws->irq_rx =3D xfer->rx_buf dws->irq_xfer =3D true dw_spi_g2_umask_intr(...) spi_transfer_wait() -> -ETIMEDOUT spi_finalize_current_message() /* caller frees xfer->rx_buf */ dw_spi_g2_irq() dw_spi_g2_irq_reader() dws->irq_rx[idx] =3D val <-- use-aft= er-free In addition, if a threshold interrupt fires in dw_spi_g2_irq() while !dws->irq_xfer, returning IRQ_NONE without masking DW_SPI_G2_IMR leaves the level-triggered interrupt asserted. > diff --git a/drivers/spi/spi-dw-g2-mmio.c b/drivers/spi/spi-dw-g2-mmio.c > new file mode 100644 > index 0000000000000..1be68c4250e67 > --- /dev/null > +++ b/drivers/spi/spi-dw-g2-mmio.c > @@ -0,0 +1,168 @@ [ ... ] > + static const char * const irq_names[] =3D { > + "rxf", "txe", "txaf", "wsf", > + }; > + bool any_named =3D false; > + > + for (i =3D 0; i < ARRAY_SIZE(irq_names); i++) { > + irq =3D platform_get_irq_byname_optional(pdev, irq_names[i]); > + if (irq < 0) > + continue; > + > + ret =3D devm_request_irq(dev, irq, dw_spi_g2_irq, 0, > + dev_name(dev), dws); [Severity: High] When the platform wires separate IRQ lines for "rxf" and "txe", can dw_spi_g2_irq() run concurrently on two CPUs without locking? Distinct IRQ numbers are not serialized against each other, and dw_spi_g2_transfer_one() unmasks both DW_SPI_G2_ISR_RXFI and DW_SPI_G2_ISR_TXEI: CPU0 (IRQ "rxf") CPU1 (IRQ "txe") dw_spi_g2_irq() dw_spi_g2_irq() dw_spi_g2_irq_reader() dw_spi_g2_irq_reader() max =3D dw_spi_g2_irq_rx_max() max =3D dw_spi_g2_irq_rx_max() idx =3D irq_len - irq_rx_rem idx =3D irq_len - irq_rx_rem readl(DW_SPI_G2_DR0) readl(DW_SPI_G2_DR0) irq_rx[idx] =3D val irq_rx[idx] =3D val irq_rx_rem-- irq_rx_rem-- <-- u32 underflow / OOB= write Both handlers also race on dw_spi_g2_irq_writer(), read-modify-write updates to DW_SPI_G2_IMR, and dw_spi_g2_irq_finalize(), and if the first CPU drains the FIFO before the second CPU reads DW_SPI_G2_ISR, the second handler sees isr =3D=3D 0 and returns IRQ_NONE. Also, in dw_spi_g2_transfer_one(), smp_wmb() is placed before dws->irq_xfer =3D true rather than between dws->irq_xfer =3D true and dw_spi_g2_umask_intr(), and "if (irq < 0) continue;" here silently drops -EPROBE_DEFER from platform_get_irq_byname_optional(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1795683279.gi= t.prakriti@synopsys.com?part=3D2