mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Xiaomeng Tong <xiam0nd.tong@gmail.com>
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
Subject: Re: [PATCH] device: fix missing check on list iterator
Date: Sun, 27 Mar 2022 07:22:27 -0700	[thread overview]
Message-ID: <10cdb7dc-c210-8439-dacc-4338d3070f7f@roeck-us.net> (raw)
In-Reply-To: <20220327065950.7886-1-xiam0nd.tong@gmail.com>

On 3/26/22 23:59, Xiaomeng Tong wrote:
> 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))
> 


Uuh, yes, you are correct. Sorry for the noise.

Guenter


      reply	other threads:[~2022-03-27 15:08 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
2022-03-27 14:22     ` Guenter Roeck [this message]

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=10cdb7dc-c210-8439-dacc-4338d3070f7f@roeck-us.net \
    --to=linux@roeck-us.net \
    --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=lyude@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=stable@vger.kernel.org \
    --cc=xiam0nd.tong@gmail.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 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®