Commit 9d131d04 authored by Alex Elder's avatar Alex Elder Committed by David S. Miller

net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros

The following macros, defined in "rmnet_map.h", assume a socket
buffer is provided as an argument without any real indication this
is the case.
    RMNET_MAP_GET_MUX_ID()
    RMNET_MAP_GET_CD_BIT()
    RMNET_MAP_GET_PAD()
    RMNET_MAP_GET_CMD_START()
    RMNET_MAP_GET_LENGTH()
What they hide is pretty trivial accessing of fields in a structure,
and it's much clearer to see this if we do these accesses directly.

So rather than using these accessor macros, assign a local
variable of the map header pointer type to the socket buffer data
pointer, and derereference that pointer variable.

In "rmnet_map_data.c", use sizeof(object) rather than sizeof(type)
in one spot.  Also, there's no need to byte swap 0; it's all zeros
irrespective of endianness.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 50c62a11
...@@ -56,20 +56,22 @@ static void ...@@ -56,20 +56,22 @@ static void
__rmnet_map_ingress_handler(struct sk_buff *skb, __rmnet_map_ingress_handler(struct sk_buff *skb,
struct rmnet_port *port) struct rmnet_port *port)
{ {
struct rmnet_map_header *map_header = (void *)skb->data;
struct rmnet_endpoint *ep; struct rmnet_endpoint *ep;
u16 len, pad; u16 len, pad;
u8 mux_id; u8 mux_id;
if (RMNET_MAP_GET_CD_BIT(skb)) { if (map_header->cd_bit) {
/* Packet contains a MAP command (not data) */
if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS)
return rmnet_map_command(skb, port); return rmnet_map_command(skb, port);
goto free_skb; goto free_skb;
} }
mux_id = RMNET_MAP_GET_MUX_ID(skb); mux_id = map_header->mux_id;
pad = RMNET_MAP_GET_PAD(skb); pad = map_header->pad_len;
len = RMNET_MAP_GET_LENGTH(skb) - pad; len = ntohs(map_header->pkt_len) - pad;
if (mux_id >= RMNET_MAX_LOGICAL_EP) if (mux_id >= RMNET_MAX_LOGICAL_EP)
goto free_skb; goto free_skb;
......
...@@ -32,18 +32,6 @@ enum rmnet_map_commands { ...@@ -32,18 +32,6 @@ enum rmnet_map_commands {
RMNET_MAP_COMMAND_ENUM_LENGTH RMNET_MAP_COMMAND_ENUM_LENGTH
}; };
#define RMNET_MAP_GET_MUX_ID(Y) (((struct rmnet_map_header *) \
(Y)->data)->mux_id)
#define RMNET_MAP_GET_CD_BIT(Y) (((struct rmnet_map_header *) \
(Y)->data)->cd_bit)
#define RMNET_MAP_GET_PAD(Y) (((struct rmnet_map_header *) \
(Y)->data)->pad_len)
#define RMNET_MAP_GET_CMD_START(Y) ((struct rmnet_map_control_command *) \
((Y)->data + \
sizeof(struct rmnet_map_header)))
#define RMNET_MAP_GET_LENGTH(Y) (ntohs(((struct rmnet_map_header *) \
(Y)->data)->pkt_len))
#define RMNET_MAP_COMMAND_REQUEST 0 #define RMNET_MAP_COMMAND_REQUEST 0
#define RMNET_MAP_COMMAND_ACK 1 #define RMNET_MAP_COMMAND_ACK 1
#define RMNET_MAP_COMMAND_UNSUPPORTED 2 #define RMNET_MAP_COMMAND_UNSUPPORTED 2
......
...@@ -12,12 +12,13 @@ static u8 rmnet_map_do_flow_control(struct sk_buff *skb, ...@@ -12,12 +12,13 @@ static u8 rmnet_map_do_flow_control(struct sk_buff *skb,
struct rmnet_port *port, struct rmnet_port *port,
int enable) int enable)
{ {
struct rmnet_map_header *map_header = (void *)skb->data;
struct rmnet_endpoint *ep; struct rmnet_endpoint *ep;
struct net_device *vnd; struct net_device *vnd;
u8 mux_id; u8 mux_id;
int r; int r;
mux_id = RMNET_MAP_GET_MUX_ID(skb); mux_id = map_header->mux_id;
if (mux_id >= RMNET_MAX_LOGICAL_EP) { if (mux_id >= RMNET_MAX_LOGICAL_EP) {
kfree_skb(skb); kfree_skb(skb);
...@@ -49,6 +50,7 @@ static void rmnet_map_send_ack(struct sk_buff *skb, ...@@ -49,6 +50,7 @@ static void rmnet_map_send_ack(struct sk_buff *skb,
unsigned char type, unsigned char type,
struct rmnet_port *port) struct rmnet_port *port)
{ {
struct rmnet_map_header *map_header = (void *)skb->data;
struct rmnet_map_control_command *cmd; struct rmnet_map_control_command *cmd;
struct net_device *dev = skb->dev; struct net_device *dev = skb->dev;
...@@ -58,7 +60,8 @@ static void rmnet_map_send_ack(struct sk_buff *skb, ...@@ -58,7 +60,8 @@ static void rmnet_map_send_ack(struct sk_buff *skb,
skb->protocol = htons(ETH_P_MAP); skb->protocol = htons(ETH_P_MAP);
cmd = RMNET_MAP_GET_CMD_START(skb); /* Command data immediately follows the MAP header */
cmd = (struct rmnet_map_control_command *)(map_header + 1);
cmd->cmd_type = type & 0x03; cmd->cmd_type = type & 0x03;
netif_tx_lock(dev); netif_tx_lock(dev);
...@@ -71,11 +74,13 @@ static void rmnet_map_send_ack(struct sk_buff *skb, ...@@ -71,11 +74,13 @@ static void rmnet_map_send_ack(struct sk_buff *skb,
*/ */
void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port)
{ {
struct rmnet_map_header *map_header = (void *)skb->data;
struct rmnet_map_control_command *cmd; struct rmnet_map_control_command *cmd;
unsigned char command_name; unsigned char command_name;
unsigned char rc = 0; unsigned char rc = 0;
cmd = RMNET_MAP_GET_CMD_START(skb); /* Command data immediately follows the MAP header */
cmd = (struct rmnet_map_control_command *)(map_header + 1);
command_name = cmd->command_name; command_name = cmd->command_name;
switch (command_name) { switch (command_name) {
......
...@@ -315,7 +315,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, ...@@ -315,7 +315,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb,
return NULL; return NULL;
maph = (struct rmnet_map_header *)skb->data; maph = (struct rmnet_map_header *)skb->data;
packet_len = ntohs(maph->pkt_len) + sizeof(struct rmnet_map_header); packet_len = ntohs(maph->pkt_len) + sizeof(*maph);
if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4)
packet_len += sizeof(struct rmnet_map_dl_csum_trailer); packet_len += sizeof(struct rmnet_map_dl_csum_trailer);
...@@ -324,7 +324,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, ...@@ -324,7 +324,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb,
return NULL; return NULL;
/* Some hardware can send us empty frames. Catch them */ /* Some hardware can send us empty frames. Catch them */
if (ntohs(maph->pkt_len) == 0) if (!maph->pkt_len)
return NULL; return NULL;
skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING, GFP_ATOMIC); skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING, GFP_ATOMIC);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment