aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei/iorw.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/mei/iorw.c')
-rw-r--r--drivers/misc/mei/iorw.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/drivers/misc/mei/iorw.c b/drivers/misc/mei/iorw.c
index 50f52e21f587..fcba98eb892e 100644
--- a/drivers/misc/mei/iorw.c
+++ b/drivers/misc/mei/iorw.c
@@ -38,7 +38,31 @@
38#include <linux/mei.h> 38#include <linux/mei.h>
39#include "interface.h" 39#include "interface.h"
40 40
41/**
42 * mei_me_cl_by_id return index to me_clients for client_id
43 *
44 * @dev: the device structure
45 * @client_id: me client id
46 *
47 * Locking: called under "dev->device_lock" lock
48 *
49 * returns index on success, -ENOENT on failure.
50 */
41 51
52int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
53{
54 int i;
55 for (i = 0; i < dev->me_clients_num; i++)
56 if (dev->me_clients[i].client_id == client_id)
57 break;
58 if (WARN_ON(dev->me_clients[i].client_id != client_id))
59 return -ENOENT;
60
61 if (i == dev->me_clients_num)
62 return -ENOENT;
63
64 return i;
65}
42 66
43/** 67/**
44 * mei_ioctl_connect_client - the connect to fw client IOCTL function 68 * mei_ioctl_connect_client - the connect to fw client IOCTL function
@@ -84,7 +108,7 @@ int mei_ioctl_connect_client(struct file *file,
84 108
85 cb->major_file_operations = MEI_IOCTL; 109 cb->major_file_operations = MEI_IOCTL;
86 110
87 if (dev->mei_state != MEI_ENABLED) { 111 if (dev->dev_state != MEI_DEV_ENABLED) {
88 rets = -ENODEV; 112 rets = -ENODEV;
89 goto end; 113 goto end;
90 } 114 }
@@ -95,7 +119,7 @@ int mei_ioctl_connect_client(struct file *file,
95 } 119 }
96 120
97 /* find ME client we're trying to connect to */ 121 /* find ME client we're trying to connect to */
98 i = mei_find_me_client_index(dev, data->in_client_uuid); 122 i = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
99 if (i >= 0 && !dev->me_clients[i].props.fixed_address) { 123 if (i >= 0 && !dev->me_clients[i].props.fixed_address) {
100 cl->me_client_id = dev->me_clients[i].client_id; 124 cl->me_client_id = dev->me_clients[i].client_id;
101 cl->state = MEI_FILE_CONNECTING; 125 cl->state = MEI_FILE_CONNECTING;
@@ -273,19 +297,12 @@ int amthi_read(struct mei_device *dev, struct file *file,
273 return -ETIMEDOUT; 297 return -ETIMEDOUT;
274 } 298 }
275 299
276 for (i = 0; i < dev->me_clients_num; i++) { 300 i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
277 if (dev->me_clients[i].client_id ==
278 dev->iamthif_cl.me_client_id)
279 break;
280 }
281 301
282 if (i == dev->me_clients_num) { 302 if (i < 0) {
283 dev_dbg(&dev->pdev->dev, "amthi client not found.\n"); 303 dev_dbg(&dev->pdev->dev, "amthi client not found.\n");
284 return -ENODEV; 304 return -ENODEV;
285 } 305 }
286 if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id))
287 return -ENODEV;
288
289 dev_dbg(&dev->pdev->dev, "checking amthi data\n"); 306 dev_dbg(&dev->pdev->dev, "checking amthi data\n");
290 cb = find_amthi_read_list_entry(dev, file); 307 cb = find_amthi_read_list_entry(dev, file);
291 308
@@ -316,8 +333,7 @@ int amthi_read(struct mei_device *dev, struct file *file,
316 dev->iamthif_timer = 0; 333 dev->iamthif_timer = 0;
317 334
318 if (cb) { 335 if (cb) {
319 timeout = cb->read_time + 336 timeout = cb->read_time + msecs_to_jiffies(IAMTHIF_READ_TIMER);
320 msecs_to_jiffies(IAMTHIF_READ_TIMER);
321 dev_dbg(&dev->pdev->dev, "amthi timeout = %lud\n", 337 dev_dbg(&dev->pdev->dev, "amthi timeout = %lud\n",
322 timeout); 338 timeout);
323 339
@@ -386,7 +402,7 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
386 if (cl->state != MEI_FILE_CONNECTED) 402 if (cl->state != MEI_FILE_CONNECTED)
387 return -ENODEV; 403 return -ENODEV;
388 404
389 if (dev->mei_state != MEI_ENABLED) 405 if (dev->dev_state != MEI_DEV_ENABLED)
390 return -ENODEV; 406 return -ENODEV;
391 407
392 dev_dbg(&dev->pdev->dev, "check if read is pending.\n"); 408 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)
401 417
402 dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n", 418 dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n",
403 cl->host_client_id, cl->me_client_id); 419 cl->host_client_id, cl->me_client_id);
404 420 i = mei_me_cl_by_id(dev, cl->me_client_id);
405 for (i = 0; i < dev->me_clients_num; i++) { 421 if (i < 0) {
406 if (dev->me_clients[i].client_id == cl->me_client_id)
407 break;
408
409 }
410
411 if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
412 rets = -ENODEV;
413 goto unlock;
414 }
415
416 if (i == dev->me_clients_num) {
417 rets = -ENODEV; 422 rets = -ENODEV;
418 goto unlock; 423 goto unlock;
419 } 424 }