Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cyril Hrubis" <chrubis@suse.cz>,
	dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels
Date: Sun, 06 Dec 2026 13:35:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-252450@kernel.org> (raw)
In-Reply-To: <20261206131330.1754178-3-chrubis@suse.cz>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Critical] drm/sitronix: heap overflow in st75256_fb_blit() on
  fractional src coords
- [High] drm/sitronix: double offset OOB read and raw vmap memcpy in
  st75256_fb_blit()
- [Medium] drm/sitronix: unsafe memcpy() on vmap->vaddr in
  st75256_fb_blit()
- [Medium] drm/sitronix: partial damage clips after CRTC enable leave
  screen blank
- [Medium] drm/sitronix: inconsistent hardware state after
  st75256_hw_init() failure
- [Medium] drm/sitronix: drm_dev_enter() blocks
  st75256_crtc_atomic_disable() on remove
--

commit 0a4d4758a47b4e9c1bc202d6013889ca0bafb0a1
Author: Cyril Hrubis <metan@ucw.cz>

drm/sitronix: Add driver for Sitronix ST75256 LCD panels

This commit adds a DRM driver for Sitronix ST75256 monochrome and
4-level grayscale SPI LCD panels, supporting R1, R2, and XRGB8888
framebuffers with damaged-area updates.

> diff --git a/drivers/gpu/drm/sitronix/st75256.c b/drivers/gpu/drm/sitronix/st75256.c
> new file mode 100644
> index 0000000000000..4a931208cec52
> --- /dev/null
> +++ b/drivers/gpu/drm/sitronix/st75256.c

[ ... ]

> +static int st75256_hw_init(struct st75256_device *st75256)
> +{

[ ... ]

> +	st75256_cmd(st75256, &err, ST75256_DISP_MODE, ST75256_MODE_GRAY);
> +	/* Clock divider, duty, line inversion */
> +	st75256_cmd(st75256, &err, ST75256_DISP_CTRL, 0x00, panel->width - 1, 0x01);
> +	if (err)
> +		return err;
> +
> +	st75256->hw_mode = ST75256_MODE_GRAY;
> +
> +	err = st75256_clear(st75256);
> +
> +	st75256_cmd(st75256, &err, ST75256_DISP_ON);
> +
> +	return err;
> +}

[Severity: Medium]
Can an SPI error during st75256_hw_init() leave the controller in an
inconsistent state for subsequent plane updates?

Early error returns leave reset deasserted, potentially with the internal
booster enabled and ST75256_EXT2 still selected while st75256->hw_mode stays
0.  Because st75256_crtc_atomic_enable() returns void,
st75256_plane_atomic_update() still runs, sees mode != st75256->hw_mode, and
sends opcode 0xf0 without selecting ST75256_EXT1 (which is
ST75256_FRAME_RATE in EXT2 instead of ST75256_DISP_MODE).

In addition, st75256->hw_mode is set to ST75256_MODE_GRAY before
st75256_clear() and ST75256_DISP_ON succeed.  Asserting reset on error,
updating hw_mode only after init succeeds, and bailing out of
st75256_plane_atomic_update() when hw_mode is 0 would keep the state
consistent.

[ ... ]

> +static int st75256_fb_blit(struct st75256_device *st75256,
> +			   struct drm_framebuffer *fb,
> +			   const struct iosys_map *vmap,
> +			   const struct drm_plane_state *state,
> +			   const struct drm_rect *damage,
> +			   struct drm_format_conv_state *fmtcnv_state)
> +{
> +	unsigned int ppb = st75256->hw_mode == ST75256_MODE_MONO ? 8 : 4;
> +	int src_x = state->src.x1 >> 16;
> +	int src_y = state->src.y1 >> 16;
> +	struct drm_rect dst = *damage;
> +	unsigned int row_len;
> +	u8 *tx = st75256->tx_buf;
> +	int y;
> +
> +	/* Framebuffer to display coordinates, aligned to whole bytes */
> +	drm_rect_translate(&dst, -src_x, -src_y);
> +	dst.x1 = round_down(dst.x1, ppb);
> +	dst.x2 = min_t(int, round_up(dst.x2, ppb), st75256->panel.width);
> +	row_len = drm_rect_width(&dst) / ppb;

[Severity: Critical]
Can fractional 16.16 source coordinates overflow st75256->tx_buf here?

st75256_plane_atomic_check() does not reject fractional bits in src.x1 or
src.y1.  When a framebuffer taller than the panel is committed with a
fractional src.y1, drm_atomic_helper_damage_iter_init() rounds plane_src.y1
down and plane_src.y2 up, producing a damage height of panel->height + 1.

Because dst.y2 is not clamped to st75256->panel.height, the row loop runs
panel->height + 1 times and writes panel->width / 4 bytes past the end of
st75256->tx_buf in 2bpp grayscale mode.

On a 256-pixel-tall panel this also truncates y2 - 1 (256) to 0 in
ST75256_SET_COL_ADDR.  Similarly, a damage clip on the trailing fractional
column clamps dst.x1 == dst.x2 == panel->width without returning early,
sending inverted out-of-range page bounds to ST75256_SET_PAGE_ADDR.

[ ... ]

> +	} else {
> +		const u8 *src = (const u8 *)vmap->vaddr + fb->offsets[0] +
> +				(dst.x1 + src_x) / ppb;

[Severity: High]
Does adding fb->offsets[0] here cause an out-of-bounds read for R1 and R2
framebuffers with a non-zero offset?

st75256_plane_atomic_update() passes &shadow_state->data[0] as vmap, which
already had fb->offsets[0] applied by drm_gem_fb_vmap() during
begin_fb_access.  Adding fb->offsets[0] a second time shifts the read by
2 * fb->offsets[0], reading up to fb->offsets[0] bytes past the end of the
mapped GEM buffer and corrupting display output or faulting on a guard page.

> +
> +		for (y = dst.y1; y < dst.y2; y++) {
> +			memcpy(tx, src + (y + src_y) * fb->pitches[0], row_len);
> +			tx += row_len;
> +		}
> +	}

[Severity: Medium]
Is it safe to dereference vmap->vaddr directly with memcpy() here instead of
using iosys_map_memcpy_from()?

DRM_GEM_SHMEM_DRIVER_OPS enables PRIME dma-buf import, and
drm_gem_shmem_vmap_locked() maps imported buffers via dma_buf_vmap(), which
can return an iosys_map with is_iomem set.  Using plain memcpy() on I/O
memory can cause alignment or bus faults on architectures such as arm64.

[ ... ]

> +	mode = fb->format->format == DRM_FORMAT_R1 ?
> +	       ST75256_MODE_MONO : ST75256_MODE_GRAY;
> +
> +	if (mode != st75256->hw_mode) {
> +		ret = st75256_set_mode(st75256, mode);
> +		if (ret)
> +			goto err;
> +		/* Display RAM layout changed, repaint everything */
> +		drm_rect_fp_to_int(&damage, &new_state->src);
> +	} else if (!drm_atomic_helper_damage_merged(old_state, new_state, &damage)) {
> +		goto out;
> +	}

[Severity: Medium]
Can partial FB_DAMAGE_CLIPS after a CRTC enable or modeset leave the rest of
the panel blank?

st75256_crtc_atomic_enable() runs before st75256_plane_atomic_update() and
calls st75256_hw_init(), which clears display RAM and sets hw_mode to
ST75256_MODE_GRAY.  When the plane uses XRGB8888 or R2 with unchanged src
and partial damage clips, mode already matches hw_mode and
drm_atomic_helper_damage_merged() only blits the damaged sub-rectangle onto
the cleared RAM.

Setting new_state->ignore_damage_clips = true in
st75256_plane_atomic_check() when drm_atomic_crtc_needs_modeset(crtc_state)
is true would force a full repaint.

[ ... ]

> +static void st75256_remove(struct spi_device *spi)
> +{
> +	struct st75256_device *st75256 = spi_get_drvdata(spi);
> +
> +	drm_dev_unplug(&st75256->drm);
> +	drm_atomic_helper_shutdown(&st75256->drm);
> +}

[Severity: Medium]
Does calling drm_dev_unplug() before drm_atomic_helper_shutdown() prevent
st75256_crtc_atomic_disable() from powering down the panel on unload?

drm_dev_unplug() sets dev->unplugged = true, so the drm_dev_enter() check in
st75256_crtc_atomic_disable() always returns false during
drm_atomic_helper_shutdown().  As a result, backlight_disable() and
st75256_hw_fini() are skipped on module unload or sysfs unbind, leaving the
panel, its internal booster, and the backlight powered on.

Sibling SPI drivers such as st7586 omit drm_dev_enter()/drm_dev_exit() in
their atomic_disable callback so regular driver unload turns off the display.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206131330.1754178-1-chrubis@suse.cz?part=2

      reply	other threads:[~2026-12-06 13:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 13:13 [PATCH v1 0/2] Add support for Sitronix ST75256 LCD panels Cyril Hrubis
2026-12-06 13:13 ` [PATCH v1 1/2] dt-bindings: display: sitronix,st75256: Add DT schema Cyril Hrubis
2026-12-06 13:29   ` sashiko-bot
2026-12-06 13:13 ` [PATCH v1 2/2] drm/sitronix: Add driver for Sitronix ST75256 LCD panels Cyril Hrubis
2026-12-06 13:35   ` 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-252450@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chrubis@suse.cz \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.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