Skip to content

Commit

Permalink
HID: hidraw: fix a problem of memory leak in hidraw_release()
Browse files Browse the repository at this point in the history
'struct hidraw_list' is a circular queue whose head can be smaller than
tail. Using 'list->tail != list->head' to release all memory that should
be released.

Fixes: a5623a2 ("HID: hidraw: fix memory leak in hidraw_release()")
Signed-off-by: Su Hui <suhui@nfschina.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
  • Loading branch information
Su Hui authored and Jiri Kosina committed Jan 25, 2024
1 parent 26dd6a5 commit a3bdcdd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/hid/hidraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,11 @@ static int hidraw_release(struct inode * inode, struct file * file)
down_write(&minors_rwsem);

spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
for (int i = list->tail; i < list->head; i++)
kfree(list->buffer[i].value);
while (list->tail != list->head) {
kfree(list->buffer[list->tail].value);
list->buffer[list->tail].value = NULL;
list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1);
}
list_del(&list->node);
spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
kfree(list);
Expand Down

0 comments on commit a3bdcdd

Please sign in to comment.