mei: bus: enable running fixup routines before device registration
authorTomas Winkler <tomas.winkler@intel.com>
Thu, 23 Jul 2015 12:08:43 +0000 (15:08 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 4 Aug 2015 00:24:16 +0000 (17:24 -0700)
Split the device registration into allocation and device struct
initialization, device setup, and the final device registration.
This why it is possible to run fixups and quirks during the setup stage
on an initialized device. Each fixup routine effects do_match flag.
If the flag is set to false at the end the device won't be
registered on the bus.

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/mei/bus-fixup.c
drivers/misc/mei/bus.c
drivers/misc/mei/mei_dev.h
include/linux/mei_cl_bus.h

index 47aa1523d9e1b501f2c00468af72a4b4a019ad3d..865e33bcd2261ce033d23ae4d22fbf0bb1097462 100644 (file)
 #include <linux/moduleparam.h>
 #include <linux/device.h>
 #include <linux/slab.h>
+#include <linux/uuid.h>
 
 #include <linux/mei_cl_bus.h>
 
 #include "mei_dev.h"
 #include "client.h"
 
+#define MEI_UUID_ANY NULL_UUID_LE
+
 struct mei_nfc_cmd {
        u8 command;
        u8 status;
@@ -412,4 +415,31 @@ void mei_nfc_host_exit(struct mei_device *bus)
        mutex_unlock(&bus->device_lock);
 }
 
+#define MEI_FIXUP(_uuid, _hook) { _uuid, _hook }
+
+static struct mei_fixup {
+
+       const uuid_le uuid;
+       void (*hook)(struct mei_cl_device *cldev);
+} mei_fixups[] = {};
+
+/**
+ * mei_cl_dev_fixup - run fixup handlers
+ *
+ * @cldev: me client device
+ */
+void mei_cl_dev_fixup(struct mei_cl_device *cldev)
+{
+       struct mei_fixup *f;
+       const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(mei_fixups); i++) {
+
+               f = &mei_fixups[i];
+               if (uuid_le_cmp(f->uuid, MEI_UUID_ANY) == 0 ||
+                   uuid_le_cmp(f->uuid, *uuid) == 0)
+                       f->hook(cldev);
+       }
+}
 
index 34b14dda050c215ac5432451db3aae1c11bf7e4f..68b7756bf384683693bad94dad7f5e96c5e7e4a4 100644 (file)
@@ -436,6 +436,9 @@ static int mei_cl_device_match(struct device *dev, struct device_driver *drv)
        if (!cldev)
                return 0;
 
+       if (!cldev->do_match)
+               return 0;
+
        if (!cldrv || !cldrv->id_table)
                return 0;
 
@@ -634,6 +637,76 @@ struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *bus,
        return NULL;
 }
 
+/**
+ * mei_cl_dev_alloc - initialize and allocate mei client device
+ *
+ * @bus: mei device
+ * @me_cl: me client
+ *
+ * Return: allocated device structur or NULL on allocation failure
+ */
+static struct mei_cl_device *mei_cl_dev_alloc(struct mei_device *bus,
+                                             struct mei_me_client *me_cl)
+{
+       struct mei_cl_device *cldev;
+
+       cldev = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
+       if (!cldev)
+               return NULL;
+
+       device_initialize(&cldev->dev);
+       cldev->dev.parent = bus->dev;
+       cldev->dev.bus    = &mei_cl_bus_type;
+       cldev->dev.type   = &mei_cl_device_type;
+       cldev->bus        = mei_dev_bus_get(bus);
+       cldev->me_cl      = mei_me_cl_get(me_cl);
+       cldev->is_added   = 0;
+       INIT_LIST_HEAD(&cldev->bus_list);
+
+       return cldev;
+}
+
+/**
+ * mei_cl_dev_setup - setup me client device
+ *    run fix up routines and set the device name
+ *
+ * @bus: mei device
+ * @cldev: me client device
+ *
+ * Return: true if the device is eligible for enumeration
+ */
+static bool mei_cl_dev_setup(struct mei_device *bus,
+                            struct mei_cl_device *cldev)
+{
+       cldev->do_match = 1;
+       mei_cl_dev_fixup(cldev);
+
+       if (cldev->do_match)
+               dev_set_name(&cldev->dev, "mei:%s:%pUl",
+                            cldev->name, mei_me_cl_uuid(cldev->me_cl));
+
+       return cldev->do_match == 1;
+}
+
+/**
+ * mei_cl_bus_dev_add - add me client devices
+ *
+ * @cldev: me client device
+ *
+ * Return: 0 on success; < 0 on failre
+ */
+static int mei_cl_bus_dev_add(struct mei_cl_device *cldev)
+{
+       int ret;
+
+       dev_dbg(cldev->bus->dev, "adding %pUL\n", mei_me_cl_uuid(cldev->me_cl));
+       ret = device_add(&cldev->dev);
+       if (!ret)
+               cldev->is_added = 1;
+
+       return ret;
+}
+
 struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
                                        struct mei_me_client *me_cl,
                                        struct mei_cl *cl,
@@ -642,28 +715,16 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
        struct mei_cl_device *cldev;
        int status;
 
-       cldev = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
+       cldev = mei_cl_dev_alloc(bus, me_cl);
        if (!cldev)
                return NULL;
 
-       cldev->me_cl = mei_me_cl_get(me_cl);
-       if (!cldev->me_cl) {
-               kfree(cldev);
-               return NULL;
-       }
-
        cldev->cl = cl;
-       cldev->dev.parent = bus->dev;
-       cldev->dev.bus = &mei_cl_bus_type;
-       cldev->dev.type = &mei_cl_device_type;
-       cldev->bus      = mei_dev_bus_get(bus);
-       INIT_LIST_HEAD(&cldev->bus_list);
-
        strlcpy(cldev->name, name, sizeof(cldev->name));
 
-       dev_set_name(&cldev->dev, "mei:%s:%pUl", name, mei_me_cl_uuid(me_cl));
+       mei_cl_dev_setup(bus, cldev);
 
-       status = device_register(&cldev->dev);
+       status = mei_cl_bus_dev_add(cldev);
        if (status) {
                dev_err(bus->dev, "Failed to register MEI device\n");
                mei_me_cl_put(cldev->me_cl);
index 882e6f77084afe44ca4bbbd5b8b23ff9d57482a7..ad59ab776f2d734e832069259d35abdd76c3310c 100644 (file)
@@ -335,7 +335,7 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
                                        struct mei_cl *cl,
                                        char *name);
 void mei_cl_remove_device(struct mei_cl_device *cldev);
-
+void mei_cl_dev_fixup(struct mei_cl_device *dev);
 ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
                        bool blocking);
 ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
index 85239138251c90edc708f736d51942c198d6b850..81ab56dd0ae0b3a278221708920f6dbcf0f82731 100644 (file)
@@ -29,6 +29,8 @@ typedef void (*mei_cl_event_cb_t)(struct mei_cl_device *device,
  *     events (e.g. Rx buffer pending) notifications.
  * @event_context: event callback run context
  * @events: Events bitmask sent to the driver.
+ *
+ * @do_match: wheather device can be matched with a driver
  * @is_added: device is already scanned
  * @priv_data: client private data
  */
@@ -45,6 +47,8 @@ struct mei_cl_device {
        mei_cl_event_cb_t event_cb;
        void *event_context;
        unsigned long events;
+
+       unsigned int do_match:1;
        unsigned int is_added:1;
 
        void *priv_data;
This page took 0.035968 seconds and 5 git commands to generate.