nfc: fix get_unaligned_...() misuses
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 16 Apr 2017 22:42:22 +0000 (00:42 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Sun, 16 Apr 2017 22:42:22 +0000 (00:42 +0200)
* if a local variable of type uint16_t is unaligned, your compiler is FUBAR
* the whole point of get_unaligned_... is to avoid memcpy + ..._to_cpu().
  Using it *after* memcpy() (into aligned object, no less) is pointless.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/nfcmrvl/fw_dnld.c
drivers/nfc/nxp-nci/i2c.c

index 441c1b0ec7b5f4c925081d073bcddf9ed27925b0..c38bdd6a5a821899d16488f3b988b741316cb26e 100644 (file)
@@ -281,12 +281,11 @@ static int process_state_fw_dnld(struct nfcmrvl_private *priv,
                        return -EINVAL;
                }
                skb_pull(skb, 1);
-               memcpy(&len, skb->data, 2);
+               len = get_unaligned_le16(skb->data);
                skb_pull(skb, 2);
+               comp_len = get_unaligned_le16(skb->data);
                memcpy(&comp_len, skb->data, 2);
                skb_pull(skb, 2);
-               len = get_unaligned_le16(&len);
-               comp_len = get_unaligned_le16(&comp_len);
                if (((~len) & 0xFFFF) != comp_len) {
                        nfc_err(priv->dev, "bad len complement: %x %x %x",
                                len, comp_len, (~len & 0xFFFF));
index c6a04a950225ef66713239854ab5750f0cd936f0..ff22d761183cbed59aef9cf38eee29c4bd1de407 100644 (file)
@@ -126,7 +126,7 @@ static int nxp_nci_i2c_fw_read(struct nxp_nci_i2c_phy *phy,
                goto fw_read_exit;
        }
 
-       frame_len = (get_unaligned_be16(&header) & NXP_NCI_FW_FRAME_LEN_MASK) +
+       frame_len = (be16_to_cpu(header) & NXP_NCI_FW_FRAME_LEN_MASK) +
                    NXP_NCI_FW_CRC_LEN;
 
        *skb = alloc_skb(NXP_NCI_FW_HDR_LEN + frame_len, GFP_KERNEL);