Commit c8e27a4a authored by Kent Gibson's avatar Kent Gibson Committed by Bartosz Golaszewski
Browse files

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: 2068339a ("gpiolib: cdev: Add hardware timestamp clock type")
Signed-off-by: default avatarKent Gibson <warthog618@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <brgl@bgdev.pl>
parent 8af3a0b2
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1460,9 +1460,10 @@ static ssize_t linereq_read(struct file *file,
static void linereq_free(struct linereq *lr)
{
	unsigned int i;
	bool hte;
	bool hte = false;

	for (i = 0; i < lr->num_lines; i++) {
		if (lr->lines[i].desc)
			hte = !!test_bit(FLAG_EVENT_CLOCK_HTE,
					 &lr->lines[i].desc->flags);
		edge_detector_stop(&lr->lines[i], hte);