All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator
@ 2022-03-27  6:15 ` Xiaomeng Tong
  0 siblings, 0 replies; 4+ messages in thread
From: Xiaomeng Tong @ 2022-03-27  6:15 UTC (permalink / raw)
  To: jyri.sarha
  Cc: tomba, airlied, daniel, dri-devel, linux-kernel, Xiaomeng Tong, stable

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>
---
 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__);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator
@ 2022-03-27  6:15 ` Xiaomeng Tong
  0 siblings, 0 replies; 4+ messages in thread
From: Xiaomeng Tong @ 2022-03-27  6:15 UTC (permalink / raw)
  To: jyri.sarha; +Cc: tomba, airlied, linux-kernel, dri-devel, Xiaomeng Tong, stable

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>
---
 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__);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator
  2022-03-27  6:15 ` Xiaomeng Tong
@ 2022-03-27 22:13   ` Jyri Sarha
  -1 siblings, 0 replies; 4+ messages in thread
From: Jyri Sarha @ 2022-03-27 22:13 UTC (permalink / raw)
  To: Xiaomeng Tong; +Cc: tomba, airlied, daniel, dri-devel, linux-kernel, stable

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__);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator
@ 2022-03-27 22:13   ` Jyri Sarha
  0 siblings, 0 replies; 4+ messages in thread
From: Jyri Sarha @ 2022-03-27 22:13 UTC (permalink / raw)
  To: Xiaomeng Tong; +Cc: tomba, airlied, linux-kernel, stable, dri-devel

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__);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-27 22:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-27  6:15 [PATCH] tilcdc: tilcdc_external: fix an incorrect NULL check on list iterator Xiaomeng Tong
2022-03-27  6:15 ` Xiaomeng Tong
2022-03-27 22:13 ` Jyri Sarha
2022-03-27 22:13   ` Jyri Sarha

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.