Skip to content

Commit a3bdcdd

Browse files
Su HuiJiri Kosina
authored andcommitted
HID: hidraw: fix a problem of memory leak in hidraw_release()
'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 <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 26dd6a5 commit a3bdcdd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/hid/hidraw.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,11 @@ static int hidraw_release(struct inode * inode, struct file * file)
357357
down_write(&minors_rwsem);
358358

359359
spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
360-
for (int i = list->tail; i < list->head; i++)
361-
kfree(list->buffer[i].value);
360+
while (list->tail != list->head) {
361+
kfree(list->buffer[list->tail].value);
362+
list->buffer[list->tail].value = NULL;
363+
list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1);
364+
}
362365
list_del(&list->node);
363366
spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
364367
kfree(list);

0 commit comments

Comments
 (0)