linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/gma500/oaktrail_lvds: replace continue with break
@ 2021-06-18 18:35 Colin King
  2021-06-18 19:20 ` Patrik Jakobsson
  2021-06-19 13:40 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2021-06-18 18:35 UTC (permalink / raw)
  To: Patrik Jakobsson, David Airlie, Daniel Vetter, dri-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently a loop scans through the connector list checking
for connectors that do not match a specific criteria. The
use of the continue statement is a little unintuitive and
can confuse static analysis checking.  Invert the criteria
matching logic and use a break to terminate the loop once
the first suitable connector has been found.

Thanks to Patrik Jakobsson for explaining the original
intent of the code and suggesting this change.

Addresses-Coverity: ("Continue has no effect")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/gma500/oaktrail_lvds.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c b/drivers/gpu/drm/gma500/oaktrail_lvds.c
index 432bdcc57ac9..8541dcf237eb 100644
--- a/drivers/gpu/drm/gma500/oaktrail_lvds.c
+++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c
@@ -113,8 +113,8 @@ static void oaktrail_lvds_mode_set(struct drm_encoder *encoder,
 
 	/* Find the connector we're trying to set up */
 	list_for_each_entry(connector, &mode_config->connector_list, head) {
-		if (!connector->encoder || connector->encoder->crtc != crtc)
-			continue;
+		if (connector->encoder && connector->encoder->crtc == crtc)
+			break;
 	}
 
 	if (!connector) {
-- 
2.31.1


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

* Re: [PATCH] drm/gma500/oaktrail_lvds: replace continue with break
  2021-06-18 18:35 [PATCH] drm/gma500/oaktrail_lvds: replace continue with break Colin King
@ 2021-06-18 19:20 ` Patrik Jakobsson
  2021-06-19 13:40 ` Dan Carpenter
  1 sibling, 0 replies; 4+ messages in thread
From: Patrik Jakobsson @ 2021-06-18 19:20 UTC (permalink / raw)
  To: Colin King
  Cc: David Airlie, Daniel Vetter, dri-devel, kernel-janitors, linux-kernel

On Fri, Jun 18, 2021 at 8:35 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently a loop scans through the connector list checking
> for connectors that do not match a specific criteria. The
> use of the continue statement is a little unintuitive and
> can confuse static analysis checking.  Invert the criteria
> matching logic and use a break to terminate the loop once
> the first suitable connector has been found.
>
> Thanks to Patrik Jakobsson for explaining the original
> intent of the code and suggesting this change.

Applied to drm-misc-next

Thanks for the patch!

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

* Re: [PATCH] drm/gma500/oaktrail_lvds: replace continue with break
  2021-06-18 18:35 [PATCH] drm/gma500/oaktrail_lvds: replace continue with break Colin King
  2021-06-18 19:20 ` Patrik Jakobsson
@ 2021-06-19 13:40 ` Dan Carpenter
  2021-06-19 20:43   ` Patrik Jakobsson
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-06-19 13:40 UTC (permalink / raw)
  To: Colin King
  Cc: Patrik Jakobsson, David Airlie, Daniel Vetter, dri-devel,
	kernel-janitors, linux-kernel

On Fri, Jun 18, 2021 at 07:35:24PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently a loop scans through the connector list checking
> for connectors that do not match a specific criteria. The
> use of the continue statement is a little unintuitive and
> can confuse static analysis checking.  Invert the criteria
> matching logic and use a break to terminate the loop once
> the first suitable connector has been found.
> 
> Thanks to Patrik Jakobsson for explaining the original
> intent of the code and suggesting this change.
> 
> Addresses-Coverity: ("Continue has no effect")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/gpu/drm/gma500/oaktrail_lvds.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c b/drivers/gpu/drm/gma500/oaktrail_lvds.c
> index 432bdcc57ac9..8541dcf237eb 100644
> --- a/drivers/gpu/drm/gma500/oaktrail_lvds.c
> +++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c
> @@ -113,8 +113,8 @@ static void oaktrail_lvds_mode_set(struct drm_encoder *encoder,
>  
>  	/* Find the connector we're trying to set up */
>  	list_for_each_entry(connector, &mode_config->connector_list, head) {
> -		if (!connector->encoder || connector->encoder->crtc != crtc)
> -			continue;
> +		if (connector->encoder && connector->encoder->crtc == crtc)
> +			break;
>  	}
>  
>  	if (!connector) {

This test is wrong/impossible.  It should be:

	if (list_entry_is_head(connector, &mode_config->connector_list,
			       head)) {

regards,
dan carpenter



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

* Re: [PATCH] drm/gma500/oaktrail_lvds: replace continue with break
  2021-06-19 13:40 ` Dan Carpenter
@ 2021-06-19 20:43   ` Patrik Jakobsson
  0 siblings, 0 replies; 4+ messages in thread
From: Patrik Jakobsson @ 2021-06-19 20:43 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Colin King, David Airlie, Daniel Vetter, dri-devel,
	kernel-janitors, linux-kernel

On Sat, Jun 19, 2021 at 3:40 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Fri, Jun 18, 2021 at 07:35:24PM +0100, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently a loop scans through the connector list checking
> > for connectors that do not match a specific criteria. The
> > use of the continue statement is a little unintuitive and
> > can confuse static analysis checking.  Invert the criteria
> > matching logic and use a break to terminate the loop once
> > the first suitable connector has been found.
> >
> > Thanks to Patrik Jakobsson for explaining the original
> > intent of the code and suggesting this change.
> >
> > Addresses-Coverity: ("Continue has no effect")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >  drivers/gpu/drm/gma500/oaktrail_lvds.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/gma500/oaktrail_lvds.c b/drivers/gpu/drm/gma500/oaktrail_lvds.c
> > index 432bdcc57ac9..8541dcf237eb 100644
> > --- a/drivers/gpu/drm/gma500/oaktrail_lvds.c
> > +++ b/drivers/gpu/drm/gma500/oaktrail_lvds.c
> > @@ -113,8 +113,8 @@ static void oaktrail_lvds_mode_set(struct drm_encoder *encoder,
> >
> >       /* Find the connector we're trying to set up */
> >       list_for_each_entry(connector, &mode_config->connector_list, head) {
> > -             if (!connector->encoder || connector->encoder->crtc != crtc)
> > -                     continue;
> > +             if (connector->encoder && connector->encoder->crtc == crtc)
> > +                     break;
> >       }
> >
> >       if (!connector) {
>
> This test is wrong/impossible.  It should be:
>
>         if (list_entry_is_head(connector, &mode_config->connector_list,
>                                head)) {

Right, we should be back at the head if no match was found. Actually,
when looking closer, we should use drm_for_each_connector_iter() when
walking the connector list together with proper locking.

-Patrik

>
> regards,
> dan carpenter
>
>

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

end of thread, other threads:[~2021-06-19 20:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 18:35 [PATCH] drm/gma500/oaktrail_lvds: replace continue with break Colin King
2021-06-18 19:20 ` Patrik Jakobsson
2021-06-19 13:40 ` Dan Carpenter
2021-06-19 20:43   ` Patrik Jakobsson

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).