From: sashiko-bot@kernel.org
To: "Antoni Pokusinski" <apokusinski01@gmail.com>
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v3 3/3] i2c: omap: add DMA support
Date: Fri, 20 Nov 2026 19:55:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-225981@kernel.org> (raw)
In-Reply-To: <20261120185915.150228-4-apokusinski01@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] i2c: omap: u8 truncation in omap_i2c_resize_fifo() breaks DMA
threshold
- [Medium] i2c: omap: DMA request disabled after buffer unmap in
omap_i2c_xfer_msg()
- [Medium] i2c: omap: ERR_PTR assigned to omap->dma after IRQ init in
omap_i2c_probe()
- [Medium] i2c: omap: missing PIO fallback on DMA failure in
omap_i2c_xfer_msg()
- [Low] i2c: omap: invalid kernel-doc comment prefix in
omap_i2c_xfer_msg()
--
commit 7c0a49ff7dadae86047390fd06ce1307e0609c76
Author: Antoni Pokusinski <apokusinski01@gmail.com>
i2c: omap: add DMA support
This commit adds TX and RX DMA support to the OMAP I2C controller for
messages whose length is at least 8 bytes and a multiple of the FIFO
threshold.
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index f02d294db42a6..650d1cce05c75 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
[ ... ]
> @@ -663,8 +861,8 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
> {
> struct omap_i2c_dev *omap = i2c_get_adapdata(adap);
> unsigned long time_left;
> - u16 w;
> - int ret;
> + u16 w, pio_irq_mask;
> + int ret, use_dma;
>
> dev_dbg(omap->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
> msg->addr, msg->len, msg->flags, stop);
>
> omap->receiver = !!(msg->flags & I2C_M_RD);
> omap_i2c_resize_fifo(omap, msg->len, omap->receiver);
>
> + /**
> + * REVISIT: If the message size is not a multiple of the threshold,
> + * the draining feature must be used.
> + */
[Severity: Low]
This internal comment uses the "/**" kernel-doc prefix, which causes a
W=1 kernel-doc build warning.
> + use_dma = !polling && omap->dma && msg->len >= OMAP_I2C_DMA_THRESHOLD &&
> + !(omap->flags & OMAP_I2C_FLAG_NO_FIFO) &&
> + msg->len % omap->threshold == 0;
[Severity: Medium]
Does passing the 16-bit msg->len into omap_i2c_resize_fifo() truncate
lengths >= 256 bytes and corrupt omap->threshold for DMA?
drivers/i2c/busses/i2c-omap.c:omap_i2c_resize_fifo() {
...
static void omap_i2c_resize_fifo(struct omap_i2c_dev *omap, u8 size, bool is_rx)
{
...
omap->threshold = clamp(size, (u8) 1, omap->fifo_size);
}
For a 256-byte transfer (such as an EEPROM page read or write), size
wraps to 0 and omap->threshold is clamped to 1 instead of
omap->fifo_size. Because 256 % 1 == 0, use_dma is true and
omap_i2c_dma_xfer() programs src_maxburst or dst_maxburst to 1 byte for
the entire transfer. Changing size in omap_i2c_resize_fifo() to u16 (and
widening the clamp types) would avoid the truncation.
>
> omap_i2c_write_reg(omap, OMAP_I2C_SA_REG, msg->addr);
>
> /* REVISIT: Could the STB bit of I2C_CON be used with probing? */
> @@ -692,6 +898,23 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
> reinit_completion(&omap->cmd_complete);
> omap->cmd_err = 0;
>
> + if (use_dma) {
> + ret = omap_i2c_dma_xfer(omap, msg);
> + if (ret) {
> + omap_i2c_reset(omap);
> + __omap_i2c_init(omap);
> + return ret;
> + }
> +
> + omap_i2c_dma_enable_req(omap);
> + } else {
> + pio_irq_mask = OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
> + ((omap->fifo_size) ? (OMAP_I2C_IE_RDR |
> + OMAP_I2C_IE_XDR) : 0);
> +
> + omap_i2c_enable_pio_irqs(omap, pio_irq_mask);
> + }
[Severity: Medium]
Should omap_i2c_xfer_msg() fall back to PIO when omap_i2c_dma_xfer()
fails instead of resetting the controller and aborting the transfer?
Nothing has been started on the bus for this message yet, and in a
multi-message transfer where an earlier message completed with stop == 0
(repeated start), calling omap_i2c_reset() here resets the controller
mid-transaction while the bus is still held active without sending a STOP
condition.
[ ... ]
> @@ -753,7 +994,18 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
> time_left = !ret;
> }
>
> - if (time_left == 0) {
> + if (use_dma) {
> + if (!time_left || omap->cmd_err)
> + dmaengine_terminate_sync(omap->dma->chan_using);
> +
> + omap_i2c_dma_cleanup(omap, time_left && !omap->cmd_err);
> +
> + omap_i2c_dma_disable_req(omap);
> + } else {
> + omap_i2c_disable_pio_irqs(omap, pio_irq_mask);
> + }
[Severity: Medium]
Should omap_i2c_dma_disable_req() be called before
dmaengine_terminate_sync() and omap_i2c_dma_cleanup(), matching the
start-condition timeout path earlier in omap_i2c_xfer_msg()? On a
timeout or bus error, the I2C controller can keep asserting DMA requests
while the channel is being terminated and the buffer is unmapped.
[ ... ]
> @@ -1478,6 +1787,22 @@ omap_i2c_probe(struct platform_device *pdev)
> goto err_unuse_clocks;
> }
>
> + if (omap->scheme != OMAP_I2C_SCHEME_0) {
> + omap->dma = omap_i2c_dma_init(omap, (dma_addr_t)res->start);
> + if (PTR_ERR(omap->dma) == -EPROBE_DEFER) {
> + r = -EPROBE_DEFER;
> + dev_err_probe(&pdev->dev, r,
> + "can't get DMA channels\n");
> + goto err_unuse_clocks;
> + } else if (PTR_ERR(omap->dma) == -ENODEV) {
> + dev_dbg(omap->dev, "DMA setup failed\n");
> + omap->dma = NULL;
> + } else if (IS_ERR(omap->dma)) {
> + r = PTR_ERR(omap->dma);
> + goto err_unuse_clocks;
> + }
> + }
[Severity: Medium]
Can assigning the return value of omap_i2c_dma_init() directly to
omap->dma cause the IRQ handler to dereference an ERR_PTR?
At this point in omap_i2c_probe(), omap_i2c_init() has enabled the
controller interrupts and devm_request_threaded_irq() has registered
omap_i2c_isr_thread(). If omap_i2c_dma_init() returns an ERR_PTR,
omap->dma is non-NULL (and remains an ERR_PTR on the err_unuse_clocks
unwind path), while omap_i2c_complete_cmd() and omap_i2c_xfer_data()
only check if (omap->dma) before calling complete(&omap->dma->complete).
In addition, omap_i2c_dma_init() already calls dev_err_probe() on
-EPROBE_DEFER, so calling dev_err_probe() again here overwrites the
channel-specific deferred probe reason. Also, since DMA is optional,
should errors other than -EPROBE_DEFER fall back to PIO with
omap->dma = NULL instead of failing the adapter probe?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120185915.150228-1-apokusinski01@gmail.com?part=3
prev parent reply other threads:[~2026-11-20 19:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 18:59 [PATCH v3 0/3] i2c: omap: add support for DMA Antoni Pokusinski
2026-11-20 18:59 ` [PATCH v3 1/3] dt-bindings: i2c: ti,omap4-i2c: Add DMA properties Antoni Pokusinski
2026-11-20 18:59 ` [PATCH v3 2/3] ARM: dts: am33xx-l4: Add missing DMAs for I2C controllers Antoni Pokusinski
2026-11-20 18:59 ` [PATCH v3 3/3] i2c: omap: add DMA support Antoni Pokusinski
2026-11-20 19:55 ` sashiko-bot [this message]
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=sashiko-outbox-225981@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=apokusinski01@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=media-ci@linuxtv.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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