public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jyri Sarha <jyri.sarha@iki.fi>
To: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Cc: tomba@kernel.org, airlied@linux.ie, daniel@ffwll.ch,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator
Date: Mon, 28 Mar 2022 01:13:21 +0300	[thread overview]
Message-ID: <eadea5bbb40c168ee1bbf955c10979cb@iki.fi> (raw)
In-Reply-To: <20220327061516.5076-1-xiam0nd.tong@gmail.com>

On 2022-03-27 9:15, Xiaomeng Tong wrote:
> The bug is here:
> 	if (!encoder) {
> 
> The list iterator value 'encoder' will *always* be set and non-NULL
> by list_for_each_entry(), so it is incorrect to assume that the
> iterator value will be NULL if the list is empty or no element
> is found.
> 
> To fix the bug, use a new variable 'iter' as the list iterator,
> while use the original variable 'encoder' as a dedicated pointer
> to point to the found element.
> 
> Cc: stable@vger.kernel.org
> Fixes: ec9eab097a500 ("drm/tilcdc: Add drm bridge support for
> attaching drm bridge drivers")
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>

Thanks for the patch. Good catch.

Reviewed-by: Jyri Sarha <jyri.sarha@iki.fi>
Tested-by: Jyri Sarha <jyri.sarha@iki.fi>

I'll apply this to drm-misc-next in couple of days.

Best regards,
Jyri

> ---
>  drivers/gpu/drm/tilcdc/tilcdc_external.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_external.c
> b/drivers/gpu/drm/tilcdc/tilcdc_external.c
> index 7594cf6e186e..3b86d002ef62 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_external.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_external.c
> @@ -60,11 +60,13 @@ struct drm_connector
> *tilcdc_encoder_find_connector(struct drm_device *ddev,
>  int tilcdc_add_component_encoder(struct drm_device *ddev)
>  {
>  	struct tilcdc_drm_private *priv = ddev->dev_private;
> -	struct drm_encoder *encoder;
> +	struct drm_encoder *encoder = NULL, *iter;
> 
> -	list_for_each_entry(encoder, &ddev->mode_config.encoder_list, head)
> -		if (encoder->possible_crtcs & (1 << priv->crtc->index))
> +	list_for_each_entry(iter, &ddev->mode_config.encoder_list, head)
> +		if (iter->possible_crtcs & (1 << priv->crtc->index)) {
> +			encoder = iter;
>  			break;
> +		}
> 
>  	if (!encoder) {
>  		dev_err(ddev->dev, "%s: No suitable encoder found\n", __func__);

      reply	other threads:[~2022-03-27 22:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-27  6:15 [PATCH] tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator Xiaomeng Tong
2022-03-27 22:13 ` Jyri Sarha [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=eadea5bbb40c168ee1bbf955c10979cb@iki.fi \
    --to=jyri.sarha@iki.fi \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tomba@kernel.org \
    --cc=xiam0nd.tong@gmail.com \
    /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