Merge tag 'char-misc-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[deliverable/linux.git] / drivers / misc / mei / iorw.c
index 50f52e21f587a229e374a9f72149186aace43777..fcba98eb892e1e410d62a4c198d978ab82b667f5 100644 (file)
 #include <linux/mei.h>
 #include "interface.h"
 
+/**
+ * mei_me_cl_by_id return index to me_clients for client_id
+ *
+ * @dev: the device structure
+ * @client_id: me client id
+ *
+ * Locking: called under "dev->device_lock" lock
+ *
+ * returns index on success, -ENOENT on failure.
+ */
 
+int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
+{
+       int i;
+       for (i = 0; i < dev->me_clients_num; i++)
+               if (dev->me_clients[i].client_id == client_id)
+                       break;
+       if (WARN_ON(dev->me_clients[i].client_id != client_id))
+               return -ENOENT;
+
+       if (i == dev->me_clients_num)
+               return -ENOENT;
+
+       return i;
+}
 
 /**
  * mei_ioctl_connect_client - the connect to fw client IOCTL function
@@ -84,7 +108,7 @@ int mei_ioctl_connect_client(struct file *file,
 
        cb->major_file_operations = MEI_IOCTL;
 
-       if (dev->mei_state != MEI_ENABLED) {
+       if (dev->dev_state != MEI_DEV_ENABLED) {
                rets = -ENODEV;
                goto end;
        }
@@ -95,7 +119,7 @@ int mei_ioctl_connect_client(struct file *file,
        }
 
        /* find ME client we're trying to connect to */
-       i = mei_find_me_client_index(dev, data->in_client_uuid);
+       i = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
        if (i >= 0 && !dev->me_clients[i].props.fixed_address) {
                cl->me_client_id = dev->me_clients[i].client_id;
                cl->state = MEI_FILE_CONNECTING;
@@ -273,19 +297,12 @@ int amthi_read(struct mei_device *dev, struct file *file,
                return -ETIMEDOUT;
        }
 
-       for (i = 0; i < dev->me_clients_num; i++) {
-               if (dev->me_clients[i].client_id ==
-                   dev->iamthif_cl.me_client_id)
-                       break;
-       }
+       i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
 
-       if (i == dev->me_clients_num) {
+       if (i < 0) {
                dev_dbg(&dev->pdev->dev, "amthi client not found.\n");
                return -ENODEV;
        }
-       if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id))
-               return -ENODEV;
-
        dev_dbg(&dev->pdev->dev, "checking amthi data\n");
        cb = find_amthi_read_list_entry(dev, file);
 
@@ -316,8 +333,7 @@ int amthi_read(struct mei_device *dev, struct file *file,
        dev->iamthif_timer = 0;
 
        if (cb) {
-               timeout = cb->read_time +
-                                       msecs_to_jiffies(IAMTHIF_READ_TIMER);
+               timeout = cb->read_time + msecs_to_jiffies(IAMTHIF_READ_TIMER);
                dev_dbg(&dev->pdev->dev, "amthi timeout = %lud\n",
                                timeout);
 
@@ -386,7 +402,7 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
        if (cl->state != MEI_FILE_CONNECTED)
                return -ENODEV;
 
-       if (dev->mei_state != MEI_ENABLED)
+       if (dev->dev_state != MEI_DEV_ENABLED)
                return -ENODEV;
 
        dev_dbg(&dev->pdev->dev, "check if read is pending.\n");
@@ -401,19 +417,8 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
 
        dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n",
                cl->host_client_id, cl->me_client_id);
-
-       for (i = 0; i < dev->me_clients_num; i++) {
-               if (dev->me_clients[i].client_id == cl->me_client_id)
-                       break;
-
-       }
-
-       if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
-               rets = -ENODEV;
-               goto unlock;
-       }
-
-       if (i == dev->me_clients_num) {
+       i = mei_me_cl_by_id(dev, cl->me_client_id);
+       if (i < 0) {
                rets = -ENODEV;
                goto unlock;
        }
This page took 0.042344 seconds and 5 git commands to generate.