Skip to content

Commit 172c48c

Browse files
jwrdegoederafaeljw
authored andcommitted
ACPI: video: Use acpi_video_device for cooling-dev driver data
The acpi_video code was storing the acpi_video_device as driver_data in the acpi_device children of the acpi_video_bus acpi_device. But the acpi_video driver only binds to the bus acpi_device. It uses, but does not bind to, the children. Since it is not the driver it should not be using the driver_data of the children's acpi_device-s. Since commit 0d16710 ("ACPI: bus: Set driver_data to NULL every time .add() fails") the childen's driver_data ends up getting set to NULL after a driver fails to bind to the children leading to a NULL pointer deref in video_get_max_state when registering the cooling-dev: [ 3.148958] BUG: kernel NULL pointer dereference, address: 0000000000000090 <snip> [ 3.149015] Hardware name: Sony Corporation VPCSB2X9R/VAIO, BIOS R2087H4 06/15/2012 [ 3.149021] RIP: 0010:video_get_max_state+0x17/0x30 [video] <snip> [ 3.149105] Call Trace: [ 3.149110] <TASK> [ 3.149114] ? __die+0x23/0x70 [ 3.149126] ? page_fault_oops+0x171/0x4e0 [ 3.149137] ? exc_page_fault+0x7f/0x180 [ 3.149147] ? asm_exc_page_fault+0x26/0x30 [ 3.149158] ? video_get_max_state+0x17/0x30 [video 9b6f3f0d19d7b4a0e2df17a2d8b43bc19c2ed71f] [ 3.149176] ? __pfx_video_get_max_state+0x10/0x10 [video 9b6f3f0d19d7b4a0e2df17a2d8b43bc19c2ed71f] [ 3.149192] __thermal_cooling_device_register.part.0+0xf2/0x2f0 [ 3.149205] acpi_video_bus_register_backlight.part.0.isra.0+0x414/0x570 [video 9b6f3f0d19d7b4a0e2df17a2d8b43bc19c2ed71f] [ 3.149227] acpi_video_register_backlight+0x57/0x80 [video 9b6f3f0d19d7b4a0e2df17a2d8b43bc19c2ed71f] [ 3.149245] intel_acpi_video_register+0x68/0x90 [i915 1f3a758130b32ef13d301d4f8f78c7d766d57f2a] [ 3.149669] intel_display_driver_register+0x28/0x50 [i915 1f3a758130b32ef13d301d4f8f78c7d766d57f2a] [ 3.150064] i915_driver_probe+0x790/0xb90 [i915 1f3a758130b32ef13d301d4f8f78c7d766d57f2a] [ 3.150402] local_pci_probe+0x45/0xa0 [ 3.150412] pci_device_probe+0xc1/0x260 <snip> Fix this by directly using the acpi_video_device as devdata for the cooling-device, which avoids the need to set driver-data on the children at all. Fixes: 0d16710 ("ACPI: bus: Set driver_data to NULL every time .add() fails") Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/9718 Cc: 6.6+ <stable@vger.kernel.org> # 6.6+ Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 2cc14f5 commit 172c48c

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

drivers/acpi/acpi_video.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ static const struct backlight_ops acpi_backlight_ops = {
253253
static int video_get_max_state(struct thermal_cooling_device *cooling_dev,
254254
unsigned long *state)
255255
{
256-
struct acpi_device *device = cooling_dev->devdata;
257-
struct acpi_video_device *video = acpi_driver_data(device);
256+
struct acpi_video_device *video = cooling_dev->devdata;
258257

259258
*state = video->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1;
260259
return 0;
@@ -263,8 +262,7 @@ static int video_get_max_state(struct thermal_cooling_device *cooling_dev,
263262
static int video_get_cur_state(struct thermal_cooling_device *cooling_dev,
264263
unsigned long *state)
265264
{
266-
struct acpi_device *device = cooling_dev->devdata;
267-
struct acpi_video_device *video = acpi_driver_data(device);
265+
struct acpi_video_device *video = cooling_dev->devdata;
268266
unsigned long long level;
269267
int offset;
270268

@@ -283,8 +281,7 @@ static int video_get_cur_state(struct thermal_cooling_device *cooling_dev,
283281
static int
284282
video_set_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long state)
285283
{
286-
struct acpi_device *device = cooling_dev->devdata;
287-
struct acpi_video_device *video = acpi_driver_data(device);
284+
struct acpi_video_device *video = cooling_dev->devdata;
288285
int level;
289286

290287
if (state >= video->brightness->count - ACPI_VIDEO_FIRST_LEVEL)
@@ -1125,7 +1122,6 @@ static int acpi_video_bus_get_one_device(struct acpi_device *device, void *arg)
11251122

11261123
strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
11271124
strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1128-
device->driver_data = data;
11291125

11301126
data->device_id = device_id;
11311127
data->video = video;
@@ -1747,8 +1743,8 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
17471743
device->backlight->props.brightness =
17481744
acpi_video_get_brightness(device->backlight);
17491745

1750-
device->cooling_dev = thermal_cooling_device_register("LCD",
1751-
device->dev, &video_cooling_ops);
1746+
device->cooling_dev = thermal_cooling_device_register("LCD", device,
1747+
&video_cooling_ops);
17521748
if (IS_ERR(device->cooling_dev)) {
17531749
/*
17541750
* Set cooling_dev to NULL so we don't crash trying to free it.

0 commit comments

Comments
 (0)