diff options
author | Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> | 2013-04-03 02:02:04 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-04-11 10:29:02 -0400 |
commit | 4231604b3e867bd8cff7ae81a3068615954aa1c8 (patch) | |
tree | bb65ac126c0aab904a455efb52f8ba38d1126aed /drivers/nfc | |
parent | 0ce1fbdd609875f523de0d8179c6f4f8500807c7 (diff) |
NFC: pn533: Optimise issued cmd context tracking
Use struct pn533_cmd instead of pn533_send_async_complete_arg
to track the context of the issued cmd.
This way pn533_send_async_complete_arg struct is no needed
anymore. Just move issuer complete callback to pn533_cmd struct.
Signed-off-by: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/nfc')
-rw-r--r-- | drivers/nfc/pn533.c | 87 |
1 files changed, 35 insertions, 52 deletions
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c index 48902e58cacb..2f39209507d4 100644 --- a/drivers/nfc/pn533.c +++ b/drivers/nfc/pn533.c | |||
@@ -363,7 +363,8 @@ struct pn533_cmd { | |||
363 | struct sk_buff *req; | 363 | struct sk_buff *req; |
364 | struct sk_buff *resp; | 364 | struct sk_buff *resp; |
365 | int resp_len; | 365 | int resp_len; |
366 | void *arg; | 366 | pn533_send_async_complete_t complete_cb; |
367 | void *complete_cb_context; | ||
367 | }; | 368 | }; |
368 | 369 | ||
369 | struct pn533_std_frame { | 370 | struct pn533_std_frame { |
@@ -691,39 +692,32 @@ static void pn533_build_cmd_frame(struct pn533 *dev, u8 cmd_code, | |||
691 | ops->tx_frame_finish(skb->data); | 692 | ops->tx_frame_finish(skb->data); |
692 | } | 693 | } |
693 | 694 | ||
694 | struct pn533_send_async_complete_arg { | 695 | static int pn533_send_async_complete(struct pn533 *dev, void *arg, int status) |
695 | pn533_send_async_complete_t complete_cb; | ||
696 | void *complete_cb_context; | ||
697 | struct sk_buff *resp; | ||
698 | struct sk_buff *req; | ||
699 | }; | ||
700 | |||
701 | static int pn533_send_async_complete(struct pn533 *dev, void *_arg, int status) | ||
702 | { | 696 | { |
703 | struct pn533_send_async_complete_arg *arg = _arg; | 697 | struct pn533_cmd *cmd = arg; |
704 | 698 | ||
705 | struct sk_buff *req = arg->req; | 699 | struct sk_buff *req = cmd->req; |
706 | struct sk_buff *resp = arg->resp; | 700 | struct sk_buff *resp = cmd->resp; |
707 | 701 | ||
708 | int rc; | 702 | int rc; |
709 | 703 | ||
710 | dev_kfree_skb(req); | 704 | dev_kfree_skb(req); |
711 | 705 | ||
712 | if (status < 0) { | 706 | if (status < 0) { |
713 | arg->complete_cb(dev, arg->complete_cb_context, | 707 | rc = cmd->complete_cb(dev, cmd->complete_cb_context, |
714 | ERR_PTR(status)); | 708 | ERR_PTR(status)); |
715 | dev_kfree_skb(resp); | 709 | dev_kfree_skb(resp); |
716 | kfree(arg); | 710 | kfree(cmd); |
717 | return status; | 711 | return rc; |
718 | } | 712 | } |
719 | 713 | ||
720 | skb_put(resp, dev->ops->rx_frame_size(resp->data)); | 714 | skb_put(resp, dev->ops->rx_frame_size(resp->data)); |
721 | skb_pull(resp, dev->ops->rx_header_len); | 715 | skb_pull(resp, dev->ops->rx_header_len); |
722 | skb_trim(resp, resp->len - dev->ops->rx_tail_len); | 716 | skb_trim(resp, resp->len - dev->ops->rx_tail_len); |
723 | 717 | ||
724 | rc = arg->complete_cb(dev, arg->complete_cb_context, resp); | 718 | rc = cmd->complete_cb(dev, cmd->complete_cb_context, resp); |
725 | 719 | ||
726 | kfree(arg); | 720 | kfree(cmd); |
727 | return rc; | 721 | return rc; |
728 | } | 722 | } |
729 | 723 | ||
@@ -734,19 +728,20 @@ static int __pn533_send_async(struct pn533 *dev, u8 cmd_code, | |||
734 | void *complete_cb_context) | 728 | void *complete_cb_context) |
735 | { | 729 | { |
736 | struct pn533_cmd *cmd; | 730 | struct pn533_cmd *cmd; |
737 | struct pn533_send_async_complete_arg *arg; | ||
738 | int rc = 0; | 731 | int rc = 0; |
739 | 732 | ||
740 | nfc_dev_dbg(&dev->interface->dev, "Sending command 0x%x", cmd_code); | 733 | nfc_dev_dbg(&dev->interface->dev, "Sending command 0x%x", cmd_code); |
741 | 734 | ||
742 | arg = kzalloc(sizeof(*arg), GFP_KERNEL); | 735 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
743 | if (!arg) | 736 | if (!cmd) |
744 | return -ENOMEM; | 737 | return -ENOMEM; |
745 | 738 | ||
746 | arg->complete_cb = complete_cb; | 739 | cmd->cmd_code = cmd_code; |
747 | arg->complete_cb_context = complete_cb_context; | 740 | cmd->req = req; |
748 | arg->resp = resp; | 741 | cmd->resp = resp; |
749 | arg->req = req; | 742 | cmd->resp_len = resp_len; |
743 | cmd->complete_cb = complete_cb; | ||
744 | cmd->complete_cb_context = complete_cb_context; | ||
750 | 745 | ||
751 | pn533_build_cmd_frame(dev, cmd_code, req); | 746 | pn533_build_cmd_frame(dev, cmd_code, req); |
752 | 747 | ||
@@ -754,7 +749,7 @@ static int __pn533_send_async(struct pn533 *dev, u8 cmd_code, | |||
754 | 749 | ||
755 | if (!dev->cmd_pending) { | 750 | if (!dev->cmd_pending) { |
756 | rc = __pn533_send_frame_async(dev, req, resp, resp_len, | 751 | rc = __pn533_send_frame_async(dev, req, resp, resp_len, |
757 | pn533_send_async_complete, arg); | 752 | pn533_send_async_complete, cmd); |
758 | if (rc) | 753 | if (rc) |
759 | goto error; | 754 | goto error; |
760 | 755 | ||
@@ -765,25 +760,13 @@ static int __pn533_send_async(struct pn533 *dev, u8 cmd_code, | |||
765 | nfc_dev_dbg(&dev->interface->dev, "%s Queueing command 0x%x", __func__, | 760 | nfc_dev_dbg(&dev->interface->dev, "%s Queueing command 0x%x", __func__, |
766 | cmd_code); | 761 | cmd_code); |
767 | 762 | ||
768 | cmd = kzalloc(sizeof(struct pn533_cmd), GFP_KERNEL); | ||
769 | if (!cmd) { | ||
770 | rc = -ENOMEM; | ||
771 | goto error; | ||
772 | } | ||
773 | |||
774 | INIT_LIST_HEAD(&cmd->queue); | 763 | INIT_LIST_HEAD(&cmd->queue); |
775 | cmd->cmd_code = cmd_code; | ||
776 | cmd->req = req; | ||
777 | cmd->resp = resp; | ||
778 | cmd->resp_len = resp_len; | ||
779 | cmd->arg = arg; | ||
780 | |||
781 | list_add_tail(&cmd->queue, &dev->cmd_queue); | 764 | list_add_tail(&cmd->queue, &dev->cmd_queue); |
782 | 765 | ||
783 | goto unlock; | 766 | goto unlock; |
784 | 767 | ||
785 | error: | 768 | error: |
786 | kfree(arg); | 769 | kfree(cmd); |
787 | unlock: | 770 | unlock: |
788 | mutex_unlock(&dev->cmd_lock); | 771 | mutex_unlock(&dev->cmd_lock); |
789 | return rc; | 772 | return rc; |
@@ -848,8 +831,8 @@ static int pn533_send_cmd_direct_async(struct pn533 *dev, u8 cmd_code, | |||
848 | pn533_send_async_complete_t complete_cb, | 831 | pn533_send_async_complete_t complete_cb, |
849 | void *complete_cb_context) | 832 | void *complete_cb_context) |
850 | { | 833 | { |
851 | struct pn533_send_async_complete_arg *arg; | ||
852 | struct sk_buff *resp; | 834 | struct sk_buff *resp; |
835 | struct pn533_cmd *cmd; | ||
853 | int rc; | 836 | int rc; |
854 | int resp_len = dev->ops->rx_header_len + | 837 | int resp_len = dev->ops->rx_header_len + |
855 | dev->ops->max_payload_len + | 838 | dev->ops->max_payload_len + |
@@ -859,24 +842,26 @@ static int pn533_send_cmd_direct_async(struct pn533 *dev, u8 cmd_code, | |||
859 | if (!resp) | 842 | if (!resp) |
860 | return -ENOMEM; | 843 | return -ENOMEM; |
861 | 844 | ||
862 | arg = kzalloc(sizeof(*arg), GFP_KERNEL); | 845 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
863 | if (!arg) { | 846 | if (!cmd) { |
864 | dev_kfree_skb(resp); | 847 | dev_kfree_skb(resp); |
865 | return -ENOMEM; | 848 | return -ENOMEM; |
866 | } | 849 | } |
867 | 850 | ||
868 | arg->complete_cb = complete_cb; | 851 | cmd->cmd_code = cmd_code; |
869 | arg->complete_cb_context = complete_cb_context; | 852 | cmd->req = req; |
870 | arg->resp = resp; | 853 | cmd->resp = resp; |
871 | arg->req = req; | 854 | cmd->resp_len = resp_len; |
855 | cmd->complete_cb = complete_cb; | ||
856 | cmd->complete_cb_context = complete_cb_context; | ||
872 | 857 | ||
873 | pn533_build_cmd_frame(dev, cmd_code, req); | 858 | pn533_build_cmd_frame(dev, cmd_code, req); |
874 | 859 | ||
875 | rc = __pn533_send_frame_async(dev, req, resp, resp_len, | 860 | rc = __pn533_send_frame_async(dev, req, resp, resp_len, |
876 | pn533_send_async_complete, arg); | 861 | pn533_send_async_complete, cmd); |
877 | if (rc < 0) { | 862 | if (rc < 0) { |
878 | dev_kfree_skb(resp); | 863 | dev_kfree_skb(resp); |
879 | kfree(arg); | 864 | kfree(cmd); |
880 | } | 865 | } |
881 | 866 | ||
882 | return rc; | 867 | return rc; |
@@ -903,14 +888,12 @@ static void pn533_wq_cmd(struct work_struct *work) | |||
903 | mutex_unlock(&dev->cmd_lock); | 888 | mutex_unlock(&dev->cmd_lock); |
904 | 889 | ||
905 | rc = __pn533_send_frame_async(dev, cmd->req, cmd->resp, cmd->resp_len, | 890 | rc = __pn533_send_frame_async(dev, cmd->req, cmd->resp, cmd->resp_len, |
906 | pn533_send_async_complete, cmd->arg); | 891 | pn533_send_async_complete, cmd); |
907 | if (rc < 0) { | 892 | if (rc < 0) { |
908 | dev_kfree_skb(cmd->req); | 893 | dev_kfree_skb(cmd->req); |
909 | dev_kfree_skb(cmd->resp); | 894 | dev_kfree_skb(cmd->resp); |
910 | kfree(cmd->arg); | 895 | kfree(cmd); |
911 | } | 896 | } |
912 | |||
913 | kfree(cmd); | ||
914 | } | 897 | } |
915 | 898 | ||
916 | struct pn533_sync_cmd_response { | 899 | struct pn533_sync_cmd_response { |