Skip to content

Commit

Permalink
misc: fastrpc: fix an incorrect NULL check on list iterator
Browse files Browse the repository at this point in the history
The bug is here:
	if (!buf) {

The list iterator value 'buf' will *always* be set and non-NULL
by list_for_each_entry(), so it is incorrect to assume that the
iterator value will be NULL if the list is empty (in this case, the
check 'if (!buf) {' will always be false and never exit expectly).

To fix the bug, use a new variable 'iter' as the list iterator,
while use the original variable 'buf' as a dedicated pointer to
point to the found element.

Fixes: 2419e55 ("misc: fastrpc: add mmap/unmap support")
Signed-off-by: Xiaomeng Tong <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Xiaomeng Tong authored and gregkh committed Apr 24, 2022
1 parent 4834f98 commit 5ac11fe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/misc/fastrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1606,17 +1606,18 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl,
struct fastrpc_req_munmap *req)
{
struct fastrpc_invoke_args args[1] = { [0] = { 0 } };
struct fastrpc_buf *buf, *b;
struct fastrpc_buf *buf = NULL, *iter, *b;
struct fastrpc_munmap_req_msg req_msg;
struct device *dev = fl->sctx->dev;
int err;
u32 sc;

spin_lock(&fl->lock);
list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
if ((buf->raddr == req->vaddrout) && (buf->size == req->size))
list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
if ((iter->raddr == req->vaddrout) && (iter->size == req->size)) {
buf = iter;
break;
buf = NULL;
}
}
spin_unlock(&fl->lock);

Expand Down

0 comments on commit 5ac11fe

Please sign in to comment.