aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-11-01 15:17:13 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-01 15:31:17 -0400
commitb0d0cf77e72a9d233015f8f21e9dfc9d9b5d0711 (patch)
tree646b3597480dff4b952899465f84c7ea5d0379f1 /drivers
parent3321e738d6f0a82b2c19f9d5890f304dab1e5357 (diff)
mei: mei_write: revamp function flow
Use goto statement for error handling instead of deeper if constructs and rename label 'unlock_dev' to more appropriate 'err' 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/main.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index ed4943f6b6c2..7a03d772fb11 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -543,24 +543,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
543 543
544 if (dev->dev_state != MEI_DEV_ENABLED) { 544 if (dev->dev_state != MEI_DEV_ENABLED) {
545 rets = -ENODEV; 545 rets = -ENODEV;
546 goto unlock_dev; 546 goto err;
547 } 547 }
548 548
549 i = mei_me_cl_by_id(dev, cl->me_client_id); 549 i = mei_me_cl_by_id(dev, cl->me_client_id);
550 if (i < 0) { 550 if (i < 0) {
551 rets = -ENODEV; 551 rets = -ENODEV;
552 goto unlock_dev; 552 goto err;
553 } 553 }
554 if (length > dev->me_clients[i].props.max_msg_length || length <= 0) { 554 if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
555 rets = -EMSGSIZE; 555 rets = -EMSGSIZE;
556 goto unlock_dev; 556 goto err;
557 } 557 }
558 558
559 if (cl->state != MEI_FILE_CONNECTED) { 559 if (cl->state != MEI_FILE_CONNECTED) {
560 rets = -ENODEV; 560 rets = -ENODEV;
561 dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d", 561 dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
562 cl->host_client_id, cl->me_client_id); 562 cl->host_client_id, cl->me_client_id);
563 goto unlock_dev; 563 goto err;
564 } 564 }
565 if (cl == &dev->iamthif_cl) { 565 if (cl == &dev->iamthif_cl) {
566 write_cb = find_amthi_read_list_entry(dev, file); 566 write_cb = find_amthi_read_list_entry(dev, file);
@@ -599,17 +599,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
599 if (!write_cb) { 599 if (!write_cb) {
600 dev_err(&dev->pdev->dev, "write cb allocation failed\n"); 600 dev_err(&dev->pdev->dev, "write cb allocation failed\n");
601 rets = -ENOMEM; 601 rets = -ENOMEM;
602 goto unlock_dev; 602 goto err;
603 } 603 }
604 rets = mei_io_cb_alloc_req_buf(write_cb, length); 604 rets = mei_io_cb_alloc_req_buf(write_cb, length);
605 if (rets) 605 if (rets)
606 goto unlock_dev; 606 goto err;
607 607
608 dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length); 608 dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length);
609 609
610 rets = copy_from_user(write_cb->request_buffer.data, ubuf, length); 610 rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
611 if (rets) 611 if (rets)
612 goto unlock_dev; 612 goto err;
613 613
614 cl->sm_state = 0; 614 cl->sm_state = 0;
615 if (length == 4 && 615 if (length == 4 &&
@@ -624,7 +624,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
624 if (cl == &dev->iamthif_cl) { 624 if (cl == &dev->iamthif_cl) {
625 rets = mei_io_cb_alloc_resp_buf(write_cb, dev->iamthif_mtu); 625 rets = mei_io_cb_alloc_resp_buf(write_cb, dev->iamthif_mtu);
626 if (rets) 626 if (rets)
627 goto unlock_dev; 627 goto err;
628 628
629 write_cb->major_file_operations = MEI_IOCTL; 629 write_cb->major_file_operations = MEI_IOCTL;
630 630
@@ -641,7 +641,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
641 if (rets) { 641 if (rets) {
642 dev_err(&dev->pdev->dev, "amthi write failed with status = %d\n", 642 dev_err(&dev->pdev->dev, "amthi write failed with status = %d\n",
643 rets); 643 rets);
644 goto unlock_dev; 644 goto err;
645 } 645 }
646 } 646 }
647 mutex_unlock(&dev->device_lock); 647 mutex_unlock(&dev->device_lock);
@@ -654,51 +654,51 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
654 cl->host_client_id, cl->me_client_id); 654 cl->host_client_id, cl->me_client_id);
655 rets = mei_flow_ctrl_creds(dev, cl); 655 rets = mei_flow_ctrl_creds(dev, cl);
656 if (rets < 0) 656 if (rets < 0)
657 goto unlock_dev; 657 goto err;
658 658
659 if (rets && dev->mei_host_buffer_is_empty) { 659 if (rets == 0 || dev->mei_host_buffer_is_empty == false) {
660 rets = 0; 660 write_cb->buf_idx = 0;
661 dev->mei_host_buffer_is_empty = false; 661 mei_hdr.msg_complete = 0;
662 if (length > mei_hbuf_max_data(dev)) {
663 mei_hdr.length = mei_hbuf_max_data(dev);
664 mei_hdr.msg_complete = 0;
665 } else {
666 mei_hdr.length = length;
667 mei_hdr.msg_complete = 1;
668 }
669 mei_hdr.host_addr = cl->host_client_id;
670 mei_hdr.me_addr = cl->me_client_id;
671 mei_hdr.reserved = 0;
672 dev_dbg(&dev->pdev->dev, "call mei_write_message header=%08x.\n",
673 *((u32 *) &mei_hdr));
674 if (mei_write_message(dev, &mei_hdr,
675 (unsigned char *) (write_cb->request_buffer.data),
676 mei_hdr.length)) {
677 rets = -ENODEV;
678 goto unlock_dev;
679 }
680 cl->writing_state = MEI_WRITING; 662 cl->writing_state = MEI_WRITING;
681 write_cb->buf_idx = mei_hdr.length; 663 goto out;
682 if (mei_hdr.msg_complete) { 664 }
683 if (mei_flow_ctrl_reduce(dev, cl)) {
684 rets = -ENODEV;
685 goto unlock_dev;
686 }
687 list_add_tail(&write_cb->list, &dev->write_waiting_list.list);
688 } else {
689 list_add_tail(&write_cb->list, &dev->write_list.list);
690 }
691 665
666 dev->mei_host_buffer_is_empty = false;
667 if (length > mei_hbuf_max_data(dev)) {
668 mei_hdr.length = mei_hbuf_max_data(dev);
669 mei_hdr.msg_complete = 0;
692 } else { 670 } else {
671 mei_hdr.length = length;
672 mei_hdr.msg_complete = 1;
673 }
674 mei_hdr.host_addr = cl->host_client_id;
675 mei_hdr.me_addr = cl->me_client_id;
676 mei_hdr.reserved = 0;
677 dev_dbg(&dev->pdev->dev, "call mei_write_message header=%08x.\n",
678 *((u32 *) &mei_hdr));
679 if (mei_write_message(dev, &mei_hdr,
680 write_cb->request_buffer.data, mei_hdr.length)) {
681 rets = -ENODEV;
682 goto err;
683 }
684 cl->writing_state = MEI_WRITING;
685 write_cb->buf_idx = mei_hdr.length;
693 686
694 write_cb->buf_idx = 0; 687out:
695 cl->writing_state = MEI_WRITING; 688 if (mei_hdr.msg_complete) {
689 if (mei_flow_ctrl_reduce(dev, cl)) {
690 rets = -ENODEV;
691 goto err;
692 }
693 list_add_tail(&write_cb->list, &dev->write_waiting_list.list);
694 } else {
696 list_add_tail(&write_cb->list, &dev->write_list.list); 695 list_add_tail(&write_cb->list, &dev->write_list.list);
697 } 696 }
697
698 mutex_unlock(&dev->device_lock); 698 mutex_unlock(&dev->device_lock);
699 return length; 699 return length;
700 700
701unlock_dev: 701err:
702 mutex_unlock(&dev->device_lock); 702 mutex_unlock(&dev->device_lock);
703 mei_io_cb_free(write_cb); 703 mei_io_cb_free(write_cb);
704 return rets; 704 return rets;