diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2012-07-23 07:05:39 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-16 12:40:28 -0400 |
commit | 07b509b7943e5594f3f228e5b62a49cf6a033709 (patch) | |
tree | 6271fdff08b54ab605cbc666cdcc054d41d3e44a /drivers | |
parent | 0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (diff) |
mei: revamp me client search function
me client search functions returns index
into me_client array according me client id
or me client uuid.
1. Add common prefix for the functions mei_me_cl_<>
2. create new function mei_me_cl_by_id that wraps open
coded loops scattered over the code
3. rename mei_find_me_client_index to mei_me_cl_by_uuid
4. rename mei_find_me_client_update_filext to
mei_me_cl_update_filext and updates its parameter names
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/misc/mei/init.c | 38 | ||||
-rw-r--r-- | drivers/misc/mei/iorw.c | 55 | ||||
-rw-r--r-- | drivers/misc/mei/main.c | 31 | ||||
-rw-r--r-- | drivers/misc/mei/mei_dev.h | 8 | ||||
-rw-r--r-- | drivers/misc/mei/wd.c | 2 |
5 files changed, 60 insertions, 74 deletions
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c index e77f86e69fb5..58b3bf47c8eb 100644 --- a/drivers/misc/mei/init.c +++ b/drivers/misc/mei/init.c | |||
@@ -522,12 +522,12 @@ void mei_cl_init(struct mei_cl *priv, struct mei_device *dev) | |||
522 | priv->dev = dev; | 522 | priv->dev = dev; |
523 | } | 523 | } |
524 | 524 | ||
525 | int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid) | 525 | int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid) |
526 | { | 526 | { |
527 | int i, res = -1; | 527 | int i, res = -ENOENT; |
528 | 528 | ||
529 | for (i = 0; i < dev->me_clients_num; ++i) | 529 | for (i = 0; i < dev->me_clients_num; ++i) |
530 | if (uuid_le_cmp(cuuid, | 530 | if (uuid_le_cmp(*cuuid, |
531 | dev->me_clients[i].props.protocol_name) == 0) { | 531 | dev->me_clients[i].props.protocol_name) == 0) { |
532 | res = i; | 532 | res = i; |
533 | break; | 533 | break; |
@@ -538,35 +538,35 @@ int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid) | |||
538 | 538 | ||
539 | 539 | ||
540 | /** | 540 | /** |
541 | * mei_find_me_client_update_filext - searches for ME client guid | 541 | * mei_me_cl_update_filext - searches for ME client guid |
542 | * sets client_id in mei_file_private if found | 542 | * sets client_id in mei_file_private if found |
543 | * @dev: the device structure | 543 | * @dev: the device structure |
544 | * @priv: private file structure to set client_id in | 544 | * @cl: private file structure to set client_id in |
545 | * @cguid: searched guid of ME client | 545 | * @cuuid: searched uuid of ME client |
546 | * @client_id: id of host client to be set in file private structure | 546 | * @client_id: id of host client to be set in file private structure |
547 | * | 547 | * |
548 | * returns ME client index | 548 | * returns ME client index |
549 | */ | 549 | */ |
550 | u8 mei_find_me_client_update_filext(struct mei_device *dev, struct mei_cl *priv, | 550 | int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl, |
551 | const uuid_le *cguid, u8 client_id) | 551 | const uuid_le *cuuid, u8 host_cl_id) |
552 | { | 552 | { |
553 | int i; | 553 | int i; |
554 | 554 | ||
555 | if (!dev || !priv || !cguid) | 555 | if (!dev || !cl || !cuuid) |
556 | return 0; | 556 | return -EINVAL; |
557 | 557 | ||
558 | /* check for valid client id */ | 558 | /* check for valid client id */ |
559 | i = mei_find_me_client_index(dev, *cguid); | 559 | i = mei_me_cl_by_uuid(dev, cuuid); |
560 | if (i >= 0) { | 560 | if (i >= 0) { |
561 | priv->me_client_id = dev->me_clients[i].client_id; | 561 | cl->me_client_id = dev->me_clients[i].client_id; |
562 | priv->state = MEI_FILE_CONNECTING; | 562 | cl->state = MEI_FILE_CONNECTING; |
563 | priv->host_client_id = client_id; | 563 | cl->host_client_id = host_cl_id; |
564 | 564 | ||
565 | list_add_tail(&priv->link, &dev->file_list); | 565 | list_add_tail(&cl->link, &dev->file_list); |
566 | return (u8)i; | 566 | return (u8)i; |
567 | } | 567 | } |
568 | 568 | ||
569 | return 0; | 569 | return -ENOENT; |
570 | } | 570 | } |
571 | 571 | ||
572 | /** | 572 | /** |
@@ -577,16 +577,16 @@ u8 mei_find_me_client_update_filext(struct mei_device *dev, struct mei_cl *priv, | |||
577 | */ | 577 | */ |
578 | void mei_host_init_iamthif(struct mei_device *dev) | 578 | void mei_host_init_iamthif(struct mei_device *dev) |
579 | { | 579 | { |
580 | u8 i; | 580 | int i; |
581 | unsigned char *msg_buf; | 581 | unsigned char *msg_buf; |
582 | 582 | ||
583 | mei_cl_init(&dev->iamthif_cl, dev); | 583 | mei_cl_init(&dev->iamthif_cl, dev); |
584 | dev->iamthif_cl.state = MEI_FILE_DISCONNECTED; | 584 | dev->iamthif_cl.state = MEI_FILE_DISCONNECTED; |
585 | 585 | ||
586 | /* find ME amthi client */ | 586 | /* find ME amthi client */ |
587 | i = mei_find_me_client_update_filext(dev, &dev->iamthif_cl, | 587 | i = mei_me_cl_update_filext(dev, &dev->iamthif_cl, |
588 | &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID); | 588 | &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID); |
589 | if (dev->iamthif_cl.state != MEI_FILE_CONNECTING) { | 589 | if (i < 0) { |
590 | dev_dbg(&dev->pdev->dev, "failed to find iamthif client.\n"); | 590 | dev_dbg(&dev->pdev->dev, "failed to find iamthif client.\n"); |
591 | return; | 591 | return; |
592 | } | 592 | } |
diff --git a/drivers/misc/mei/iorw.c b/drivers/misc/mei/iorw.c index 50f52e21f587..9187d852ef9c 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 | ||
52 | int 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 |
@@ -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 | ||
@@ -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 | } |
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index 092330208869..b0903bd44bf7 100644 --- a/drivers/misc/mei/main.c +++ b/drivers/misc/mei/main.c | |||
@@ -393,10 +393,9 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, | |||
393 | 393 | ||
394 | if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) { | 394 | if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) { |
395 | /* Do not allow to read watchdog client */ | 395 | /* Do not allow to read watchdog client */ |
396 | i = mei_find_me_client_index(dev, mei_wd_guid); | 396 | i = mei_me_cl_by_uuid(dev, &mei_wd_guid); |
397 | if (i >= 0) { | 397 | if (i >= 0) { |
398 | struct mei_me_client *me_client = &dev->me_clients[i]; | 398 | struct mei_me_client *me_client = &dev->me_clients[i]; |
399 | |||
400 | if (cl->me_client_id == me_client->client_id) { | 399 | if (cl->me_client_id == me_client->client_id) { |
401 | rets = -EBADF; | 400 | rets = -EBADF; |
402 | goto out; | 401 | goto out; |
@@ -620,22 +619,12 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, | |||
620 | rets = -ENODEV; | 619 | rets = -ENODEV; |
621 | goto unlock_dev; | 620 | goto unlock_dev; |
622 | } | 621 | } |
623 | for (i = 0; i < dev->me_clients_num; i++) { | 622 | i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id); |
624 | if (dev->me_clients[i].client_id == | 623 | if (i < 0) { |
625 | dev->iamthif_cl.me_client_id) | ||
626 | break; | ||
627 | } | ||
628 | |||
629 | if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) { | ||
630 | rets = -ENODEV; | 624 | rets = -ENODEV; |
631 | goto unlock_dev; | 625 | goto unlock_dev; |
632 | } | 626 | } |
633 | if (i == dev->me_clients_num || | 627 | if (length > dev->me_clients[i].props.max_msg_length || |
634 | (dev->me_clients[i].client_id != | ||
635 | dev->iamthif_cl.me_client_id)) { | ||
636 | rets = -ENODEV; | ||
637 | goto unlock_dev; | ||
638 | } else if (length > dev->me_clients[i].props.max_msg_length || | ||
639 | length <= 0) { | 628 | length <= 0) { |
640 | rets = -EMSGSIZE; | 629 | rets = -EMSGSIZE; |
641 | goto unlock_dev; | 630 | goto unlock_dev; |
@@ -688,16 +677,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, | |||
688 | cl->me_client_id); | 677 | cl->me_client_id); |
689 | goto unlock_dev; | 678 | goto unlock_dev; |
690 | } | 679 | } |
691 | for (i = 0; i < dev->me_clients_num; i++) { | 680 | i = mei_me_cl_by_id(dev, cl->me_client_id); |
692 | if (dev->me_clients[i].client_id == | 681 | if (i < 0) { |
693 | cl->me_client_id) | ||
694 | break; | ||
695 | } | ||
696 | if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) { | ||
697 | rets = -ENODEV; | ||
698 | goto unlock_dev; | ||
699 | } | ||
700 | if (i == dev->me_clients_num) { | ||
701 | rets = -ENODEV; | 682 | rets = -ENODEV; |
702 | goto unlock_dev; | 683 | goto unlock_dev; |
703 | } | 684 | } |
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index d61c4ddfc80c..1ff1fc678fb3 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h | |||
@@ -279,9 +279,10 @@ void mei_host_init_iamthif(struct mei_device *dev); | |||
279 | void mei_allocate_me_clients_storage(struct mei_device *dev); | 279 | void mei_allocate_me_clients_storage(struct mei_device *dev); |
280 | 280 | ||
281 | 281 | ||
282 | u8 mei_find_me_client_update_filext(struct mei_device *dev, | 282 | int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl, |
283 | struct mei_cl *priv, | 283 | const uuid_le *cguid, u8 host_client_id); |
284 | const uuid_le *cguid, u8 client_id); | 284 | int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid); |
285 | int mei_me_cl_by_id(struct mei_device *dev, u8 client_id); | ||
285 | 286 | ||
286 | /* | 287 | /* |
287 | * MEI IO List Functions | 288 | * MEI IO List Functions |
@@ -348,7 +349,6 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev); | |||
348 | 349 | ||
349 | void mei_free_cb_private(struct mei_cl_cb *priv_cb); | 350 | void mei_free_cb_private(struct mei_cl_cb *priv_cb); |
350 | 351 | ||
351 | int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid); | ||
352 | 352 | ||
353 | /* | 353 | /* |
354 | * Register Access Function | 354 | * Register Access Function |
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c index 5133fd77b91c..912319e4fa90 100644 --- a/drivers/misc/mei/wd.c +++ b/drivers/misc/mei/wd.c | |||
@@ -69,7 +69,7 @@ int mei_wd_host_init(struct mei_device *dev) | |||
69 | dev->wd_timeout = AMT_WD_DEFAULT_TIMEOUT; | 69 | dev->wd_timeout = AMT_WD_DEFAULT_TIMEOUT; |
70 | 70 | ||
71 | /* find ME WD client */ | 71 | /* find ME WD client */ |
72 | mei_find_me_client_update_filext(dev, &dev->wd_cl, | 72 | mei_me_cl_update_filext(dev, &dev->wd_cl, |
73 | &mei_wd_guid, MEI_WD_HOST_CLIENT_ID); | 73 | &mei_wd_guid, MEI_WD_HOST_CLIENT_ID); |
74 | 74 | ||
75 | dev_dbg(&dev->pdev->dev, "wd: check client\n"); | 75 | dev_dbg(&dev->pdev->dev, "wd: check client\n"); |