dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm/gma500: fix a potential repeat execution in psb_driver_load
@ 2022-04-06 11:31 Xiaomeng Tong
  2022-04-12 14:58 ` Patrik Jakobsson
  0 siblings, 1 reply; 3+ messages in thread
From: Xiaomeng Tong @ 2022-04-06 11:31 UTC (permalink / raw)
  To: patrik.r.jakobsson, airlied, daniel
  Cc: Xiaomeng Tong, linux-kernel, dri-devel

Instead of exiting the loop as expected when an entry is found, the
list_for_each_entry() continues until the traversal is complete. To
avoid potential executing 'ret = gma_backlight_init(dev);' repeatly,
goto outside the loop when the entry is found.

Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---

changes since v1:
 - goto outside the loop (Xiaomeng Tong)

v1: https://lore.kernel.org/lkml/20220401115811.9656-1-xiam0nd.tong@gmail.com/

---
 drivers/gpu/drm/gma500/psb_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 2aff54d505e2..929fd47548b4 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -400,9 +400,10 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 		case INTEL_OUTPUT_LVDS:
 		case INTEL_OUTPUT_MIPI:
 			ret = gma_backlight_init(dev);
-			break;
+			goto out;
 		}
 	}
+out:
 	drm_connector_list_iter_end(&conn_iter);
 
 	if (ret)
-- 
2.17.1


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

* Re: [PATCH v2] drm/gma500: fix a potential repeat execution in psb_driver_load
  2022-04-06 11:31 [PATCH v2] drm/gma500: fix a potential repeat execution in psb_driver_load Xiaomeng Tong
@ 2022-04-12 14:58 ` Patrik Jakobsson
  2022-04-13  5:17   ` Xiaomeng Tong
  0 siblings, 1 reply; 3+ messages in thread
From: Patrik Jakobsson @ 2022-04-12 14:58 UTC (permalink / raw)
  To: Xiaomeng Tong; +Cc: David Airlie, dri-devel, linux-kernel

On Wed, Apr 6, 2022 at 1:31 PM Xiaomeng Tong <xiam0nd.tong@gmail.com> wrote:
>
> Instead of exiting the loop as expected when an entry is found, the
> list_for_each_entry() continues until the traversal is complete. To
> avoid potential executing 'ret = gma_backlight_init(dev);' repeatly,
> goto outside the loop when the entry is found.
>
> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
> ---
>
> changes since v1:
>  - goto outside the loop (Xiaomeng Tong)
>
> v1: https://lore.kernel.org/lkml/20220401115811.9656-1-xiam0nd.tong@gmail.com/
>
> ---
>  drivers/gpu/drm/gma500/psb_drv.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
> index 2aff54d505e2..929fd47548b4 100644
> --- a/drivers/gpu/drm/gma500/psb_drv.c
> +++ b/drivers/gpu/drm/gma500/psb_drv.c
> @@ -400,9 +400,10 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
>                 case INTEL_OUTPUT_LVDS:
>                 case INTEL_OUTPUT_MIPI:
>                         ret = gma_backlight_init(dev);
> -                       break;
> +                       goto out;
>                 }
>         }
> +out:
>         drm_connector_list_iter_end(&conn_iter);

Hi,
This would work but using gotos like this easily turns the code into
spaghetti. See "7. Centralized exiting of functions" in
Documentation/process/coding-style.rst for when to use gotos.

In this particular case I think we are better off using an
if-statement. What about something like this:

if (gma_encoder->type == INTEL_OUTPUT_LVDS ||
    gma_encoder->type == INTEL_OUTPUT_MIPI) {
        ret = gma_backlight_init();
        break;
}

-Patrik

>
>         if (ret)
> --
> 2.17.1
>

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

* Re: [PATCH v2] drm/gma500: fix a potential repeat execution in psb_driver_load
  2022-04-12 14:58 ` Patrik Jakobsson
@ 2022-04-13  5:17   ` Xiaomeng Tong
  0 siblings, 0 replies; 3+ messages in thread
From: Xiaomeng Tong @ 2022-04-13  5:17 UTC (permalink / raw)
  To: patrik.r.jakobsson; +Cc: airlied, xiam0nd.tong, dri-devel, linux-kernel

On Tue, 12 Apr 2022 16:58:24 +0200, Patrik Jakobsson wrote:
> Hi,
> This would work but using gotos like this easily turns the code into
> spaghetti. See "7. Centralized exiting of functions" in
> Documentation/process/coding-style.rst for when to use gotos.
> 
> In this particular case I think we are better off using an
> if-statement. What about something like this:
> 
> if (gma_encoder->type == INTEL_OUTPUT_LVDS ||
>     gma_encoder->type == INTEL_OUTPUT_MIPI) {
>         ret = gma_backlight_init();
>         break;
> }

Yes, it looks better.
I have sent a PATCH v3 with changes as you suggested, please check it.
Thank you very much.

--
Xiaomeng Tong

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

end of thread, other threads:[~2022-04-13  5:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 11:31 [PATCH v2] drm/gma500: fix a potential repeat execution in psb_driver_load Xiaomeng Tong
2022-04-12 14:58 ` Patrik Jakobsson
2022-04-13  5:17   ` Xiaomeng Tong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).