Skip to content

Commit c8e27a4

Browse files
warthog618brgl
authored andcommitted
gpiolib: cdev: fix null pointer dereference in linereq_free()
Fix a kernel NULL pointer dereference reported by gpio kselftests. linereq_free() can be called as part of the cleanup of a failed request, at which time the desc for a line may not have been determined, so it is unsafe to dereference without a check. Add a check prior to dereferencing the line desc. Fixes: 2068339 ("gpiolib: cdev: Add hardware timestamp clock type") Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
1 parent 8af3a0b commit c8e27a4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,11 +1460,12 @@ static ssize_t linereq_read(struct file *file,
14601460
static void linereq_free(struct linereq *lr)
14611461
{
14621462
unsigned int i;
1463-
bool hte;
1463+
bool hte = false;
14641464

14651465
for (i = 0; i < lr->num_lines; i++) {
1466-
hte = !!test_bit(FLAG_EVENT_CLOCK_HTE,
1467-
&lr->lines[i].desc->flags);
1466+
if (lr->lines[i].desc)
1467+
hte = !!test_bit(FLAG_EVENT_CLOCK_HTE,
1468+
&lr->lines[i].desc->flags);
14681469
edge_detector_stop(&lr->lines[i], hte);
14691470
if (lr->lines[i].desc)
14701471
gpiod_free(lr->lines[i].desc);

0 commit comments

Comments
 (0)