Skip to content

Commit

Permalink
ACPI: fix NULL pointer dereference
Browse files Browse the repository at this point in the history
Commit 71f6428 ("ACPI: utils: Fix reference counting in
for_each_acpi_dev_match()") started doing "acpi_dev_put()" on a pointer
that was possibly NULL.  That fails miserably, because that helper
inline function is not set up to handle that case.

Just make acpi_dev_put() silently accept a NULL pointer, rather than
calling down to put_device() with an invalid offset off that NULL
pointer.

Link: https://lore.kernel.org/lkml/a607c149-6bf6-0fd0-0e31-100378504da2@kernel.dk/
Reported-and-tested-by: Jens Axboe <axboe@kernel.dk>
Tested-by: Daniel Scally <djrscally@gmail.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Jul 24, 2021
1 parent 7ffca2b commit fc68f42
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/acpi/acpi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev)

static inline void acpi_dev_put(struct acpi_device *adev)
{
put_device(&adev->dev);
if (adev)
put_device(&adev->dev);
}

struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle);
Expand Down

0 comments on commit fc68f42

Please sign in to comment.