From: sashiko-bot@kernel.org
To: "Maxime Ripard" <mripard@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v8 16/39] drm/atomic_sro: Add function to install state into drm objects
Date: Fri, 06 Nov 2026 13:33:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-201477@kernel.org> (raw)
In-Reply-To: <20261106-drm-state-readout-v8-16-cbe78624e1bc@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/atomic_sro: bad private_objs loop bound in
drm_atomic_sro_install_state()
- [Medium] drm/atomic_sro: premature state destruction in
drm_atomic_sro_install_state()
--
commit 9bc3fe0d50e4075338d8a443036b9d7e790c5ea0
Author: Maxime Ripard <mripard@kernel.org>
drm/atomic_sro: Add function to install state into drm objects
This commit adds drm_atomic_sro_install_state() to install readout states
into DRM objects and introduces the optional atomic_sro_install_state hook
for planes, CRTCs, connectors, and private objects.
> diff --git a/drivers/gpu/drm/drm_atomic_state_readout.c b/drivers/gpu/drm/drm_atomic_state_readout.c
> index 07ddc315b13d9..de0f27186bea9 100644
> --- a/drivers/gpu/drm/drm_atomic_state_readout.c
> +++ b/drivers/gpu/drm/drm_atomic_state_readout.c
[ ... ]
> @@ -581,3 +582,145 @@ void drm_atomic_sro_set_private_obj_state(struct drm_atomic_sro_state *state,
> obj_state, state);
> }
> EXPORT_SYMBOL(drm_atomic_sro_set_private_obj_state);
> +
> +/**
> + * drm_atomic_sro_install_state - install readout state into DRM objects
> + * @state: SRO state to install
> + *
> + * Takes a &struct drm_atomic_sro_state built by
> + * &drm_mode_config_helper_funcs.atomic_sro_build_state and installs its
> + * contents as the current state of each DRM object (setting
> + * &drm_crtc.state, &drm_plane.state, &drm_connector.state and
> + * &drm_private_obj.state).
> + *
> + * For each object, the optional atomic_sro_install_state hook is
> + * called before the state pointer is updated, allowing drivers to
> + * perform any needed action.
> + */
> +void drm_atomic_sro_install_state(struct drm_atomic_sro_state *state)
> +{
> + unsigned int i;
> +
> + for (i = 0; i <= state->max_connector_index; i++) {
> + const struct drm_connector_funcs *conn_funcs;
> + struct drm_connector_state *conn_state;
> + struct drm_connector *conn;
> +
> + conn = state->connectors[i].ptr;
> + if (!conn)
> + continue;
> +
> + conn_funcs = conn->funcs;
> + if (!conn_funcs)
> + continue;
> +
> + if (conn->state) {
> + conn_funcs->atomic_destroy_state(conn, conn->state);
> + conn->state = NULL;
> + }
> +
> + conn_state = state->connectors[i].state;
> + if (!conn_state)
> + continue;
> +
> + if (conn_funcs->atomic_sro_install_state)
> + conn_funcs->atomic_sro_install_state(conn, conn_state);
> +
> + conn->state = conn_state;
> + state->connectors[i].state = NULL;
> + state->connectors[i].ptr = NULL;
> + drm_connector_put(conn);
> + }
[Severity: Medium]
Does destroying conn->state (and crtc->state, plane->state, and obj->state
in the loops below) before checking whether the new state pointer in the
SRO container is non-NULL leave the object with a NULL state pointer?
If state->connectors[i].state is NULL, the old state has already been
destroyed and nulled when the loop continues, leaving the KMS object
without a state and causing NULL pointer dereferences in later
atomic_duplicate_state() calls. It also leaves the object's state pointer
NULL while atomic_sro_install_state() runs.
[ ... ]
> + for (i = 0; i < count_private_obj(state->dev); i++) {
> + const struct drm_private_state_funcs *obj_funcs;
> + struct drm_private_state *obj_state;
> + struct drm_private_obj *obj;
> +
> + obj = state->private_objs[i].ptr;
> + if (!obj)
> + continue;
> +
> + obj_funcs = obj->funcs;
> + if (!obj_funcs)
> + continue;
> +
> + if (obj->state) {
> + obj_funcs->atomic_destroy_state(obj, obj->state);
> + obj->state = NULL;
> + }
> +
> + obj_state = state->private_objs[i].state;
> + if (!obj_state)
> + continue;
> +
> + if (obj_funcs->atomic_sro_install_state)
> + obj_funcs->atomic_sro_install_state(obj, obj_state);
> +
> + obj->state = obj_state;
> + state->private_objs[i].state = NULL;
> + state->private_objs[i].ptr = NULL;
> + }
> + state->num_private_objs = 0;
> +}
[Severity: Medium]
Should this loop bound be state->num_private_objs instead of
count_private_obj(state->dev)?
drm_atomic_sro_state_init() allocates state->private_objs for the count at
allocation time, and drm_atomic_sro_set_private_obj_state() populates up to
state->num_private_objs entries. Bounding the loop by
count_private_obj(state->dev) re-walks dev->mode_config.privobj_list on
every iteration, scans unpopulated slots, and reads past the end of
state->private_objs if a private object was added after
drm_atomic_sro_state_alloc(). In addition, zeroing state->num_private_objs
at the end prevents drm_atomic_sro_state_free() from freeing any
obj_state skipped by an early continue.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106-drm-state-readout-v8-0-cbe78624e1bc@kernel.org?part=16
next prev parent reply other threads:[~2026-11-06 13:34 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 13:14 [PATCH v8 00/39] drm: Implement state readout support Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 01/39] drm/ingenic: Convert to devm_drm_bridge_alloc() Maxime Ripard
2026-11-06 13:33 ` sashiko-bot
2026-11-06 13:55 ` Luca Ceresoli
2026-11-06 13:59 ` Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 02/39] drm/bridge-helper: Don't unlock the connection mutex after a backoff Maxime Ripard
2026-11-06 13:39 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 03/39] drm/tests: hdmi-state-helper: Handle EDEADLK in the 420-only test Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 04/39] drm/tests: hdmi-state-helper: Handle EDEADLK in the color format test Maxime Ripard
2026-11-06 13:32 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 05/39] drm/colorop: Export drm_atomic_helper_colorop_create_state() Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 06/39] drm/atomic: Fix private obj error handling Maxime Ripard
2026-11-06 13:29 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 07/39] drm/atomic: Add drm_private_obj name Maxime Ripard
2026-11-06 13:35 ` sashiko-bot
2026-11-19 15:20 ` Luca Ceresoli
2026-11-06 13:14 ` [PATCH v8 08/39] drm/bridge: Switch print_state to use bridge name Maxime Ripard
2026-11-19 15:25 ` Luca Ceresoli
2026-11-06 13:14 ` [PATCH v8 09/39] drm/bridge: Add drm_private_obj_is_bridge() Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 10/39] drm/fb-dma-helper: Handle framebuffers without a GEM object Maxime Ripard
2026-11-06 13:32 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 11/39] drm/gem-atomic-helper: " Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 12/39] drm/atomic: Export drm_atomic_*_print_state Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 13/39] drm/atomic_sro: Create drm_atomic_sro_state container Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 14/39] drm/atomic_sro: Create kernel parameter to force or disable readout Maxime Ripard
2026-11-06 13:31 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 15/39] drm/atomic_sro: Add atomic state readout infrastructure Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 16/39] drm/atomic_sro: Add function to install state into drm objects Maxime Ripard
2026-11-06 13:33 ` sashiko-bot [this message]
2026-11-06 13:14 ` [PATCH v8 17/39] drm/atomic_sro: Create documentation Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 18/39] drm/bridge: Handle bridges with hardware state readout Maxime Ripard
2026-11-06 13:33 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 19/39] drm/mode-config: Read out hardware state in drm_mode_config_create_state Maxime Ripard
2026-11-06 13:33 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 20/39] drm/atomic_sro: Provide helpers to implement hardware state readout Maxime Ripard
2026-11-06 13:44 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 21/39] drm/mode-config: Introduce hw_reset hook Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 22/39] drm/modeset-helper: Add drm_mode_config_helper_hw_reset() Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 23/39] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 24/39] drm/atomic-state-helper: Provide comparison macros Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 25/39] drm/atomic-state-helper: Provide atomic_compare_state helpers Maxime Ripard
2026-11-06 13:44 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 26/39] drm/atomic-helper: Document State Read-Out as a state initialization approach Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 27/39] drm/tests: kunit: Add a drm_printer helper Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 28/39] drm/tests: Add tests for the atomic state readout Maxime Ripard
2026-11-06 13:44 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 29/39] drm/encoder: Create atomic_sro_get_current_crtc hook Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 30/39] drm/bridge: display-connector: Implement readout support Maxime Ripard
2026-11-06 13:50 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 31/39] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 32/39] drm/tidss: crtc: Add atomic_print_state implementation Maxime Ripard
2026-11-17 7:24 ` Tomi Valkeinen
2026-11-06 13:14 ` [PATCH v8 33/39] drm/tidss: dispc: Improve mode checking logs Maxime Ripard
2026-11-17 7:25 ` Tomi Valkeinen
2026-11-06 13:14 ` [PATCH v8 34/39] drm/tidss: Implement hw_reset Maxime Ripard
2026-11-06 13:50 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 35/39] drm/tidss: Implement readout support Maxime Ripard
2026-11-06 14:06 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 36/39] drm/tidss: encoder: Implement atomic_sro_get_current_crtc Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 37/39] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2026-11-06 13:14 ` [PATCH v8 38/39] drm/panel: Implement state readout support Maxime Ripard
2026-11-06 13:45 ` sashiko-bot
2026-11-06 13:14 ` [PATCH v8 39/39] fixup! drm/tidss: Implement " Maxime Ripard
2026-11-06 13:57 ` sashiko-bot
2026-11-17 15:17 ` [PATCH v8 00/39] drm: Implement state " Tomi Valkeinen
2026-11-18 12:37 ` Tomi Valkeinen
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-201477@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=mripard@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