From 13292c9a1ed92e535caae6154db1fea7993777ad Mon Sep 17 00:00:00 2001 From: Thierry Escande Date: Tue, 24 Sep 2013 11:47:34 +0200 Subject: 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 Signed-off-by: Samuel Ortiz --- net/nfc/digital_technology.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'net/nfc/digital_technology.c') 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 @@ #define DIGITAL_SEL_RES_IS_T2T(sel_res) (!((sel_res) & 0x60)) #define DIGITAL_SEL_RES_IS_NFC_DEP(sel_res) ((sel_res) & 0x40) -#define DIGITAL_SENS_RES_IS_T1T(sens_res) (((sens_res) & 0x000C) == 0x000C) +#define DIGITAL_SENS_RES_IS_T1T(sens_res) (((sens_res) & 0x0C00) == 0x0C00) #define DIGITAL_SENS_RES_IS_VALID(sens_res) \ - ((!((sens_res) & 0x1F00) && (((sens_res) & 0x000C) == 0x000C)) || \ - (((sens_res) & 0x1F00) && ((sens_res) & 0x000C) != 0x000C)) + ((!((sens_res) & 0x001F) && (((sens_res) & 0x0C00) == 0x0C00)) || \ + (((sens_res) & 0x001F) && ((sens_res) & 0x0C00) != 0x0C00)) #define DIGITAL_MIFARE_READ_RES_LEN 16 #define DIGITAL_MIFARE_ACK_RES 0x0A @@ -280,7 +280,6 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { struct nfc_target *target = NULL; - u16 sens_res; int rc; if (IS_ERR(resp)) { @@ -300,17 +299,15 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg, goto exit; } - memcpy(&target->sens_res, resp->data, sizeof(u16)); + target->sens_res = __le16_to_cpu(*(__le16 *)resp->data); - sens_res = be16_to_cpu(target->sens_res); - - if (!DIGITAL_SENS_RES_IS_VALID(sens_res)) { + if (!DIGITAL_SENS_RES_IS_VALID(target->sens_res)) { PROTOCOL_ERR("4.6.3.3"); rc = -EINVAL; goto exit; } - if (DIGITAL_SENS_RES_IS_T1T(sens_res)) + if (DIGITAL_SENS_RES_IS_T1T(target->sens_res)) rc = digital_target_found(ddev, target, NFC_PROTO_JEWEL); else rc = digital_in_send_sdd_req(ddev, target); -- cgit v1.2.1