]> git.baikalelectronics.ru Git - kernel.git/commit
drm/nouveau/clk: Fix an incorrect NULL check on list iterator
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Sun, 27 Mar 2022 07:58:24 +0000 (15:58 +0800)
committerLyude Paul <lyude@redhat.com>
Mon, 4 Apr 2022 21:25:38 +0000 (17:25 -0400)
commitbcb1dc7834f4f4828ed4462fd5c887e2856f9e12
tree9731eb4a1d786170dc8c8b53e91118399c77de22
parentf06d955652b952265c20996ed40041bc08089932
drm/nouveau/clk: Fix an incorrect NULL check on list iterator

The bug is here:
if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp))
return cstate;

The list iterator value 'cstate' will *always* be set and non-NULL
by list_for_each_entry_from_reverse(), so it is incorrect to assume
that the iterator value will be unchanged if the list is empty or no
element is found (In fact, it will be a bogus pointer to an invalid
structure object containing the HEAD). Also it missed a NULL check
at callsite and may lead to invalid memory access after that.

To fix this bug, just return 'encoder' when found, otherwise return
NULL. And add the NULL check.

Cc: stable@vger.kernel.org
Fixes: a8627497af03d ("drm/nouveau/clk: Respect voltage limits in nvkm_cstate_prog")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Lyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220327075824.11806-1-xiam0nd.tong@gmail.com
drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c