All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Roland Scheidegger <sroland@vmware.com>
Cc: David Airlie <airlied@linux.ie>,
	kernel-janitors@vger.kernel.org,
	VMware Graphics <linux-graphics-maintainer@vmware.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/vmwgfx: Fix two list_for_each loop exit tests
Date: Tue, 14 Jul 2020 08:25:16 +0000	[thread overview]
Message-ID: <20200714082516.GZ2571@kadam> (raw)
In-Reply-To: <77f0761a-11e6-e321-2245-700258d54924@vmware.com>

On Tue, Jul 14, 2020 at 03:39:13AM +0200, Roland Scheidegger wrote:
> Am 26.06.20 um 12:39 schrieb Dan Carpenter:
> > These if statements are supposed to be true if we ended the
> > list_for_each_entry() loops without hitting a break statement but they
> > don't work.
> > 
> > In the first loop, we increment "i" after the "if (i = unit)" condition
> > so we don't necessarily know that "i" is not equal to unit at the end of
> > the loop.
> So, if I understand this right, this would only really be a problem if
> there's no list entries at all, right? That is i = unit = 0.
> Not sure if that can actually happen, but in any case the fix looks correct.

An empty list and there is another potential issue where unit is exactly
off by one.

	list_for_each_entry(con, &dev_priv->dev->mode_config.connector_list,
			    head) {
		if (i = unit)
			break;
		++i;  <-- this is the last iteration and it's off by one
			  so now i = unit but we didn't exit via the
			  break statement.
	}

	if (i != unit) {
            ^^^^^^^^^
Since we didn't exit by the break statement we want this to be true but
it's false instead.

		DRM_ERROR("Could not find initial display unit.\n");

I don't know how *likely* this is, but static checkers complain.
Technically correct is the best kind of correct!  ;)

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Roland Scheidegger <sroland@vmware.com>
Cc: David Airlie <airlied@linux.ie>,
	kernel-janitors@vger.kernel.org,
	VMware Graphics <linux-graphics-maintainer@vmware.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/vmwgfx: Fix two list_for_each loop exit tests
Date: Tue, 14 Jul 2020 11:25:16 +0300	[thread overview]
Message-ID: <20200714082516.GZ2571@kadam> (raw)
In-Reply-To: <77f0761a-11e6-e321-2245-700258d54924@vmware.com>

On Tue, Jul 14, 2020 at 03:39:13AM +0200, Roland Scheidegger wrote:
> Am 26.06.20 um 12:39 schrieb Dan Carpenter:
> > These if statements are supposed to be true if we ended the
> > list_for_each_entry() loops without hitting a break statement but they
> > don't work.
> > 
> > In the first loop, we increment "i" after the "if (i == unit)" condition
> > so we don't necessarily know that "i" is not equal to unit at the end of
> > the loop.
> So, if I understand this right, this would only really be a problem if
> there's no list entries at all, right? That is i == unit == 0.
> Not sure if that can actually happen, but in any case the fix looks correct.

An empty list and there is another potential issue where unit is exactly
off by one.

	list_for_each_entry(con, &dev_priv->dev->mode_config.connector_list,
			    head) {
		if (i == unit)
			break;
		++i;  <-- this is the last iteration and it's off by one
			  so now i == unit but we didn't exit via the
			  break statement.
	}

	if (i != unit) {
            ^^^^^^^^^
Since we didn't exit by the break statement we want this to be true but
it's false instead.

		DRM_ERROR("Could not find initial display unit.\n");

I don't know how *likely* this is, but static checkers complain.
Technically correct is the best kind of correct!  ;)

regards,
dan carpenter

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-07-14  8:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26 10:39 [PATCH] drm/vmwgfx: Fix two list_for_each loop exit tests Dan Carpenter
2020-06-26 10:39 ` Dan Carpenter
2020-07-14  1:39 ` Roland Scheidegger
2020-07-14  1:39   ` Roland Scheidegger
2020-07-14  8:25   ` Dan Carpenter [this message]
2020-07-14  8:25     ` Dan Carpenter
2020-07-15  2:19     ` Roland Scheidegger
2020-07-15  2:19       ` Roland Scheidegger

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=20200714082516.GZ2571@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-graphics-maintainer@vmware.com \
    --cc=sroland@vmware.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 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.