mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: linux@roeck-us.net
Cc: airlied@linux.ie, bskeggs@redhat.com, daniel@ffwll.ch,
	dri-devel@lists.freedesktop.org, kherbst@redhat.com,
	linux-kernel@vger.kernel.org, lyude@redhat.com,
	nouveau@lists.freedesktop.org, stable@vger.kernel.org,
	xiam0nd.tong@gmail.com
Subject: Re: [PATCH] device: fix missing check on list iterator
Date: Sun, 27 Mar 2022 14:59:50 +0800	[thread overview]
Message-ID: <20220327065950.7886-1-xiam0nd.tong@gmail.com> (raw)
In-Reply-To: <80429172-37c6-c9ce-4df7-259bb90338a8@roeck-us.net>

On Sat, 26 Mar 2022 22:38:05 -0700, Guenter Roeck <linux@roeck-us.net> wrote:
> > @@ -103,11 +103,16 @@ nvkm_control_mthd_pstate_attr(struct nvkm_control *ctrl, void *data, u32 size)
> >   		return -EINVAL;
> >   
> >   	if (args->v0.state != NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT) {
> > -		list_for_each_entry(pstate, &clk->states, head) {
> > -			if (i++ == args->v0.state)
> > +		list_for_each_entry(iter, &clk->states, head) {
> > +			if (i++ == args->v0.state) {
> > +				pstate = iter;
> 
> Is iter and the assignment really necessary ? Unless I am missing something,
> list_for_each_entry() always assigns pos (pstate/iter), even if the list is
> empty. If nothing is found, pstate would be NULL at the end, so

the pstate will not be NULL at the end! so the assignment is necessary!
#define list_for_each_entry(pos, head, member)                          \
    for (pos = __container_of((head)->next, pos, member);               \
         &pos->member != (head);                                        \
         pos = __container_of(pos->member.next, pos, member))

--
Xiaomeng Tong

  reply	other threads:[~2022-03-27  7:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-27  5:31 Xiaomeng Tong
2022-03-27  5:38 ` Guenter Roeck
2022-03-27  6:59   ` Xiaomeng Tong [this message]
2022-03-27 14:22     ` Guenter Roeck

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=20220327065950.7886-1-xiam0nd.tong@gmail.com \
    --to=xiam0nd.tong@gmail.com \
    --cc=airlied@linux.ie \
    --cc=bskeggs@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kherbst@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lyude@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®