linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Darren Hart <dvhart@infradead.org>
To: platform-driver-x86@vger.kernel.org
Cc: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Mario Limonciello" <mario_limonciello@dell.com>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Rafael Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	"Darren Hart" <dvhart@infradead.org>
Subject: [PATCH 09/16] platform/x86: wmi: Instantiate all devices before adding them
Date: Fri, 26 May 2017 22:31:23 -0700	[thread overview]
Message-ID: <a25645295f6aaf80407ff851baa14ec039c885aa.1495862272.git.dvhart@infradead.org> (raw)
In-Reply-To: <cover.1495862272.git.dvhart@infradead.org>
In-Reply-To: <cover.1495862272.git.dvhart@infradead.org>

From: Andy Lutomirski <luto@kernel.org>

At some point, we will want sub-drivers to get references to other
devices on the same WMI bus. This change is needed to avoid races.

This ends up simplifying the setup code and fixing some leaks, too.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Mario Limonciello <mario_limonciello@dell.com>
Cc: Pali Rohár <pali.rohar@gmail.com>
Cc: Rafael Wysocki <rjw@rjwysocki.net>
Cc: linux-kernel@vger.kernel.org
Cc: platform-driver-x86@vger.kernel.org
Cc: linux-acpi@vger.kernel.org
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
---
 drivers/platform/x86/wmi.c | 49 +++++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 651693a..bfc0a3f 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -796,7 +796,7 @@ static struct device_type wmi_type_data = {
 	.release = wmi_dev_release,
 };
 
-static int wmi_create_device(struct device *wmi_bus_dev,
+static void wmi_create_device(struct device *wmi_bus_dev,
 			     const struct guid_block *gblock,
 			     struct wmi_block *wblock,
 			     struct acpi_device *device)
@@ -852,7 +852,7 @@ static int wmi_create_device(struct device *wmi_bus_dev,
 
 	}
 
-	return device_register(&wblock->dev.dev);
+	device_initialize(&wblock->dev.dev);
 }
 
 static void wmi_free_devices(struct acpi_device *device)
@@ -863,10 +863,14 @@ static void wmi_free_devices(struct acpi_device *device)
 	list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
 		if (wblock->acpi_device == device) {
 			list_del(&wblock->list);
-			if (wblock->dev.dev.bus)
-				device_unregister(&wblock->dev.dev);
-			else
+			if (wblock->dev.dev.bus) {
+				/* Device was initialized. */
+				device_del(&wblock->dev.dev);
+				put_device(&wblock->dev.dev);
+			} else {
+				/* device_initialize was not called. */
 				kfree(wblock);
+			}
 		}
 	}
 }
@@ -901,9 +905,9 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
 	struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
 	union acpi_object *obj;
 	const struct guid_block *gblock;
-	struct wmi_block *wblock;
+	struct wmi_block *wblock, *next;
 	acpi_status status;
-	int retval;
+	int retval = 0;
 	u32 i, total;
 
 	status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out);
@@ -936,19 +940,15 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
 			continue;
 
 		wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
-		if (!wblock)
-			return -ENOMEM;
+		if (!wblock) {
+			retval = -ENOMEM;
+			break;
+		}
 
 		wblock->acpi_device = device;
 		wblock->gblock = gblock[i];
 
-		retval = wmi_create_device(wmi_bus_dev, &gblock[i],
-					   wblock, device);
-		if (retval) {
-			put_device(&wblock->dev.dev);
-			wmi_free_devices(device);
-			goto out_free_pointer;
-		}
+		wmi_create_device(wmi_bus_dev, &gblock[i], wblock, device);
 
 		list_add_tail(&wblock->list, &wmi_block_list);
 
@@ -958,11 +958,24 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
 		}
 	}
 
-	retval = 0;
-
 out_free_pointer:
 	kfree(out.pointer);
 
+	/*
+	 * Now that all of the devices are created, add them to the
+	 * device tree and probe subdrivers.
+	 */
+	list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
+		if (wblock->acpi_device == device) {
+			if (device_add(&wblock->dev.dev) != 0) {
+				dev_err(wmi_bus_dev,
+					"failed to register %pULL\n",
+					wblock->gblock.guid);
+				list_del(&wblock->list);
+			}
+		}
+	}
+
 	return retval;
 }
 
-- 
2.9.4

  parent reply	other threads:[~2017-05-27  5:32 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-27  5:31 [PATCH 00/16] Convert WMI to a proper bus Darren Hart
2017-05-27  5:31 ` [PATCH 01/16] platform/x86: wmi: Drop "Mapper (un)loaded" messages Darren Hart
2017-05-27  5:31 ` [PATCH 02/16] platform/x86: wmi: Pass the acpi_device through to parse_wdg Darren Hart
2017-05-27  5:31 ` [PATCH 03/16] platform/x86: wmi: Clean up acpi_wmi_add Darren Hart
2017-05-27  5:31 ` [PATCH 04/16] platform/x86: wmi: Track wmi devices per ACPI device Darren Hart
2017-05-27  5:31 ` [PATCH 05/16] platform/x86: wmi: Turn WMI into a bus driver Darren Hart
2017-05-27  5:31 ` [PATCH 06/16] platform/x86: wmi: Fix error handling when creating devices Darren Hart
2017-05-27  5:31 ` [PATCH 07/16] platform/x86: wmi: Split devices into types and add basic sysfs attributes Darren Hart
2017-05-27  5:31 ` [PATCH 08/16] platform/x86: wmi: Probe data objects for read and write capabilities Darren Hart
2017-05-27  5:31 ` Darren Hart [this message]
2017-06-01 20:43   ` [PATCH 09/16] platform/x86: wmi: Instantiate all devices before adding them Michał Kępień
2017-06-06  3:03     ` Darren Hart
2017-06-06 16:03       ` Andy Lutomirski
2017-06-08  4:43         ` Michał Kępień
2017-05-27  5:31 ` [PATCH 10/16] platform/x86: wmi: Incorporate acpi_install_notify_handler Darren Hart
2017-05-27  5:31 ` [PATCH 11/16] platform/x86: wmi: Add a new interface to read block data Darren Hart
2017-05-27  5:31 ` [PATCH 12/16] platform/x86: wmi: Bind the platform device, not the ACPI node Darren Hart
2017-05-27  5:31 ` [PATCH 13/16] platform/x86: wmi: Add an interface for subdrivers to access sibling devices Darren Hart
2017-05-27  5:31 ` [PATCH 14/16] platform/x86: wmi: Require query for data blocks, rename writable to setable Darren Hart
2017-05-27  5:31 ` [PATCH 15/16] platform/x86: wmi-mof: New driver to expose embedded WMI MOF metadata Darren Hart
2017-05-27 11:14   ` Pali Rohár
2017-05-27 21:07     ` Andy Lutomirski
2017-05-30 15:24       ` Andy Shevchenko
2017-05-30 16:46         ` Darren Hart
2017-05-30 17:03         ` Pali Rohár
2017-05-30 17:21           ` Andy Shevchenko
2017-06-05 22:14     ` Darren Hart
2017-06-05 22:19       ` Pali Rohár
2017-06-05 22:39         ` Andy Lutomirski
2017-06-06 11:05           ` Pali Rohár
2017-06-06 13:46             ` Mario.Limonciello
2017-06-06 13:56               ` Pali Rohár
2017-06-07 17:39                 ` Pali Rohár
2017-06-07 20:23                   ` Mario.Limonciello
2017-06-07 20:50                     ` Pali Rohár
2017-06-09 15:46                       ` Mario.Limonciello
2017-06-09 21:51                         ` Pali Rohár
2017-06-15 16:46                           ` Pali Rohár
2017-06-06  2:33         ` Darren Hart
2017-05-27  5:31 ` [PATCH 16/16] platform/x86: dell-wmi: Convert to the WMI bus infrastructure Darren Hart
2017-05-27 10:50   ` Pali Rohár
2017-05-27 16:04     ` Andy Lutomirski
2017-05-27 16:17       ` Dmitry Torokhov
2017-05-27 18:40         ` Andy Lutomirski
2017-05-30  2:45           ` Dmitry Torokhov
2017-06-06  3:04             ` Darren Hart
2017-05-27 19:49 ` [PATCH 00/16] Convert WMI to a proper bus Rafael J. Wysocki
2017-05-27 20:01   ` Andy Shevchenko
2017-06-06 17:23 ` Darren Hart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a25645295f6aaf80407ff851baa14ec039c885aa.1495862272.git.dvhart@infradead.org \
    --to=dvhart@infradead.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mario_limonciello@dell.com \
    --cc=pali.rohar@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).