Skip to content

Commit c593642

Browse files
bpankajlkees
authored andcommitted
treewide: Use sizeof_field() macro
Replace all the occurrences of FIELD_SIZEOF() with sizeof_field() except at places where these are defined. Later patches will remove the unused definition of FIELD_SIZEOF(). This patch is generated using following script: EXCLUDE_FILES="include/linux/stddef.h|include/linux/kernel.h" git grep -l -e "\bFIELD_SIZEOF\b" | while read file; do if [[ "$file" =~ $EXCLUDE_FILES ]]; then continue fi sed -i -e 's/\bFIELD_SIZEOF\b/sizeof_field/g' $file; done Signed-off-by: Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com> Link: https://lore.kernel.org/r/20190924105839.110713-3-pankaj.laxminarayan.bharadiya@intel.com Co-developed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: David Miller <davem@davemloft.net> # for net
1 parent e437232 commit c593642

115 files changed

Lines changed: 298 additions & 298 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/process/coding-style.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ Similarly, if you need to calculate the size of some structure member, use
988988

989989
.. code-block:: c
990990
991-
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
991+
#define sizeof_field(t, f) (sizeof(((t*)0)->f))
992992
993993
There are also min() and max() macros that do strict type checking if you
994994
need them. Feel free to peruse that header file to see what else is already

‎Documentation/translations/it_IT/process/coding-style.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ struttura, usate
10051005

10061006
.. code-block:: c
10071007
1008-
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
1008+
#define sizeof_field(t, f) (sizeof(((t*)0)->f))
10091009
10101010
Ci sono anche le macro min() e max() che, se vi serve, effettuano un controllo
10111011
rigido sui tipi. Sentitevi liberi di leggere attentamente questo file

‎Documentation/translations/zh_CN/process/coding-style.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ inline gcc 也可以自动使其内联。而且其他用户可能会要求移除
826826

827827
.. code-block:: c
828828
829-
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
829+
#define sizeof_field(t, f) (sizeof(((t*)0)->f))
830830
831831
还有可以做严格的类型检查的 min() 和 max() 宏,如果你需要可以使用它们。你可以
832832
自己看看那个头文件里还定义了什么你可以拿来用的东西,如果有定义的话,你就不应

‎arch/arc/kernel/unwind.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ do { \
4242

4343
#define EXTRA_INFO(f) { \
4444
BUILD_BUG_ON_ZERO(offsetof(struct unwind_frame_info, f) \
45-
% FIELD_SIZEOF(struct unwind_frame_info, f)) \
45+
% sizeof_field(struct unwind_frame_info, f)) \
4646
+ offsetof(struct unwind_frame_info, f) \
47-
/ FIELD_SIZEOF(struct unwind_frame_info, f), \
48-
FIELD_SIZEOF(struct unwind_frame_info, f) \
47+
/ sizeof_field(struct unwind_frame_info, f), \
48+
sizeof_field(struct unwind_frame_info, f) \
4949
}
5050
#define PTREGS_INFO(f) EXTRA_INFO(regs.f)
5151

‎arch/powerpc/net/bpf_jit32.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
9797
#ifdef CONFIG_SMP
9898
#ifdef CONFIG_PPC64
9999
#define PPC_BPF_LOAD_CPU(r) \
100-
do { BUILD_BUG_ON(FIELD_SIZEOF(struct paca_struct, paca_index) != 2); \
100+
do { BUILD_BUG_ON(sizeof_field(struct paca_struct, paca_index) != 2); \
101101
PPC_LHZ_OFFS(r, 13, offsetof(struct paca_struct, paca_index)); \
102102
} while (0)
103103
#else
104104
#define PPC_BPF_LOAD_CPU(r) \
105-
do { BUILD_BUG_ON(FIELD_SIZEOF(struct task_struct, cpu) != 4); \
105+
do { BUILD_BUG_ON(sizeof_field(struct task_struct, cpu) != 4); \
106106
PPC_LHZ_OFFS(r, 2, offsetof(struct task_struct, cpu)); \
107107
} while(0)
108108
#endif

‎arch/powerpc/net/bpf_jit_comp.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
321321
ctx->seen |= SEEN_XREG | SEEN_MEM | (1<<(K & 0xf));
322322
break;
323323
case BPF_LD | BPF_W | BPF_LEN: /* A = skb->len; */
324-
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4);
324+
BUILD_BUG_ON(sizeof_field(struct sk_buff, len) != 4);
325325
PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff, len));
326326
break;
327327
case BPF_LDX | BPF_W | BPF_ABS: /* A = *((u32 *)(seccomp_data + K)); */
@@ -333,16 +333,16 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
333333

334334
/*** Ancillary info loads ***/
335335
case BPF_ANC | SKF_AD_PROTOCOL: /* A = ntohs(skb->protocol); */
336-
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
336+
BUILD_BUG_ON(sizeof_field(struct sk_buff,
337337
protocol) != 2);
338338
PPC_NTOHS_OFFS(r_A, r_skb, offsetof(struct sk_buff,
339339
protocol));
340340
break;
341341
case BPF_ANC | SKF_AD_IFINDEX:
342342
case BPF_ANC | SKF_AD_HATYPE:
343-
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
343+
BUILD_BUG_ON(sizeof_field(struct net_device,
344344
ifindex) != 4);
345-
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
345+
BUILD_BUG_ON(sizeof_field(struct net_device,
346346
type) != 2);
347347
PPC_LL_OFFS(r_scratch1, r_skb, offsetof(struct sk_buff,
348348
dev));
@@ -365,17 +365,17 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
365365

366366
break;
367367
case BPF_ANC | SKF_AD_MARK:
368-
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
368+
BUILD_BUG_ON(sizeof_field(struct sk_buff, mark) != 4);
369369
PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
370370
mark));
371371
break;
372372
case BPF_ANC | SKF_AD_RXHASH:
373-
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
373+
BUILD_BUG_ON(sizeof_field(struct sk_buff, hash) != 4);
374374
PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
375375
hash));
376376
break;
377377
case BPF_ANC | SKF_AD_VLAN_TAG:
378-
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
378+
BUILD_BUG_ON(sizeof_field(struct sk_buff, vlan_tci) != 2);
379379

380380
PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
381381
vlan_tci));
@@ -388,7 +388,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
388388
PPC_ANDI(r_A, r_A, 1);
389389
break;
390390
case BPF_ANC | SKF_AD_QUEUE:
391-
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
391+
BUILD_BUG_ON(sizeof_field(struct sk_buff,
392392
queue_mapping) != 2);
393393
PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
394394
queue_mapping));

‎arch/sparc/net/bpf_jit_comp_32.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ do { \
180180

181181
#define emit_loadptr(BASE, STRUCT, FIELD, DEST) \
182182
do { unsigned int _off = offsetof(STRUCT, FIELD); \
183-
BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(void *)); \
183+
BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(void *)); \
184184
*prog++ = LDPTRI | RS1(BASE) | S13(_off) | RD(DEST); \
185185
} while (0)
186186

187187
#define emit_load32(BASE, STRUCT, FIELD, DEST) \
188188
do { unsigned int _off = offsetof(STRUCT, FIELD); \
189-
BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u32)); \
189+
BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(u32)); \
190190
*prog++ = LD32I | RS1(BASE) | S13(_off) | RD(DEST); \
191191
} while (0)
192192

193193
#define emit_load16(BASE, STRUCT, FIELD, DEST) \
194194
do { unsigned int _off = offsetof(STRUCT, FIELD); \
195-
BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u16)); \
195+
BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(u16)); \
196196
*prog++ = LD16I | RS1(BASE) | S13(_off) | RD(DEST); \
197197
} while (0)
198198

@@ -202,7 +202,7 @@ do { unsigned int _off = offsetof(STRUCT, FIELD); \
202202
} while (0)
203203

204204
#define emit_load8(BASE, STRUCT, FIELD, DEST) \
205-
do { BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u8)); \
205+
do { BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(u8)); \
206206
__emit_load8(BASE, STRUCT, FIELD, DEST); \
207207
} while (0)
208208

‎arch/x86/kernel/fpu/xstate.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static void __init setup_xstate_features(void)
259259
xmm_space);
260260

261261
xstate_offsets[XFEATURE_SSE] = xstate_sizes[XFEATURE_FP];
262-
xstate_sizes[XFEATURE_SSE] = FIELD_SIZEOF(struct fxregs_state,
262+
xstate_sizes[XFEATURE_SSE] = sizeof_field(struct fxregs_state,
263263
xmm_space);
264264

265265
for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {

‎block/blk-core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,9 @@ int __init blk_dev_init(void)
17921792
{
17931793
BUILD_BUG_ON(REQ_OP_LAST >= (1 << REQ_OP_BITS));
17941794
BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
1795-
FIELD_SIZEOF(struct request, cmd_flags));
1795+
sizeof_field(struct request, cmd_flags));
17961796
BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
1797-
FIELD_SIZEOF(struct bio, bi_opf));
1797+
sizeof_field(struct bio, bi_opf));
17981798

17991799
/* used for unplugging and affects IO latency/throughput - HIGHPRI */
18001800
kblockd_workqueue = alloc_workqueue("kblockd",

‎crypto/adiantum.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,10 @@ static int adiantum_init_tfm(struct crypto_skcipher *tfm)
436436

437437
BUILD_BUG_ON(offsetofend(struct adiantum_request_ctx, u) !=
438438
sizeof(struct adiantum_request_ctx));
439-
subreq_size = max(FIELD_SIZEOF(struct adiantum_request_ctx,
439+
subreq_size = max(sizeof_field(struct adiantum_request_ctx,
440440
u.hash_desc) +
441441
crypto_shash_descsize(hash),
442-
FIELD_SIZEOF(struct adiantum_request_ctx,
442+
sizeof_field(struct adiantum_request_ctx,
443443
u.streamcipher_req) +
444444
crypto_skcipher_reqsize(streamcipher));
445445

0 commit comments

Comments
 (0)