aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/nfc/st21nfca
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-10-05 21:34:39 -0400
committerDavid S. Miller <davem@davemloft.net>2014-10-05 21:34:39 -0400
commita4b4a2b7f98a45c71a906b1126cabea6446a9905 (patch)
tree0d501e78aeb9df90172a9435d673f31bf89290eb /drivers/nfc/st21nfca
parent61b37d2f54961b336a47a501e797a05df20c3b30 (diff)
parent3f08e47291879fb047d7d4464d2beaedfea4eb63 (diff)
Merge tag 'master-2014-10-02' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next
John W. Linville says: ==================== pull request: wireless-next 2014-10-03 Please pull tihs batch of updates intended for the 3.18 stream! For the iwlwifi bits, Emmanuel says: "I have here a few things that depend on the latest mac80211's changes: RRM, TPC, Quiet Period etc... Eyal keeps improving our rate control and we have a new device ID. This last patch should probably have gone to wireless.git, but at that stage, I preferred to send it to -next and CC stable." For (most of) the Atheros bits, Kalle says: "The only new feature is testmode support from me. Ben added a new method to crash the firmware with an assert for debug purposes. As usual, we have lots of smaller fixes from Michal. Matteo fixed a Kconfig dependency with debugfs. I fixed some warnings recently added to checkpatch." For the NFC bits, Samuel says: "We've had major updates for TI and ST Microelectronics drivers, and a few NCI related changes. For TI's trf7970a driver: - Target mode support for trf7970a - Suspend/resume support for trf7970a - DT properties additions to handle different quirks - A bunch of fixes for smartphone IOP related issues For ST Microelectronics' ST21NFCA and ST21NFCB drivers: - ISO15693 support for st21nfcb - checkpatch and sparse related warning fixes - Code cleanups and a few minor fixes Finally, Marvell added ISO15693 support to the NCI stack, together with a couple of NCI fixes." For the Bluetooth bits, Johan says: "This 3.18 pull request replaces the one I did on Monday ("bluetooth-next 2014-09-22", which hasn't been pulled yet). The additions since the last request are: - SCO connection fix for devices not supporting eSCO - Cleanups regarding the SCO establishment logic - Remove unnecessary return value from logging functions - Header compression fix for 6lowpan - Cleanups to the ieee802154/mrf24j40 driver Here's a copy from previous request that this one replaces: ' Here are some more patches for 3.18. They include various fixes to the btusb HCI driver, a fix for LE SMP, as well as adding Jukka to the MAINTAINERS file for generic 6LoWPAN (as requested by Alexander Aring). I've held on to this pull request a bit since we were waiting for a SCO related fix to get sorted out first. However, since the merge window is getting closer I decided not to wait for it. If we do get the fix sorted out there'll probably be a second small pull request later this week. '" And, "Unless 3.17 gets delayed this will probably be our last -next pull request for 3.18. We've got: - New Marvell hardware supportr - Multicast support for 6lowpan - Several of 6lowpan fixes & cleanups - Fix for a (false-positive) lockdep warning in L2CAP - Minor btusb cleanup" On top of all that comes the usual sort of updates to ath5k, ath9k, ath10k, brcmfmac, mwifiex, and wil6210. This time around there are also a number of rtlwifi updates to enable some new hardware and to reconcile the in-kernel drivers with some newer releases of the Realtek vendor drivers. Also of note is some device tree work for the bcma bus. Please let me know if there are problems! ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/nfc/st21nfca')
-rw-r--r--drivers/nfc/st21nfca/i2c.c34
-rw-r--r--drivers/nfc/st21nfca/st21nfca.c59
-rw-r--r--drivers/nfc/st21nfca/st21nfca.h21
-rw-r--r--drivers/nfc/st21nfca/st21nfca_dep.c59
4 files changed, 72 insertions, 101 deletions
diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c
index ff31939978ae..0ea756b77519 100644
--- a/drivers/nfc/st21nfca/i2c.c
+++ b/drivers/nfc/st21nfca/i2c.c
@@ -271,6 +271,7 @@ static int st21nfca_hci_i2c_write(void *phy_id, struct sk_buff *skb)
271static int get_frame_size(u8 *buf, int buflen) 271static int get_frame_size(u8 *buf, int buflen)
272{ 272{
273 int len = 0; 273 int len = 0;
274
274 if (buf[len + 1] == ST21NFCA_SOF_EOF) 275 if (buf[len + 1] == ST21NFCA_SOF_EOF)
275 return 0; 276 return 0;
276 277
@@ -311,6 +312,7 @@ static int check_crc(u8 *buf, int buflen)
311static int st21nfca_hci_i2c_repack(struct sk_buff *skb) 312static int st21nfca_hci_i2c_repack(struct sk_buff *skb)
312{ 313{
313 int i, j, r, size; 314 int i, j, r, size;
315
314 if (skb->len < 1 || (skb->len > 1 && skb->data[1] != 0)) 316 if (skb->len < 1 || (skb->len > 1 && skb->data[1] != 0))
315 return -EBADMSG; 317 return -EBADMSG;
316 318
@@ -525,24 +527,19 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)
525 } 527 }
526 528
527 /* GPIO request and configuration */ 529 /* GPIO request and configuration */
528 r = devm_gpio_request(&client->dev, gpio, "clf_enable"); 530 r = devm_gpio_request_one(&client->dev, gpio, GPIOF_OUT_INIT_HIGH,
531 "clf_enable");
529 if (r) { 532 if (r) {
530 nfc_err(&client->dev, "Failed to request enable pin\n"); 533 nfc_err(&client->dev, "Failed to request enable pin\n");
531 return -ENODEV; 534 return -ENODEV;
532 } 535 }
533 536
534 r = gpio_direction_output(gpio, 1);
535 if (r) {
536 nfc_err(&client->dev, "Failed to set enable pin direction as output\n");
537 return -ENODEV;
538 }
539 phy->gpio_ena = gpio; 537 phy->gpio_ena = gpio;
540 538
541 /* IRQ */ 539 /* IRQ */
542 r = irq_of_parse_and_map(pp, 0); 540 r = irq_of_parse_and_map(pp, 0);
543 if (r < 0) { 541 if (r < 0) {
544 nfc_err(&client->dev, 542 nfc_err(&client->dev, "Unable to get irq, error: %d\n", r);
545 "Unable to get irq, error: %d\n", r);
546 return r; 543 return r;
547 } 544 }
548 545
@@ -576,32 +573,20 @@ static int st21nfca_hci_i2c_request_resources(struct i2c_client *client)
576 phy->gpio_ena = pdata->gpio_ena; 573 phy->gpio_ena = pdata->gpio_ena;
577 phy->irq_polarity = pdata->irq_polarity; 574 phy->irq_polarity = pdata->irq_polarity;
578 575
579 r = devm_gpio_request(&client->dev, phy->gpio_irq, "wake_up"); 576 r = devm_gpio_request_one(&client->dev, phy->gpio_irq, GPIOF_IN,
577 "wake_up");
580 if (r) { 578 if (r) {
581 pr_err("%s : gpio_request failed\n", __FILE__); 579 pr_err("%s : gpio_request failed\n", __FILE__);
582 return -ENODEV; 580 return -ENODEV;
583 } 581 }
584 582
585 r = gpio_direction_input(phy->gpio_irq);
586 if (r) {
587 pr_err("%s : gpio_direction_input failed\n", __FILE__);
588 return -ENODEV;
589 }
590
591 if (phy->gpio_ena > 0) { 583 if (phy->gpio_ena > 0) {
592 r = devm_gpio_request(&client->dev, 584 r = devm_gpio_request_one(&client->dev, phy->gpio_ena,
593 phy->gpio_ena, "clf_enable"); 585 GPIOF_OUT_INIT_HIGH, "clf_enable");
594 if (r) { 586 if (r) {
595 pr_err("%s : ena gpio_request failed\n", __FILE__); 587 pr_err("%s : ena gpio_request failed\n", __FILE__);
596 return -ENODEV; 588 return -ENODEV;
597 } 589 }
598 r = gpio_direction_output(phy->gpio_ena, 1);
599
600 if (r) {
601 pr_err("%s : ena gpio_direction_output failed\n",
602 __FILE__);
603 return -ENODEV;
604 }
605 } 590 }
606 591
607 /* IRQ */ 592 /* IRQ */
@@ -711,7 +696,6 @@ static struct i2c_driver st21nfca_hci_i2c_driver = {
711 .driver = { 696 .driver = {
712 .owner = THIS_MODULE, 697 .owner = THIS_MODULE,
713 .name = ST21NFCA_HCI_I2C_DRIVER_NAME, 698 .name = ST21NFCA_HCI_I2C_DRIVER_NAME,
714 .owner = THIS_MODULE,
715 .of_match_table = of_match_ptr(of_st21nfca_i2c_match), 699 .of_match_table = of_match_ptr(of_st21nfca_i2c_match),
716 }, 700 },
717 .probe = st21nfca_hci_i2c_probe, 701 .probe = st21nfca_hci_i2c_probe,
diff --git a/drivers/nfc/st21nfca/st21nfca.c b/drivers/nfc/st21nfca/st21nfca.c
index a902b0551c86..a89e56c2c749 100644
--- a/drivers/nfc/st21nfca/st21nfca.c
+++ b/drivers/nfc/st21nfca/st21nfca.c
@@ -34,7 +34,7 @@
34#define ST21NFCA_RF_READER_CMD_PRESENCE_CHECK 0x30 34#define ST21NFCA_RF_READER_CMD_PRESENCE_CHECK 0x30
35 35
36#define ST21NFCA_RF_READER_ISO15693_GATE 0x12 36#define ST21NFCA_RF_READER_ISO15693_GATE 0x12
37#define ST21NFCA_RF_READER_ISO15693_INVENTORY 0x01 37#define ST21NFCA_RF_READER_ISO15693_INVENTORY 0x01
38 38
39/* 39/*
40 * Reader gate for communication with contact-less cards using Type A 40 * Reader gate for communication with contact-less cards using Type A
@@ -45,21 +45,42 @@
45#define ST21NFCA_RF_READER_14443_3_A_ATQA 0x03 45#define ST21NFCA_RF_READER_14443_3_A_ATQA 0x03
46#define ST21NFCA_RF_READER_14443_3_A_SAK 0x04 46#define ST21NFCA_RF_READER_14443_3_A_SAK 0x04
47 47
48#define ST21NFCA_RF_READER_F_DATARATE 0x01
49#define ST21NFCA_RF_READER_F_DATARATE_106 0x01
50#define ST21NFCA_RF_READER_F_DATARATE_212 0x02
51#define ST21NFCA_RF_READER_F_DATARATE_424 0x04
52#define ST21NFCA_RF_READER_F_POL_REQ 0x02
53#define ST21NFCA_RF_READER_F_POL_REQ_DEFAULT 0xffff0000
54#define ST21NFCA_RF_READER_F_NFCID2 0x03
55#define ST21NFCA_RF_READER_F_NFCID1 0x04
56
57#define ST21NFCA_RF_CARD_F_MODE 0x01
58#define ST21NFCA_RF_CARD_F_NFCID2_LIST 0x04
59#define ST21NFCA_RF_CARD_F_NFCID1 0x05
60#define ST21NFCA_RF_CARD_F_SENS_RES 0x06
61#define ST21NFCA_RF_CARD_F_SEL_RES 0x07
62#define ST21NFCA_RF_CARD_F_DATARATE 0x08
63#define ST21NFCA_RF_CARD_F_DATARATE_212_424 0x01
64
48#define ST21NFCA_DEVICE_MGNT_GATE 0x01 65#define ST21NFCA_DEVICE_MGNT_GATE 0x01
49#define ST21NFCA_DEVICE_MGNT_PIPE 0x02 66#define ST21NFCA_DEVICE_MGNT_PIPE 0x02
50 67
51#define ST21NFCA_DM_GETINFO 0x13 68#define ST21NFCA_DM_GETINFO 0x13
52#define ST21NFCA_DM_GETINFO_PIPE_LIST 0x02 69#define ST21NFCA_DM_GETINFO_PIPE_LIST 0x02
53#define ST21NFCA_DM_GETINFO_PIPE_INFO 0x01 70#define ST21NFCA_DM_GETINFO_PIPE_INFO 0x01
54#define ST21NFCA_DM_PIPE_CREATED 0x02 71#define ST21NFCA_DM_PIPE_CREATED 0x02
55#define ST21NFCA_DM_PIPE_OPEN 0x04 72#define ST21NFCA_DM_PIPE_OPEN 0x04
56#define ST21NFCA_DM_RF_ACTIVE 0x80 73#define ST21NFCA_DM_RF_ACTIVE 0x80
57#define ST21NFCA_DM_DISCONNECT 0x30 74#define ST21NFCA_DM_DISCONNECT 0x30
58 75
59#define ST21NFCA_DM_IS_PIPE_OPEN(p) \ 76#define ST21NFCA_DM_IS_PIPE_OPEN(p) \
60 ((p & 0x0f) == (ST21NFCA_DM_PIPE_CREATED | ST21NFCA_DM_PIPE_OPEN)) 77 ((p & 0x0f) == (ST21NFCA_DM_PIPE_CREATED | ST21NFCA_DM_PIPE_OPEN))
61 78
62#define ST21NFCA_NFC_MODE 0x03 /* NFC_MODE parameter*/ 79#define ST21NFCA_NFC_MODE 0x03 /* NFC_MODE parameter*/
80#define ST21NFCA_EVT_FIELD_ON 0x11
81#define ST21NFCA_EVT_CARD_DEACTIVATED 0x12
82#define ST21NFCA_EVT_CARD_ACTIVATED 0x13
83#define ST21NFCA_EVT_FIELD_OFF 0x14
63 84
64static DECLARE_BITMAP(dev_mask, ST21NFCA_NUM_DEVICES); 85static DECLARE_BITMAP(dev_mask, ST21NFCA_NUM_DEVICES);
65 86
@@ -355,8 +376,8 @@ static int st21nfca_hci_start_poll(struct nfc_hci_dev *hdev,
355 if (r < 0) 376 if (r < 0)
356 return r; 377 return r;
357 378
358 pol_req = 379 pol_req = be32_to_cpu((__force __be32)
359 be32_to_cpu(ST21NFCA_RF_READER_F_POL_REQ_DEFAULT); 380 ST21NFCA_RF_READER_F_POL_REQ_DEFAULT);
360 r = nfc_hci_set_param(hdev, ST21NFCA_RF_READER_F_GATE, 381 r = nfc_hci_set_param(hdev, ST21NFCA_RF_READER_F_GATE,
361 ST21NFCA_RF_READER_F_POL_REQ, 382 ST21NFCA_RF_READER_F_POL_REQ,
362 (u8 *) &pol_req, 4); 383 (u8 *) &pol_req, 4);
@@ -790,6 +811,7 @@ static int st21nfca_hci_check_presence(struct nfc_hci_dev *hdev,
790 struct nfc_target *target) 811 struct nfc_target *target)
791{ 812{
792 u8 fwi = 0x11; 813 u8 fwi = 0x11;
814
793 switch (target->hci_reader_gate) { 815 switch (target->hci_reader_gate) {
794 case NFC_HCI_RF_READER_A_GATE: 816 case NFC_HCI_RF_READER_A_GATE:
795 case NFC_HCI_RF_READER_B_GATE: 817 case NFC_HCI_RF_READER_B_GATE:
@@ -839,20 +861,16 @@ static int st21nfca_hci_event_received(struct nfc_hci_dev *hdev, u8 gate,
839 if (gate == ST21NFCA_RF_CARD_F_GATE) { 861 if (gate == ST21NFCA_RF_CARD_F_GATE) {
840 r = st21nfca_tm_event_send_data(hdev, skb, gate); 862 r = st21nfca_tm_event_send_data(hdev, skb, gate);
841 if (r < 0) 863 if (r < 0)
842 goto exit; 864 return r;
843 return 0; 865 return 0;
844 } else {
845 info->dep_info.curr_nfc_dep_pni = 0;
846 return 1;
847 } 866 }
848 break; 867 info->dep_info.curr_nfc_dep_pni = 0;
868 return 1;
849 default: 869 default:
850 return 1; 870 return 1;
851 } 871 }
852 kfree_skb(skb); 872 kfree_skb(skb);
853 return 0; 873 return 0;
854exit:
855 return r;
856} 874}
857 875
858static struct nfc_hci_ops st21nfca_hci_ops = { 876static struct nfc_hci_ops st21nfca_hci_ops = {
@@ -904,8 +922,11 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops,
904 * persistent info to discriminate 2 identical chips 922 * persistent info to discriminate 2 identical chips
905 */ 923 */
906 dev_num = find_first_zero_bit(dev_mask, ST21NFCA_NUM_DEVICES); 924 dev_num = find_first_zero_bit(dev_mask, ST21NFCA_NUM_DEVICES);
925
907 if (dev_num >= ST21NFCA_NUM_DEVICES) 926 if (dev_num >= ST21NFCA_NUM_DEVICES)
908 goto err_alloc_hdev; 927 return -ENODEV;
928
929 set_bit(dev_num, dev_mask);
909 930
910 scnprintf(init_data.session_id, sizeof(init_data.session_id), "%s%2x", 931 scnprintf(init_data.session_id, sizeof(init_data.session_id), "%s%2x",
911 "ST21AH", dev_num); 932 "ST21AH", dev_num);
diff --git a/drivers/nfc/st21nfca/st21nfca.h b/drivers/nfc/st21nfca/st21nfca.h
index 96fe5a62dc0d..a0b77f1ba6d9 100644
--- a/drivers/nfc/st21nfca/st21nfca.h
+++ b/drivers/nfc/st21nfca/st21nfca.h
@@ -82,30 +82,9 @@ struct st21nfca_hci_info {
82#define ST21NFCA_WR_XCHG_DATA 0x10 82#define ST21NFCA_WR_XCHG_DATA 0x10
83 83
84#define ST21NFCA_RF_READER_F_GATE 0x14 84#define ST21NFCA_RF_READER_F_GATE 0x14
85#define ST21NFCA_RF_READER_F_DATARATE 0x01
86#define ST21NFCA_RF_READER_F_DATARATE_106 0x01
87#define ST21NFCA_RF_READER_F_DATARATE_212 0x02
88#define ST21NFCA_RF_READER_F_DATARATE_424 0x04
89#define ST21NFCA_RF_READER_F_POL_REQ 0x02
90#define ST21NFCA_RF_READER_F_POL_REQ_DEFAULT 0xffff0000
91#define ST21NFCA_RF_READER_F_NFCID2 0x03
92#define ST21NFCA_RF_READER_F_NFCID1 0x04
93#define ST21NFCA_RF_READER_F_SENS_RES 0x05
94 85
95#define ST21NFCA_RF_CARD_F_GATE 0x24 86#define ST21NFCA_RF_CARD_F_GATE 0x24
96#define ST21NFCA_RF_CARD_F_MODE 0x01
97#define ST21NFCA_RF_CARD_F_NFCID2_LIST 0x04
98#define ST21NFCA_RF_CARD_F_NFCID1 0x05
99#define ST21NFCA_RF_CARD_F_SENS_RES 0x06
100#define ST21NFCA_RF_CARD_F_SEL_RES 0x07
101#define ST21NFCA_RF_CARD_F_DATARATE 0x08
102#define ST21NFCA_RF_CARD_F_DATARATE_106 0x00
103#define ST21NFCA_RF_CARD_F_DATARATE_212_424 0x01
104 87
105#define ST21NFCA_EVT_SEND_DATA 0x10 88#define ST21NFCA_EVT_SEND_DATA 0x10
106#define ST21NFCA_EVT_FIELD_ON 0x11
107#define ST21NFCA_EVT_CARD_DEACTIVATED 0x12
108#define ST21NFCA_EVT_CARD_ACTIVATED 0x13
109#define ST21NFCA_EVT_FIELD_OFF 0x14
110 89
111#endif /* __LOCAL_ST21NFCA_H_ */ 90#endif /* __LOCAL_ST21NFCA_H_ */
diff --git a/drivers/nfc/st21nfca/st21nfca_dep.c b/drivers/nfc/st21nfca/st21nfca_dep.c
index b2d9957b57f8..bfb6df56c505 100644
--- a/drivers/nfc/st21nfca/st21nfca_dep.c
+++ b/drivers/nfc/st21nfca/st21nfca_dep.c
@@ -121,6 +121,7 @@ static void st21nfca_tx_work(struct work_struct *work)
121 121
122 struct nfc_dev *dev; 122 struct nfc_dev *dev;
123 struct sk_buff *skb; 123 struct sk_buff *skb;
124
124 if (info) { 125 if (info) {
125 dev = info->hdev->ndev; 126 dev = info->hdev->ndev;
126 skb = info->dep_info.tx_pending; 127 skb = info->dep_info.tx_pending;
@@ -128,9 +129,8 @@ static void st21nfca_tx_work(struct work_struct *work)
128 device_lock(&dev->dev); 129 device_lock(&dev->dev);
129 130
130 nfc_hci_send_cmd_async(info->hdev, ST21NFCA_RF_READER_F_GATE, 131 nfc_hci_send_cmd_async(info->hdev, ST21NFCA_RF_READER_F_GATE,
131 ST21NFCA_WR_XCHG_DATA, 132 ST21NFCA_WR_XCHG_DATA, skb->data, skb->len,
132 skb->data, skb->len, 133 info->async_cb, info);
133 info->async_cb, info);
134 device_unlock(&dev->dev); 134 device_unlock(&dev->dev);
135 kfree_skb(skb); 135 kfree_skb(skb);
136 } 136 }
@@ -185,8 +185,10 @@ static int st21nfca_tm_send_atr_res(struct nfc_hci_dev *hdev,
185 185
186 info->dep_info.curr_nfc_dep_pni = 0; 186 info->dep_info.curr_nfc_dep_pni = 0;
187 187
188 return nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE, 188 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
189 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len); 189 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
190 kfree_skb(skb);
191 return r;
190} 192}
191 193
192static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev, 194static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev,
@@ -197,10 +199,6 @@ static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev,
197 int r; 199 int r;
198 200
199 skb_trim(skb, skb->len - 1); 201 skb_trim(skb, skb->len - 1);
200 if (IS_ERR(skb)) {
201 r = PTR_ERR(skb);
202 goto exit;
203 }
204 202
205 if (!skb->len) { 203 if (!skb->len) {
206 r = -EIO; 204 r = -EIO;
@@ -214,6 +212,11 @@ static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev,
214 212
215 atr_req = (struct st21nfca_atr_req *)skb->data; 213 atr_req = (struct st21nfca_atr_req *)skb->data;
216 214
215 if (atr_req->length < sizeof(struct st21nfca_atr_req)) {
216 r = -EPROTO;
217 goto exit;
218 }
219
217 r = st21nfca_tm_send_atr_res(hdev, atr_req); 220 r = st21nfca_tm_send_atr_res(hdev, atr_req);
218 if (r) 221 if (r)
219 goto exit; 222 goto exit;
@@ -237,7 +240,6 @@ static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
237 struct st21nfca_psl_res *psl_res; 240 struct st21nfca_psl_res *psl_res;
238 struct sk_buff *skb; 241 struct sk_buff *skb;
239 u8 bitrate[2] = {0, 0}; 242 u8 bitrate[2] = {0, 0};
240
241 int r; 243 int r;
242 244
243 skb = alloc_skb(sizeof(struct st21nfca_psl_res), GFP_KERNEL); 245 skb = alloc_skb(sizeof(struct st21nfca_psl_res), GFP_KERNEL);
@@ -254,6 +256,8 @@ static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
254 256
255 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE, 257 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
256 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len); 258 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
259 if (r < 0)
260 goto error;
257 261
258 /* 262 /*
259 * ST21NFCA only support P2P passive. 263 * ST21NFCA only support P2P passive.
@@ -269,8 +273,11 @@ static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
269 } 273 }
270 274
271 /* Send an event to change bitrate change event to card f */ 275 /* Send an event to change bitrate change event to card f */
272 return nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE, 276 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
273 ST21NFCA_EVT_CARD_F_BITRATE, bitrate, 2); 277 ST21NFCA_EVT_CARD_F_BITRATE, bitrate, 2);
278error:
279 kfree_skb(skb);
280 return r;
274} 281}
275 282
276static int st21nfca_tm_recv_psl_req(struct nfc_hci_dev *hdev, 283static int st21nfca_tm_recv_psl_req(struct nfc_hci_dev *hdev,
@@ -280,11 +287,6 @@ static int st21nfca_tm_recv_psl_req(struct nfc_hci_dev *hdev,
280 int r; 287 int r;
281 288
282 skb_trim(skb, skb->len - 1); 289 skb_trim(skb, skb->len - 1);
283 if (IS_ERR(skb)) {
284 r = PTR_ERR(skb);
285 skb = NULL;
286 goto exit;
287 }
288 290
289 if (!skb->len) { 291 if (!skb->len) {
290 r = -EIO; 292 r = -EIO;
@@ -314,7 +316,7 @@ int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb)
314 *skb_push(skb, 1) = skb->len; 316 *skb_push(skb, 1) = skb->len;
315 317
316 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE, 318 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
317 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len); 319 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
318 kfree_skb(skb); 320 kfree_skb(skb);
319 321
320 return r; 322 return r;
@@ -330,11 +332,6 @@ static int st21nfca_tm_recv_dep_req(struct nfc_hci_dev *hdev,
330 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev); 332 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
331 333
332 skb_trim(skb, skb->len - 1); 334 skb_trim(skb, skb->len - 1);
333 if (IS_ERR(skb)) {
334 r = PTR_ERR(skb);
335 skb = NULL;
336 goto exit;
337 }
338 335
339 size = 4; 336 size = 4;
340 337
@@ -368,12 +365,6 @@ static int st21nfca_tm_recv_dep_req(struct nfc_hci_dev *hdev,
368 break; 365 break;
369 } 366 }
370 367
371 if (IS_ERR(skb)) {
372 r = PTR_ERR(skb);
373 skb = NULL;
374 goto exit;
375 }
376
377 skb_pull(skb, size); 368 skb_pull(skb, size);
378 369
379 return nfc_tm_data_received(hdev->ndev, skb); 370 return nfc_tm_data_received(hdev->ndev, skb);
@@ -437,8 +428,6 @@ static void st21nfca_im_send_psl_req(struct nfc_hci_dev *hdev, u8 did, u8 bsi,
437 *skb_push(skb, 1) = info->dep_info.to | 0x10; 428 *skb_push(skb, 1) = info->dep_info.to | 0x10;
438 429
439 st21nfca_im_send_pdu(info, skb); 430 st21nfca_im_send_pdu(info, skb);
440
441 kfree_skb(skb);
442} 431}
443 432
444#define ST21NFCA_CB_TYPE_READER_F 1 433#define ST21NFCA_CB_TYPE_READER_F 1
@@ -452,7 +441,7 @@ static void st21nfca_im_recv_atr_res_cb(void *context, struct sk_buff *skb,
452 if (err != 0) 441 if (err != 0)
453 return; 442 return;
454 443
455 if (IS_ERR(skb)) 444 if (!skb)
456 return; 445 return;
457 446
458 switch (info->async_cb_type) { 447 switch (info->async_cb_type) {
@@ -484,8 +473,7 @@ static void st21nfca_im_recv_atr_res_cb(void *context, struct sk_buff *skb,
484 ST21NFCA_PP2LRI(atr_res->ppi)); 473 ST21NFCA_PP2LRI(atr_res->ppi));
485 break; 474 break;
486 default: 475 default:
487 if (err == 0) 476 kfree_skb(skb);
488 kfree_skb(skb);
489 break; 477 break;
490 } 478 }
491} 479}
@@ -522,7 +510,7 @@ int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len)
522 memset(atr_req->nfcid3, 0, NFC_NFCID3_MAXSIZE); 510 memset(atr_req->nfcid3, 0, NFC_NFCID3_MAXSIZE);
523 target = hdev->ndev->targets; 511 target = hdev->ndev->targets;
524 512
525 if (target->sensf_res) 513 if (target->sensf_res_len > 0)
526 memcpy(atr_req->nfcid3, target->sensf_res, 514 memcpy(atr_req->nfcid3, target->sensf_res,
527 target->sensf_res_len); 515 target->sensf_res_len);
528 else 516 else
@@ -565,7 +553,7 @@ static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,
565 if (err != 0) 553 if (err != 0)
566 return; 554 return;
567 555
568 if (IS_ERR(skb)) 556 if (!skb)
569 return; 557 return;
570 558
571 switch (info->async_cb_type) { 559 switch (info->async_cb_type) {
@@ -615,8 +603,7 @@ static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,
615 } 603 }
616 604
617exit: 605exit:
618 if (err == 0) 606 kfree_skb(skb);
619 kfree_skb(skb);
620} 607}
621 608
622int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb) 609int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb)