diff options
author | Thierry Escande <thierry.escande@linux.intel.com> | 2013-09-24 05:47:34 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-09-24 20:02:42 -0400 |
commit | 13292c9a1ed92e535caae6154db1fea7993777ad (patch) | |
tree | d6dc69f283c270da3e743a2ba0f1da74d9c694ba /net | |
parent | 4cf7e032960a945f813784a68bf0b982a4035bf9 (diff) |
NFC: digital: Fix sens_res endiannes handling
This was triggered by the following sparse warning:
net/nfc/digital_technology.c:272:20: sparse: cast to restricted __be16
The SENS_RES response must be treated as __le16 with the first byte
received as LSB and the second one as MSB. This is the way neard
handles it in the sens_res field of the nfc_target structure which is
treated as u16 in cpu endianness. So le16_to_cpu() is used on the
received SENS_RES instead of memcpy'ing it.
SENS_RES test macros have also been fixed accordingly.
Signed-off-by: Thierry Escande <thierry.escande@linux.intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/nfc/digital_technology.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c index f5dd8cfad404..251c8c753ebe 100644 --- a/net/nfc/digital_technology.c +++ b/net/nfc/digital_technology.c | |||
@@ -32,10 +32,10 @@ | |||
32 | #define DIGITAL_SEL_RES_IS_T2T(sel_res) (!((sel_res) & 0x60)) | 32 | #define DIGITAL_SEL_RES_IS_T2T(sel_res) (!((sel_res) & 0x60)) |
33 | #define DIGITAL_SEL_RES_IS_NFC_DEP(sel_res) ((sel_res) & 0x40) | 33 | #define DIGITAL_SEL_RES_IS_NFC_DEP(sel_res) ((sel_res) & 0x40) |
34 | 34 | ||
35 | #define DIGITAL_SENS_RES_IS_T1T(sens_res) (((sens_res) & 0x000C) == 0x000C) | 35 | #define DIGITAL_SENS_RES_IS_T1T(sens_res) (((sens_res) & 0x0C00) == 0x0C00) |
36 | #define DIGITAL_SENS_RES_IS_VALID(sens_res) \ | 36 | #define DIGITAL_SENS_RES_IS_VALID(sens_res) \ |
37 | ((!((sens_res) & 0x1F00) && (((sens_res) & 0x000C) == 0x000C)) || \ | 37 | ((!((sens_res) & 0x001F) && (((sens_res) & 0x0C00) == 0x0C00)) || \ |
38 | (((sens_res) & 0x1F00) && ((sens_res) & 0x000C) != 0x000C)) | 38 | (((sens_res) & 0x001F) && ((sens_res) & 0x0C00) != 0x0C00)) |
39 | 39 | ||
40 | #define DIGITAL_MIFARE_READ_RES_LEN 16 | 40 | #define DIGITAL_MIFARE_READ_RES_LEN 16 |
41 | #define DIGITAL_MIFARE_ACK_RES 0x0A | 41 | #define DIGITAL_MIFARE_ACK_RES 0x0A |
@@ -280,7 +280,6 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg, | |||
280 | struct sk_buff *resp) | 280 | struct sk_buff *resp) |
281 | { | 281 | { |
282 | struct nfc_target *target = NULL; | 282 | struct nfc_target *target = NULL; |
283 | u16 sens_res; | ||
284 | int rc; | 283 | int rc; |
285 | 284 | ||
286 | if (IS_ERR(resp)) { | 285 | if (IS_ERR(resp)) { |
@@ -300,17 +299,15 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg, | |||
300 | goto exit; | 299 | goto exit; |
301 | } | 300 | } |
302 | 301 | ||
303 | memcpy(&target->sens_res, resp->data, sizeof(u16)); | 302 | target->sens_res = __le16_to_cpu(*(__le16 *)resp->data); |
304 | 303 | ||
305 | sens_res = be16_to_cpu(target->sens_res); | 304 | if (!DIGITAL_SENS_RES_IS_VALID(target->sens_res)) { |
306 | |||
307 | if (!DIGITAL_SENS_RES_IS_VALID(sens_res)) { | ||
308 | PROTOCOL_ERR("4.6.3.3"); | 305 | PROTOCOL_ERR("4.6.3.3"); |
309 | rc = -EINVAL; | 306 | rc = -EINVAL; |
310 | goto exit; | 307 | goto exit; |
311 | } | 308 | } |
312 | 309 | ||
313 | if (DIGITAL_SENS_RES_IS_T1T(sens_res)) | 310 | if (DIGITAL_SENS_RES_IS_T1T(target->sens_res)) |
314 | rc = digital_target_found(ddev, target, NFC_PROTO_JEWEL); | 311 | rc = digital_target_found(ddev, target, NFC_PROTO_JEWEL); |
315 | else | 312 | else |
316 | rc = digital_in_send_sdd_req(ddev, target); | 313 | rc = digital_in_send_sdd_req(ddev, target); |