All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: dri-devel@lists.freedesktop.org,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:KERNEL HARDENING (not covered by other
	areas):Keyword:b__counted_by(_le|_be)?b"
	<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] drm: dp_tunnel: use kzalloc_flex
Date: Tue, 10 Mar 2026 10:12:26 +0200	[thread overview]
Message-ID: <aa_SahEg_NzB_PJN@intel.com> (raw)
In-Reply-To: <20260308211220.33759-1-rosenp@gmail.com>

On Sun, Mar 08, 2026 at 02:12:20PM -0700, Rosen Penev wrote:
> Simplifies allocation by using a flexible array member to remove a
> second kzalloc.
> 
> Added __counted_by for extra runtime analysis.
> 
> Simplify assignment loop. It always returns true. That is,
> max_group_count is always equal to group_count.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/gpu/drm/display/drm_dp_tunnel.c | 26 ++++++-------------------
>  1 file changed, 6 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/gpu/drm/display/drm_dp_tunnel.c b/drivers/gpu/drm/display/drm_dp_tunnel.c
> index f442430d8de7..aad1605b956e 100644
> --- a/drivers/gpu/drm/display/drm_dp_tunnel.c
> +++ b/drivers/gpu/drm/display/drm_dp_tunnel.c
> @@ -188,13 +188,13 @@ struct drm_dp_tunnel_group {
>  struct drm_dp_tunnel_mgr {
>  	struct drm_device *dev;
>  
> -	int group_count;
> -	struct drm_dp_tunnel_group *groups;
>  	wait_queue_head_t bw_req_queue;
>  
>  #ifdef CONFIG_DRM_DISPLAY_DP_TUNNEL_STATE_DEBUG
>  	struct ref_tracker_dir ref_tracker;
>  #endif
> +	int group_count;
> +	struct drm_dp_tunnel_group groups[] __counted_by(group_count);
>  };
>  
>  /*
> @@ -1893,7 +1893,6 @@ static void destroy_mgr(struct drm_dp_tunnel_mgr *mgr)
>  	ref_tracker_dir_exit(&mgr->ref_tracker);
>  #endif
>  
> -	kfree(mgr->groups);
>  	kfree(mgr);
>  }
>  
> @@ -1913,33 +1912,20 @@ drm_dp_tunnel_mgr_create(struct drm_device *dev, int max_group_count)
>  	struct drm_dp_tunnel_mgr *mgr;
>  	int i;
>  
> -	mgr = kzalloc_obj(*mgr);
> +	mgr = kzalloc_flex(*mgr, groups, max_group_count);
>  	if (!mgr)
>  		return ERR_PTR(-ENOMEM);
>  
> +	mgr->group_count = max_group_count;
>  	mgr->dev = dev;
>  	init_waitqueue_head(&mgr->bw_req_queue);
>  
> -	mgr->groups = kzalloc_objs(*mgr->groups, max_group_count);
> -	if (!mgr->groups) {
> -		kfree(mgr);
> -
> -		return ERR_PTR(-ENOMEM);
> -	}
> -
>  #ifdef CONFIG_DRM_DISPLAY_DP_TUNNEL_STATE_DEBUG
>  	ref_tracker_dir_init(&mgr->ref_tracker, 16, "drm_dptun");
>  #endif
>  
> -	for (i = 0; i < max_group_count; i++) {
> -		if (!init_group(mgr, &mgr->groups[i])) {
> -			destroy_mgr(mgr);
> -
> -			return ERR_PTR(-ENOMEM);
> -		}
> -
> -		mgr->group_count++;
> -	}
> +	for (i = 0; i < max_group_count; i++)
> +		init_group(mgr, &mgr->groups[i]);

This breaks the error handling.

Hmm, actually it looks like it already got broken by commit
8e6da25bd60d ("drm/dp_tunnel: Switch private_obj initialization
to atomic_create_state")...

>  
>  	return mgr;
>  }
> -- 
> 2.53.0

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2026-03-10  8:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-08 21:12 [PATCH] drm: dp_tunnel: use kzalloc_flex Rosen Penev
2026-03-10  8:12 ` Ville Syrjälä [this message]
2026-03-10 22:09   ` Rosen Penev
2026-03-16 16:44     ` Ville Syrjälä

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=aa_SahEg_NzB_PJN@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=rosenp@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.