2018-09-19 10:41:38

by zhong jiang

[permalink] [raw]
Subject: [PATCH 0/5] Use FIELD_SIZEOF directly instead of reimplementing its function

The issue is detected with the help of Coccinelle.

zhong jiang (5):
net: iucv: Use FIELD_SIZEOF directly instead of reimplementing its
function
net: sched: Use FIELD_SIZEOF directly instead of reimplementing its
function
net: core: Use FIELD_SIZEOF directly instead of reimplementing its
function
net: qede: Use FIELD_SIZEOF directly instead of reimplementing its
function
net: ti: Use FIELD_SIZEOF directly instead of reimplementing its
function

drivers/net/ethernet/qlogic/qede/qede.h | 2 +-
drivers/net/ethernet/ti/cpsw.c | 6 +++---
net/core/flow_dissector.c | 10 +++++-----
net/iucv/af_iucv.c | 2 +-
net/sched/cls_flower.c | 2 +-
5 files changed, 11 insertions(+), 11 deletions(-)

--
1.7.12.4



2018-09-19 10:39:19

by zhong jiang

[permalink] [raw]
Subject: [PATCH 4/5] net: qede: Use FIELD_SIZEOF directly instead of reimplementing its function

FIELD_SIZEOF is defined as a macro to calculate the specified value. Therefore,
We prefer to use the macro rather than calculating its value.

Signed-off-by: zhong jiang <[email protected]>
---
drivers/net/ethernet/qlogic/qede/qede.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede.h b/drivers/net/ethernet/qlogic/qede/qede.h
index 6a4d266..c73839c 100644
--- a/drivers/net/ethernet/qlogic/qede/qede.h
+++ b/drivers/net/ethernet/qlogic/qede/qede.h
@@ -440,7 +440,7 @@ struct qede_fastpath {
struct qede_tx_queue *txq;
struct qede_tx_queue *xdp_tx;

-#define VEC_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
+ #define VEC_NAME_SIZE (FIELD_SIZEOF(struct net_device, name) + 8)
char name[VEC_NAME_SIZE];
};

--
1.7.12.4


2018-09-19 10:39:27

by zhong jiang

[permalink] [raw]
Subject: [PATCH 2/5] net: sched: Use FIELD_SIZEOF directly instead of reimplementing its function

FIELD_SIZEOF is defined as a macro to calculate the specified value. Therefore,
We prefer to use the macro rather than calculating its value.

Signed-off-by: zhong jiang <[email protected]>
---
net/sched/cls_flower.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 4b8dd37..9aada2d 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -993,7 +993,7 @@ static int fl_init_mask_hashtable(struct fl_flow_mask *mask)
}

#define FL_KEY_MEMBER_OFFSET(member) offsetof(struct fl_flow_key, member)
-#define FL_KEY_MEMBER_SIZE(member) (sizeof(((struct fl_flow_key *) 0)->member))
+#define FL_KEY_MEMBER_SIZE(member) FIELD_SIZEOF(struct fl_flow_key, member)

#define FL_KEY_IS_MASKED(mask, member) \
memchr_inv(((char *)mask) + FL_KEY_MEMBER_OFFSET(member), \
--
1.7.12.4


2018-09-19 10:39:50

by zhong jiang

[permalink] [raw]
Subject: [PATCH 5/5] net: ti: Use FIELD_SIZEOF directly instead of reimplementing its function

FIELD_SIZEOF is defined as a macro to calculate the specified value. Therefore,
We prefer to use the macro rather than calculating its value.

Signed-off-by: zhong jiang <[email protected]>
---
drivers/net/ethernet/ti/cpsw.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 832bce0..16dcbf3 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -484,13 +484,13 @@ enum {
};

#define CPSW_STAT(m) CPSW_STATS, \
- sizeof(((struct cpsw_hw_stats *)0)->m), \
+ FIELD_SIZEOF(struct cpsw_hw_stats, m), \
offsetof(struct cpsw_hw_stats, m)
#define CPDMA_RX_STAT(m) CPDMA_RX_STATS, \
- sizeof(((struct cpdma_chan_stats *)0)->m), \
+ FIELD_SIZEOF(struct cpdma_chan_stats, m), \
offsetof(struct cpdma_chan_stats, m)
#define CPDMA_TX_STAT(m) CPDMA_TX_STATS, \
- sizeof(((struct cpdma_chan_stats *)0)->m), \
+ FIELD_SIZEOF(struct cpdma_chan_stats, m), \
offsetof(struct cpdma_chan_stats, m)

static const struct cpsw_stats cpsw_gstrings_stats[] = {
--
1.7.12.4


2018-09-19 10:40:02

by zhong jiang

[permalink] [raw]
Subject: [PATCH 1/5] net: iucv: Use FIELD_SIZEOF directly instead of reimplementing its function

FIELD_SIZEOF is defined as a macro to calculate the specified value. Therefore,
We prefer to use the macro rather than calculating its value.

Signed-off-by: zhong jiang <[email protected]>
---
net/iucv/af_iucv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index e2f16a0..5b68ee9 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -48,7 +48,7 @@
static const u8 iprm_shutdown[8] =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};

-#define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class))
+#define TRGCLS_SIZE FIELD_SIZEOF(struct iucv_message, class)

#define __iucv_sock_wait(sk, condition, timeo, ret) \
do { \
--
1.7.12.4


2018-09-19 10:40:45

by zhong jiang

[permalink] [raw]
Subject: [PATCH 3/5] net: core: Use FIELD_SIZEOF directly instead of reimplementing its function

FIELD_SIZEOF is defined as a macro to calculate the specified value. Therefore,
We prefer to use the macro rather than calculating its value.

Signed-off-by: zhong jiang <[email protected]>
---
net/core/flow_dissector.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 5c5dd74..aeac884 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -423,8 +423,8 @@ __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
offset += sizeof(struct gre_base_hdr);

if (hdr->flags & GRE_CSUM)
- offset += sizeof(((struct gre_full_hdr *) 0)->csum) +
- sizeof(((struct gre_full_hdr *) 0)->reserved1);
+ offset += FIELD_SIZEOF(struct gre_full_hdr, csum) +
+ FIELD_SIZEOF(struct gre_full_hdr, reserved1);

if (hdr->flags & GRE_KEY) {
const __be32 *keyid;
@@ -446,11 +446,11 @@ __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
else
key_keyid->keyid = *keyid & GRE_PPTP_KEY_MASK;
}
- offset += sizeof(((struct gre_full_hdr *) 0)->key);
+ offset += FIELD_SIZEOF(struct gre_full_hdr, key);
}

if (hdr->flags & GRE_SEQ)
- offset += sizeof(((struct pptp_gre_header *) 0)->seq);
+ offset += FIELD_SIZEOF(struct pptp_gre_header, seq);

if (gre_ver == 0) {
if (*p_proto == htons(ETH_P_TEB)) {
@@ -477,7 +477,7 @@ __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
u8 *ppp_hdr;

if (hdr->flags & GRE_ACK)
- offset += sizeof(((struct pptp_gre_header *) 0)->ack);
+ offset += FIELD_SIZEOF(struct pptp_gre_header, ack);

ppp_hdr = __skb_header_pointer(skb, *p_nhoff + offset,
sizeof(_ppp_hdr),
--
1.7.12.4


2018-09-19 11:23:03

by Christian Borntraeger

[permalink] [raw]
Subject: Re: [PATCH 1/5] net: iucv: Use FIELD_SIZEOF directly instead of reimplementing its function

Can you please copy Ursula and Julian for iucv related patches?

On 09/19/2018 12:26 PM, zhong jiang wrote:
> FIELD_SIZEOF is defined as a macro to calculate the specified value. Therefore,
> We prefer to use the macro rather than calculating its value.
>
> Signed-off-by: zhong jiang <[email protected]>
> ---
> net/iucv/af_iucv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index e2f16a0..5b68ee9 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
> @@ -48,7 +48,7 @@
> static const u8 iprm_shutdown[8] =
> {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
>
> -#define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class))
> +#define TRGCLS_SIZE FIELD_SIZEOF(struct iucv_message, class)
>
> #define __iucv_sock_wait(sk, condition, timeo, ret) \
> do { \
>


2018-09-19 11:32:54

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH 1/5] net: iucv: Use FIELD_SIZEOF directly instead of reimplementing its function

On 2018/9/19 19:21, Christian Borntraeger wrote:
> Can you please copy Ursula and Julian for iucv related patches?
Thanks, Maybe I forget cc more maintainer. So I will resend in v2.

Sincerely,
zhong jiang
> On 09/19/2018 12:26 PM, zhong jiang wrote:
>> FIELD_SIZEOF is defined as a macro to calculate the specified value. Therefore,
>> We prefer to use the macro rather than calculating its value.
>>
>> Signed-off-by: zhong jiang <[email protected]>
>> ---
>> net/iucv/af_iucv.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
>> index e2f16a0..5b68ee9 100644
>> --- a/net/iucv/af_iucv.c
>> +++ b/net/iucv/af_iucv.c
>> @@ -48,7 +48,7 @@
>> static const u8 iprm_shutdown[8] =
>> {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
>>
>> -#define TRGCLS_SIZE (sizeof(((struct iucv_message *)0)->class))
>> +#define TRGCLS_SIZE FIELD_SIZEOF(struct iucv_message, class)
>>
>> #define __iucv_sock_wait(sk, condition, timeo, ret) \
>> do { \
>>
>
>