Commit e4865a56 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

ACPI: driver: Check ACPI_COMPANION() against NULL during probe



Since every platform driver can be forced to match a device that doesn't
match its list of device IDs because of device_match_driver_override(),
platform drivers that rely on the existence of a device's ACPI companion
object should verify its presence.

Accordingly, add requisite ACPI_COMPANION() or ACPI_HANDLE() checks
against NULL to 13 platform drivers handling core ACPI devices.

Also change the value returned by the ACPI thermal zone driver when
the device's ACPI companion is not present to -ENODEV for consistency
with the other drivers.

Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarHans de Goede <johannes.goede@oss.qualcomm.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/4516068.ejJDZkT8p0@rafael.j.wysocki
Cc: 7.0+ <stable@vger.kernel.org> # 7.0+
parent 5d691905
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -192,11 +192,15 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = {

static int acpi_ac_probe(struct platform_device *pdev)
{
	struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
	struct power_supply_config psy_cfg = {};
	struct acpi_device *adev;
	struct acpi_ac *ac;
	int result;

	adev = ACPI_COMPANION(&pdev->dev);
	if (!adev)
		return -ENODEV;

	ac = kzalloc_obj(struct acpi_ac);
	if (!ac)
		return -ENOMEM;
+5 −1
Original line number Diff line number Diff line
@@ -423,7 +423,11 @@ static void acpi_pad_notify(acpi_handle handle, u32 event, void *data)

static int acpi_pad_probe(struct platform_device *pdev)
{
	struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
	struct acpi_device *adev;

	adev = ACPI_COMPANION(&pdev->dev);
	if (!adev)
		return -ENODEV;

	return acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
					       acpi_pad_notify, adev);
+5 −1
Original line number Diff line number Diff line
@@ -815,12 +815,16 @@ static void acpi_tad_remove(void *data)
static int acpi_tad_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	acpi_handle handle = ACPI_HANDLE(dev);
	struct acpi_tad_driver_data *dd;
	acpi_handle handle;
	acpi_status status;
	unsigned long long caps;
	int ret;

	handle = ACPI_HANDLE(dev);
	if (!handle)
		return -ENODEV;

	/*
	 * Initialization failure messages are mostly about firmware issues, so
	 * print them at the "info" level.
+5 −1
Original line number Diff line number Diff line
@@ -1214,10 +1214,14 @@ static void sysfs_battery_cleanup(struct acpi_battery *battery)

static int acpi_battery_probe(struct platform_device *pdev)
{
	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
	struct acpi_battery *battery;
	struct acpi_device *device;
	int result;

	device = ACPI_COMPANION(&pdev->dev);
	if (!device)
		return -ENODEV;

	if (device->dep_unmet)
		return -EPROBE_DEFER;

+7 −2
Original line number Diff line number Diff line
@@ -531,15 +531,20 @@ static int acpi_lid_input_open(struct input_dev *input)

static int acpi_button_probe(struct platform_device *pdev)
{
	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
	acpi_notify_handler handler;
	struct acpi_device *device;
	struct acpi_button *button;
	struct input_dev *input;
	const char *hid = acpi_device_hid(device);
	acpi_status status;
	char *name, *class;
	const char *hid;
	int error = 0;

	device = ACPI_COMPANION(&pdev->dev);
	if (!device)
		return -ENODEV;

	hid = acpi_device_hid(device);
	if (!strcmp(hid, ACPI_BUTTON_HID_LID) &&
	     lid_init_state == ACPI_BUTTON_LID_INIT_DISABLED)
		return -ENODEV;
Loading