From 634fef61076d644b989b86abc2f560d81a089a31 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 16 Jun 2017 14:29:24 +0200 Subject: networking: add and use skb_put_u8() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Joe and Bjørn suggested that it'd be nicer to not have the cast in the fairly common case of doing *(u8 *)skb_put(skb, 1) = c; Add skb_put_u8() for this case, and use it across the code, using the following spatch: @@ expression SKB, C, S; typedef u8; identifier fn = {skb_put}; fresh identifier fn2 = fn ## "_u8"; @@ - *(u8 *)fn(SKB, S) = C; + fn2(SKB, C); Note that due to the "S", the spatch isn't perfect, it should have checked that S is 1, but there's also places that use a sizeof expression like sizeof(var) or sizeof(u8) etc. Turns out that nobody ever did something like *(u8 *)skb_put(skb, 2) = c; which would be wrong anyway since the second byte wouldn't be initialized. Suggested-by: Joe Perches Suggested-by: Bjørn Mork Signed-off-by: Johannes Berg Signed-off-by: David S. Miller --- drivers/nfc/fdp/i2c.c | 2 +- drivers/nfc/microread/i2c.c | 4 ++-- drivers/nfc/microread/microread.c | 4 ++-- drivers/nfc/nfcmrvl/fw_dnld.c | 4 ++-- drivers/nfc/pn533/pn533.c | 32 ++++++++++++++++---------------- drivers/nfc/pn544/i2c.c | 6 +++--- drivers/nfc/port100.c | 4 ++-- drivers/nfc/st21nfca/i2c.c | 6 +++--- drivers/nfc/st95hf/core.c | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index d5781aa0f791..e0baec848ff2 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -86,7 +86,7 @@ static void fdp_nci_i2c_add_len_lrc(struct sk_buff *skb) for (i = 0; i < len + 2; i++) lrc ^= skb->data[i]; - *(u8 *)skb_put(skb, 1) = lrc; + skb_put_u8(skb, lrc); } static void fdp_nci_i2c_remove_len_lrc(struct sk_buff *skb) diff --git a/drivers/nfc/microread/i2c.c b/drivers/nfc/microread/i2c.c index 386cc61d95b9..b668b7b9a61e 100644 --- a/drivers/nfc/microread/i2c.c +++ b/drivers/nfc/microread/i2c.c @@ -75,7 +75,7 @@ static void microread_i2c_add_len_crc(struct sk_buff *skb) for (i = 0; i < skb->len; i++) crc = crc ^ skb->data[i]; - *(u8 *)skb_put(skb, 1) = crc; + skb_put_u8(skb, crc); } static void microread_i2c_remove_len_crc(struct sk_buff *skb) @@ -173,7 +173,7 @@ static int microread_i2c_read(struct microread_i2c_phy *phy, goto flush; } - *(u8 *)skb_put(*skb, 1) = len; + skb_put_u8(*skb, len); r = i2c_master_recv(client, skb_put(*skb, len), len); if (r != len) { diff --git a/drivers/nfc/microread/microread.c b/drivers/nfc/microread/microread.c index 38a979eacc29..e5d5d2d97409 100644 --- a/drivers/nfc/microread/microread.c +++ b/drivers/nfc/microread/microread.c @@ -441,8 +441,8 @@ static int microread_im_transceive(struct nfc_hci_dev *hdev, crc = crc_ccitt(0xffff, skb->data, skb->len); crc = ~crc; - *(u8 *)skb_put(skb, 1) = crc & 0xff; - *(u8 *)skb_put(skb, 1) = crc >> 8; + skb_put_u8(skb, crc & 0xff); + skb_put_u8(skb, crc >> 8); break; case MICROREAD_GATE_ID_MREAD_NFC_T3: control_bits = 0xDB; diff --git a/drivers/nfc/nfcmrvl/fw_dnld.c b/drivers/nfc/nfcmrvl/fw_dnld.c index 788599de9d8a..f9f000c546d1 100644 --- a/drivers/nfc/nfcmrvl/fw_dnld.c +++ b/drivers/nfc/nfcmrvl/fw_dnld.c @@ -292,7 +292,7 @@ static int process_state_fw_dnld(struct nfcmrvl_private *priv, out_skb = alloc_lc_skb(priv, 1); if (!out_skb) return -ENOMEM; - *(u8 *)skb_put(out_skb, 1) = 0xBF; + skb_put_u8(out_skb, 0xBF); nci_send_frame(priv->ndev, out_skb); priv->fw_dnld.substate = SUBSTATE_WAIT_NACK_CREDIT; return 0; @@ -301,7 +301,7 @@ static int process_state_fw_dnld(struct nfcmrvl_private *priv, out_skb = alloc_lc_skb(priv, 1); if (!out_skb) return -ENOMEM; - *(u8 *)skb_put(out_skb, 1) = HELPER_ACK_PACKET_FORMAT; + skb_put_u8(out_skb, HELPER_ACK_PACKET_FORMAT); nci_send_frame(priv->ndev, out_skb); priv->fw_dnld.substate = SUBSTATE_WAIT_ACK_CREDIT; break; diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c index 6a711b5b9490..c8a8f5badb5b 100644 --- a/drivers/nfc/pn533/pn533.c +++ b/drivers/nfc/pn533/pn533.c @@ -1032,7 +1032,7 @@ static struct sk_buff *pn533_alloc_poll_tg_frame(struct pn533 *dev) return NULL; /* DEP support only */ - *(u8 *)skb_put(skb, 1) = PN533_INIT_TARGET_DEP; + skb_put_u8(skb, PN533_INIT_TARGET_DEP); /* MIFARE params */ skb_put_data(skb, mifare_params, 6); @@ -1046,12 +1046,12 @@ static struct sk_buff *pn533_alloc_poll_tg_frame(struct pn533 *dev) memcpy(nfcid3, felica, 8); /* General bytes */ - *(u8 *)skb_put(skb, 1) = gbytes_len; + skb_put_u8(skb, gbytes_len); gb = skb_put_data(skb, gbytes, gbytes_len); /* Len Tk */ - *(u8 *)skb_put(skb, 1) = 0; + skb_put_u8(skb, 0); return skb; } @@ -1280,8 +1280,8 @@ static void pn533_wq_rf(struct work_struct *work) if (!skb) return; - *(u8 *)skb_put(skb, 1) = PN533_CFGITEM_RF_FIELD; - *(u8 *)skb_put(skb, 1) = PN533_CFGITEM_RF_FIELD_AUTO_RFCA; + skb_put_u8(skb, PN533_CFGITEM_RF_FIELD); + skb_put_u8(skb, PN533_CFGITEM_RF_FIELD_AUTO_RFCA); rc = pn533_send_cmd_async(dev, PN533_CMD_RF_CONFIGURATION, skb, pn533_rf_complete, NULL); @@ -1375,8 +1375,8 @@ static int pn533_poll_dep(struct nfc_dev *nfc_dev) if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, 1) = 0x01; /* Active */ - *(u8 *)skb_put(skb, 1) = 0x02; /* 424 kbps */ + skb_put_u8(skb, 0x01); /* Active */ + skb_put_u8(skb, 0x02); /* 424 kbps */ next = skb_put(skb, 1); /* Next */ *next = 0; @@ -1620,8 +1620,8 @@ static int pn533_activate_target_nfcdep(struct pn533 *dev) if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, sizeof(u8)) = 1; /* TG */ - *(u8 *)skb_put(skb, sizeof(u8)) = 0; /* Next */ + skb_put_u8(skb, 1); /* TG */ + skb_put_u8(skb, 0); /* Next */ resp = pn533_send_cmd_sync(dev, PN533_CMD_IN_ATR, skb); if (IS_ERR(resp)) @@ -1737,7 +1737,7 @@ static void pn533_deactivate_target(struct nfc_dev *nfc_dev, if (!skb) return; - *(u8 *)skb_put(skb, 1) = 1; /* TG*/ + skb_put_u8(skb, 1); /* TG*/ rc = pn533_send_cmd_async(dev, PN533_CMD_IN_RELEASE, skb, pn533_deactivate_target_complete, NULL); @@ -1848,8 +1848,8 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, 1) = !comm_mode; /* ActPass */ - *(u8 *)skb_put(skb, 1) = 0x02; /* 424 kbps */ + skb_put_u8(skb, !comm_mode); /* ActPass */ + skb_put_u8(skb, 0x02); /* 424 kbps */ next = skb_put(skb, 1); /* Next */ *next = 0; @@ -2274,7 +2274,7 @@ static void pn533_wq_mi_recv(struct work_struct *work) break; } default: - *(u8 *)skb_put(skb, sizeof(u8)) = 1; /*TG*/ + skb_put_u8(skb, 1); /*TG*/ rc = pn533_send_cmd_direct_async(dev, PN533_CMD_IN_DATA_EXCHANGE, @@ -2370,7 +2370,7 @@ static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata, if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, sizeof(cfgitem)) = cfgitem; + skb_put_u8(skb, cfgitem); skb_put_data(skb, cfgdata, cfgdata_len); resp = pn533_send_cmd_sync(dev, PN533_CMD_RF_CONFIGURATION, skb); @@ -2415,7 +2415,7 @@ static int pn533_pasori_fw_reset(struct pn533 *dev) if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, sizeof(u8)) = 0x1; + skb_put_u8(skb, 0x1); resp = pn533_send_cmd_sync(dev, 0x18, skb); if (IS_ERR(resp)) @@ -2454,7 +2454,7 @@ static int pn532_sam_configuration(struct nfc_dev *nfc_dev) if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, 1) = 0x01; + skb_put_u8(skb, 0x01); resp = pn533_send_cmd_sync(dev, PN533_CMD_SAM_CONFIGURATION, skb); if (IS_ERR(resp)) diff --git a/drivers/nfc/pn544/i2c.c b/drivers/nfc/pn544/i2c.c index b7be6c25b7e6..fedde9d46ab6 100644 --- a/drivers/nfc/pn544/i2c.c +++ b/drivers/nfc/pn544/i2c.c @@ -287,8 +287,8 @@ static void pn544_hci_i2c_add_len_crc(struct sk_buff *skb) crc = crc_ccitt(0xffff, skb->data, skb->len); crc = ~crc; - *(u8 *)skb_put(skb, 1) = crc & 0xff; - *(u8 *)skb_put(skb, 1) = crc >> 8; + skb_put_u8(skb, crc & 0xff); + skb_put_u8(skb, crc >> 8); } static void pn544_hci_i2c_remove_len_crc(struct sk_buff *skb) @@ -391,7 +391,7 @@ static int pn544_hci_i2c_read(struct pn544_i2c_phy *phy, struct sk_buff **skb) goto flush; } - *(u8 *)skb_put(*skb, 1) = len; + skb_put_u8(*skb, len); r = i2c_master_recv(client, skb_put(*skb, len), len); if (r != len) { diff --git a/drivers/nfc/port100.c b/drivers/nfc/port100.c index 5fa3cf0fabd6..bb43cebda9dc 100644 --- a/drivers/nfc/port100.c +++ b/drivers/nfc/port100.c @@ -991,7 +991,7 @@ static int port100_set_command_type(struct port100 *dev, u8 command_type) if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, sizeof(u8)) = command_type; + skb_put_u8(skb, command_type); resp = port100_send_cmd_sync(dev, PORT100_CMD_SET_COMMAND_TYPE, skb); if (IS_ERR(resp)) @@ -1059,7 +1059,7 @@ static int port100_switch_rf(struct nfc_digital_dev *ddev, bool on) if (!skb) return -ENOMEM; - *(u8 *)skb_put(skb, 1) = on ? 1 : 0; + skb_put_u8(skb, on ? 1 : 0); /* Cancel the last command if the device is being switched off */ if (!on) diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c index 396cdafb3e36..4bff76baa341 100644 --- a/drivers/nfc/st21nfca/i2c.c +++ b/drivers/nfc/st21nfca/i2c.c @@ -177,10 +177,10 @@ static void st21nfca_hci_add_len_crc(struct sk_buff *skb) crc = ~crc; tmp = crc & 0x00ff; - *(u8 *)skb_put(skb, 1) = tmp; + skb_put_u8(skb, tmp); tmp = (crc >> 8) & 0x00ff; - *(u8 *)skb_put(skb, 1) = tmp; + skb_put_u8(skb, tmp); } static void st21nfca_hci_remove_len_crc(struct sk_buff *skb) @@ -214,7 +214,7 @@ static int st21nfca_hci_i2c_write(void *phy_id, struct sk_buff *skb) st21nfca_hci_add_len_crc(skb); /* add ST21NFCA_SOF_EOF on tail */ - *(u8 *)skb_put(skb, 1) = ST21NFCA_SOF_EOF; + skb_put_u8(skb, ST21NFCA_SOF_EOF); /* add ST21NFCA_SOF_EOF on head */ *(u8 *)skb_push(skb, 1) = ST21NFCA_SOF_EOF; diff --git a/drivers/nfc/st95hf/core.c b/drivers/nfc/st95hf/core.c index 168adcc46cb8..2b26f762fbc3 100644 --- a/drivers/nfc/st95hf/core.c +++ b/drivers/nfc/st95hf/core.c @@ -949,7 +949,7 @@ static int st95hf_in_send_cmd(struct nfc_digital_dev *ddev, switch (stcontext->current_rf_tech) { case NFC_DIGITAL_RF_TECH_106A: len_data_to_tag = skb->len + 1; - *(u8 *)skb_put(skb, 1) = stcontext->sendrcv_trflag; + skb_put_u8(skb, stcontext->sendrcv_trflag); break; case NFC_DIGITAL_RF_TECH_106B: case NFC_DIGITAL_RF_TECH_ISO15693: -- cgit v1.2.3