Message ID | 20190520135354.18628-4-elder@linaro.org |
---|---|
State | New |
Headers | show |
Series | net: introduce "include/linux/if_rmnet.h" | expand |
On Mon 20 May 06:53 PDT 2019, Alex Elder wrote: > Using C bitfields (e.g. int foo : 3) is not portable. So stop > using them for the command/data flag and the pad length fields in > the rmnet_map structure. Instead, use the functions defined in > <linux/bitfield.h> along with field mask constants to extract or > assign values within an integral structure member of a known size. > Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> > Signed-off-by: Alex Elder <elder@linaro.org> > --- > drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 +++-- > drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 8 +++++--- > drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 5 ++++- > 3 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c > index 4c1b62b72504..5fff6c78ecd5 100644 > --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c > +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c > @@ -13,6 +13,7 @@ > * > */ > > +#include <linux/bitfield.h> > #include <linux/netdevice.h> > #include <linux/netdev_features.h> > #include <linux/if_arp.h> > @@ -70,7 +71,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, > u16 len, pad; > u8 mux_id; > > - if (map_header->cd_bit) { > + if (u8_get_bits(map_header->cmd_pad_len, RMNET_MAP_CMD_FMASK)) { > if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) > return rmnet_map_command(skb, port); > > @@ -78,7 +79,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, > } > > mux_id = map_header->mux_id; > - pad = map_header->pad_len; > + pad = u8_get_bits(map_header->cmd_pad_len, RMNET_MAP_PAD_LEN_FMASK); > len = ntohs(map_header->pkt_len) - pad; > > if (mux_id >= RMNET_MAX_LOGICAL_EP) > diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h > index a30a7b405a11..a56209645c81 100644 > --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h > +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h > @@ -40,13 +40,15 @@ enum rmnet_map_commands { > }; > > struct rmnet_map_header { > - u8 cd_bit:1; > - u8 reserved_bit:1; > - u8 pad_len:6; > + u8 cmd_pad_len; /* RMNET_MAP_* */ > u8 mux_id; > __be16 pkt_len; > } __aligned(1); > > +#define RMNET_MAP_CMD_FMASK GENMASK(0, 0) /* 0: data; 1: cmd */ > +#define RMNET_MAP_RESERVED_FMASK GENMASK(1, 1) > +#define RMNET_MAP_PAD_LEN_FMASK GENMASK(7, 2) > + > struct rmnet_map_dl_csum_trailer { > u8 reserved1; > u8 valid:1; > diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c > index 498f20ba1826..10d2d582a9ce 100644 > --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c > +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c > @@ -13,6 +13,7 @@ > * > */ > > +#include <linux/bitfield.h> > #include <linux/netdevice.h> > #include <linux/ip.h> > #include <linux/ipv6.h> > @@ -301,7 +302,9 @@ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, > > done: > map_header->pkt_len = htons(map_datalen + padding); > - map_header->pad_len = padding & 0x3F; > + /* This is a data packet, so cmd field is 0 */ > + map_header->cmd_pad_len = > + u8_encode_bits(padding, RMNET_MAP_PAD_LEN_FMASK); > > return map_header; > } > -- > 2.20.1 >
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index 4c1b62b72504..5fff6c78ecd5 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -13,6 +13,7 @@ * */ +#include <linux/bitfield.h> #include <linux/netdevice.h> #include <linux/netdev_features.h> #include <linux/if_arp.h> @@ -70,7 +71,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, u16 len, pad; u8 mux_id; - if (map_header->cd_bit) { + if (u8_get_bits(map_header->cmd_pad_len, RMNET_MAP_CMD_FMASK)) { if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) return rmnet_map_command(skb, port); @@ -78,7 +79,7 @@ __rmnet_map_ingress_handler(struct sk_buff *skb, } mux_id = map_header->mux_id; - pad = map_header->pad_len; + pad = u8_get_bits(map_header->cmd_pad_len, RMNET_MAP_PAD_LEN_FMASK); len = ntohs(map_header->pkt_len) - pad; if (mux_id >= RMNET_MAX_LOGICAL_EP) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h index a30a7b405a11..a56209645c81 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h @@ -40,13 +40,15 @@ enum rmnet_map_commands { }; struct rmnet_map_header { - u8 cd_bit:1; - u8 reserved_bit:1; - u8 pad_len:6; + u8 cmd_pad_len; /* RMNET_MAP_* */ u8 mux_id; __be16 pkt_len; } __aligned(1); +#define RMNET_MAP_CMD_FMASK GENMASK(0, 0) /* 0: data; 1: cmd */ +#define RMNET_MAP_RESERVED_FMASK GENMASK(1, 1) +#define RMNET_MAP_PAD_LEN_FMASK GENMASK(7, 2) + struct rmnet_map_dl_csum_trailer { u8 reserved1; u8 valid:1; diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 498f20ba1826..10d2d582a9ce 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -13,6 +13,7 @@ * */ +#include <linux/bitfield.h> #include <linux/netdevice.h> #include <linux/ip.h> #include <linux/ipv6.h> @@ -301,7 +302,9 @@ struct rmnet_map_header *rmnet_map_add_map_header(struct sk_buff *skb, done: map_header->pkt_len = htons(map_datalen + padding); - map_header->pad_len = padding & 0x3F; + /* This is a data packet, so cmd field is 0 */ + map_header->cmd_pad_len = + u8_encode_bits(padding, RMNET_MAP_PAD_LEN_FMASK); return map_header; }
Using C bitfields (e.g. int foo : 3) is not portable. So stop using them for the command/data flag and the pad length fields in the rmnet_map structure. Instead, use the functions defined in <linux/bitfield.h> along with field mask constants to extract or assign values within an integral structure member of a known size. Signed-off-by: Alex Elder <elder@linaro.org> --- drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 5 +++-- drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 8 +++++--- drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) -- 2.20.1