mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
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
This commit is contained in:
committed by
Kees Cook
parent
e43723292d
commit
c593642c8b
@@ -988,7 +988,7 @@ Similarly, if you need to calculate the size of some structure member, use
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
|
||||
#define sizeof_field(t, f) (sizeof(((t*)0)->f))
|
||||
|
||||
There are also min() and max() macros that do strict type checking if you
|
||||
need them. Feel free to peruse that header file to see what else is already
|
||||
|
||||
@@ -1005,7 +1005,7 @@ struttura, usate
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
|
||||
#define sizeof_field(t, f) (sizeof(((t*)0)->f))
|
||||
|
||||
Ci sono anche le macro min() e max() che, se vi serve, effettuano un controllo
|
||||
rigido sui tipi. Sentitevi liberi di leggere attentamente questo file
|
||||
|
||||
@@ -826,7 +826,7 @@ inline gcc 也可以自动使其内联。而且其他用户可能会要求移除
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
|
||||
#define sizeof_field(t, f) (sizeof(((t*)0)->f))
|
||||
|
||||
还有可以做严格的类型检查的 min() 和 max() 宏,如果你需要可以使用它们。你可以
|
||||
自己看看那个头文件里还定义了什么你可以拿来用的东西,如果有定义的话,你就不应
|
||||
|
||||
@@ -42,10 +42,10 @@ do { \
|
||||
|
||||
#define EXTRA_INFO(f) { \
|
||||
BUILD_BUG_ON_ZERO(offsetof(struct unwind_frame_info, f) \
|
||||
% FIELD_SIZEOF(struct unwind_frame_info, f)) \
|
||||
% sizeof_field(struct unwind_frame_info, f)) \
|
||||
+ offsetof(struct unwind_frame_info, f) \
|
||||
/ FIELD_SIZEOF(struct unwind_frame_info, f), \
|
||||
FIELD_SIZEOF(struct unwind_frame_info, f) \
|
||||
/ sizeof_field(struct unwind_frame_info, f), \
|
||||
sizeof_field(struct unwind_frame_info, f) \
|
||||
}
|
||||
#define PTREGS_INFO(f) EXTRA_INFO(regs.f)
|
||||
|
||||
|
||||
@@ -97,12 +97,12 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
|
||||
#ifdef CONFIG_SMP
|
||||
#ifdef CONFIG_PPC64
|
||||
#define PPC_BPF_LOAD_CPU(r) \
|
||||
do { BUILD_BUG_ON(FIELD_SIZEOF(struct paca_struct, paca_index) != 2); \
|
||||
do { BUILD_BUG_ON(sizeof_field(struct paca_struct, paca_index) != 2); \
|
||||
PPC_LHZ_OFFS(r, 13, offsetof(struct paca_struct, paca_index)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define PPC_BPF_LOAD_CPU(r) \
|
||||
do { BUILD_BUG_ON(FIELD_SIZEOF(struct task_struct, cpu) != 4); \
|
||||
do { BUILD_BUG_ON(sizeof_field(struct task_struct, cpu) != 4); \
|
||||
PPC_LHZ_OFFS(r, 2, offsetof(struct task_struct, cpu)); \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
@@ -321,7 +321,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
|
||||
ctx->seen |= SEEN_XREG | SEEN_MEM | (1<<(K & 0xf));
|
||||
break;
|
||||
case BPF_LD | BPF_W | BPF_LEN: /* A = skb->len; */
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4);
|
||||
BUILD_BUG_ON(sizeof_field(struct sk_buff, len) != 4);
|
||||
PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff, len));
|
||||
break;
|
||||
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,
|
||||
|
||||
/*** Ancillary info loads ***/
|
||||
case BPF_ANC | SKF_AD_PROTOCOL: /* A = ntohs(skb->protocol); */
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
|
||||
BUILD_BUG_ON(sizeof_field(struct sk_buff,
|
||||
protocol) != 2);
|
||||
PPC_NTOHS_OFFS(r_A, r_skb, offsetof(struct sk_buff,
|
||||
protocol));
|
||||
break;
|
||||
case BPF_ANC | SKF_AD_IFINDEX:
|
||||
case BPF_ANC | SKF_AD_HATYPE:
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
|
||||
BUILD_BUG_ON(sizeof_field(struct net_device,
|
||||
ifindex) != 4);
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
|
||||
BUILD_BUG_ON(sizeof_field(struct net_device,
|
||||
type) != 2);
|
||||
PPC_LL_OFFS(r_scratch1, r_skb, offsetof(struct sk_buff,
|
||||
dev));
|
||||
@@ -365,17 +365,17 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
|
||||
|
||||
break;
|
||||
case BPF_ANC | SKF_AD_MARK:
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
|
||||
BUILD_BUG_ON(sizeof_field(struct sk_buff, mark) != 4);
|
||||
PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
|
||||
mark));
|
||||
break;
|
||||
case BPF_ANC | SKF_AD_RXHASH:
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
|
||||
BUILD_BUG_ON(sizeof_field(struct sk_buff, hash) != 4);
|
||||
PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
|
||||
hash));
|
||||
break;
|
||||
case BPF_ANC | SKF_AD_VLAN_TAG:
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
|
||||
BUILD_BUG_ON(sizeof_field(struct sk_buff, vlan_tci) != 2);
|
||||
|
||||
PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
|
||||
vlan_tci));
|
||||
@@ -388,7 +388,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
|
||||
PPC_ANDI(r_A, r_A, 1);
|
||||
break;
|
||||
case BPF_ANC | SKF_AD_QUEUE:
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
|
||||
BUILD_BUG_ON(sizeof_field(struct sk_buff,
|
||||
queue_mapping) != 2);
|
||||
PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
|
||||
queue_mapping));
|
||||
|
||||
@@ -180,19 +180,19 @@ do { \
|
||||
|
||||
#define emit_loadptr(BASE, STRUCT, FIELD, DEST) \
|
||||
do { unsigned int _off = offsetof(STRUCT, FIELD); \
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(void *)); \
|
||||
BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(void *)); \
|
||||
*prog++ = LDPTRI | RS1(BASE) | S13(_off) | RD(DEST); \
|
||||
} while (0)
|
||||
|
||||
#define emit_load32(BASE, STRUCT, FIELD, DEST) \
|
||||
do { unsigned int _off = offsetof(STRUCT, FIELD); \
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u32)); \
|
||||
BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(u32)); \
|
||||
*prog++ = LD32I | RS1(BASE) | S13(_off) | RD(DEST); \
|
||||
} while (0)
|
||||
|
||||
#define emit_load16(BASE, STRUCT, FIELD, DEST) \
|
||||
do { unsigned int _off = offsetof(STRUCT, FIELD); \
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u16)); \
|
||||
BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(u16)); \
|
||||
*prog++ = LD16I | RS1(BASE) | S13(_off) | RD(DEST); \
|
||||
} while (0)
|
||||
|
||||
@@ -202,7 +202,7 @@ do { unsigned int _off = offsetof(STRUCT, FIELD); \
|
||||
} while (0)
|
||||
|
||||
#define emit_load8(BASE, STRUCT, FIELD, DEST) \
|
||||
do { BUILD_BUG_ON(FIELD_SIZEOF(STRUCT, FIELD) != sizeof(u8)); \
|
||||
do { BUILD_BUG_ON(sizeof_field(STRUCT, FIELD) != sizeof(u8)); \
|
||||
__emit_load8(BASE, STRUCT, FIELD, DEST); \
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ static void __init setup_xstate_features(void)
|
||||
xmm_space);
|
||||
|
||||
xstate_offsets[XFEATURE_SSE] = xstate_sizes[XFEATURE_FP];
|
||||
xstate_sizes[XFEATURE_SSE] = FIELD_SIZEOF(struct fxregs_state,
|
||||
xstate_sizes[XFEATURE_SSE] = sizeof_field(struct fxregs_state,
|
||||
xmm_space);
|
||||
|
||||
for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) {
|
||||
|
||||
@@ -1792,9 +1792,9 @@ int __init blk_dev_init(void)
|
||||
{
|
||||
BUILD_BUG_ON(REQ_OP_LAST >= (1 << REQ_OP_BITS));
|
||||
BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
|
||||
FIELD_SIZEOF(struct request, cmd_flags));
|
||||
sizeof_field(struct request, cmd_flags));
|
||||
BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
|
||||
FIELD_SIZEOF(struct bio, bi_opf));
|
||||
sizeof_field(struct bio, bi_opf));
|
||||
|
||||
/* used for unplugging and affects IO latency/throughput - HIGHPRI */
|
||||
kblockd_workqueue = alloc_workqueue("kblockd",
|
||||
|
||||
@@ -436,10 +436,10 @@ static int adiantum_init_tfm(struct crypto_skcipher *tfm)
|
||||
|
||||
BUILD_BUG_ON(offsetofend(struct adiantum_request_ctx, u) !=
|
||||
sizeof(struct adiantum_request_ctx));
|
||||
subreq_size = max(FIELD_SIZEOF(struct adiantum_request_ctx,
|
||||
subreq_size = max(sizeof_field(struct adiantum_request_ctx,
|
||||
u.hash_desc) +
|
||||
crypto_shash_descsize(hash),
|
||||
FIELD_SIZEOF(struct adiantum_request_ctx,
|
||||
sizeof_field(struct adiantum_request_ctx,
|
||||
u.streamcipher_req) +
|
||||
crypto_skcipher_reqsize(streamcipher));
|
||||
|
||||
|
||||
@@ -347,7 +347,7 @@ static int essiv_aead_init_tfm(struct crypto_aead *tfm)
|
||||
if (IS_ERR(aead))
|
||||
return PTR_ERR(aead);
|
||||
|
||||
subreq_size = FIELD_SIZEOF(struct essiv_aead_request_ctx, aead_req) +
|
||||
subreq_size = sizeof_field(struct essiv_aead_request_ctx, aead_req) +
|
||||
crypto_aead_reqsize(aead);
|
||||
|
||||
tctx->ivoffset = offsetof(struct essiv_aead_request_ctx, aead_req) +
|
||||
|
||||
@@ -681,7 +681,7 @@ device_initcall(efi_load_efivars);
|
||||
{ name }, \
|
||||
{ prop }, \
|
||||
offsetof(struct efi_fdt_params, field), \
|
||||
FIELD_SIZEOF(struct efi_fdt_params, field) \
|
||||
sizeof_field(struct efi_fdt_params, field) \
|
||||
}
|
||||
|
||||
struct params {
|
||||
|
||||
@@ -145,7 +145,7 @@ static inline bool is_rdma_read_cap(struct efa_dev *dev)
|
||||
}
|
||||
|
||||
#define field_avail(x, fld, sz) (offsetof(typeof(x), fld) + \
|
||||
FIELD_SIZEOF(typeof(x), fld) <= (sz))
|
||||
sizeof_field(typeof(x), fld) <= (sz))
|
||||
|
||||
#define is_reserved_cleared(reserved) \
|
||||
!memchr_inv(reserved, 0, sizeof(reserved))
|
||||
|
||||
@@ -848,7 +848,7 @@ static const struct rhashtable_params sdma_rht_params = {
|
||||
.nelem_hint = NR_CPUS_HINT,
|
||||
.head_offset = offsetof(struct sdma_rht_node, node),
|
||||
.key_offset = offsetof(struct sdma_rht_node, cpu_id),
|
||||
.key_len = FIELD_SIZEOF(struct sdma_rht_node, cpu_id),
|
||||
.key_len = sizeof_field(struct sdma_rht_node, cpu_id),
|
||||
.max_size = NR_CPUS,
|
||||
.min_size = 8,
|
||||
.automatic_shrinking = true,
|
||||
|
||||
@@ -107,9 +107,9 @@ enum {
|
||||
HFI1_HAS_GRH = (1 << 0),
|
||||
};
|
||||
|
||||
#define LRH_16B_BYTES (FIELD_SIZEOF(struct hfi1_16b_header, lrh))
|
||||
#define LRH_16B_BYTES (sizeof_field(struct hfi1_16b_header, lrh))
|
||||
#define LRH_16B_DWORDS (LRH_16B_BYTES / sizeof(u32))
|
||||
#define LRH_9B_BYTES (FIELD_SIZEOF(struct ib_header, lrh))
|
||||
#define LRH_9B_BYTES (sizeof_field(struct ib_header, lrh))
|
||||
#define LRH_9B_DWORDS (LRH_9B_BYTES / sizeof(u32))
|
||||
|
||||
/* 24Bits for qpn, upper 8Bits reserved */
|
||||
|
||||
@@ -63,7 +63,7 @@ struct vnic_stats {
|
||||
};
|
||||
};
|
||||
|
||||
#define VNIC_STAT(m) { FIELD_SIZEOF(struct opa_vnic_stats, m), \
|
||||
#define VNIC_STAT(m) { sizeof_field(struct opa_vnic_stats, m), \
|
||||
offsetof(struct opa_vnic_stats, m) }
|
||||
|
||||
static struct vnic_stats vnic_gstrings_stats[] = {
|
||||
|
||||
@@ -1360,7 +1360,7 @@ int ppl_init_log(struct r5conf *conf)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
max_disks = FIELD_SIZEOF(struct ppl_log, disk_flush_bitmap) *
|
||||
max_disks = sizeof_field(struct ppl_log, disk_flush_bitmap) *
|
||||
BITS_PER_BYTE;
|
||||
if (conf->raid_disks > max_disks) {
|
||||
pr_warn("md/raid:%s PPL doesn't support over %d disks in the array\n",
|
||||
|
||||
@@ -753,7 +753,7 @@ static const struct preview_update update_attrs[] = {
|
||||
preview_config_luma_enhancement,
|
||||
preview_enable_luma_enhancement,
|
||||
offsetof(struct prev_params, luma),
|
||||
FIELD_SIZEOF(struct prev_params, luma),
|
||||
sizeof_field(struct prev_params, luma),
|
||||
offsetof(struct omap3isp_prev_update_config, luma),
|
||||
}, /* OMAP3ISP_PREV_INVALAW */ {
|
||||
NULL,
|
||||
@@ -762,55 +762,55 @@ static const struct preview_update update_attrs[] = {
|
||||
preview_config_hmed,
|
||||
preview_enable_hmed,
|
||||
offsetof(struct prev_params, hmed),
|
||||
FIELD_SIZEOF(struct prev_params, hmed),
|
||||
sizeof_field(struct prev_params, hmed),
|
||||
offsetof(struct omap3isp_prev_update_config, hmed),
|
||||
}, /* OMAP3ISP_PREV_CFA */ {
|
||||
preview_config_cfa,
|
||||
NULL,
|
||||
offsetof(struct prev_params, cfa),
|
||||
FIELD_SIZEOF(struct prev_params, cfa),
|
||||
sizeof_field(struct prev_params, cfa),
|
||||
offsetof(struct omap3isp_prev_update_config, cfa),
|
||||
}, /* OMAP3ISP_PREV_CHROMA_SUPP */ {
|
||||
preview_config_chroma_suppression,
|
||||
preview_enable_chroma_suppression,
|
||||
offsetof(struct prev_params, csup),
|
||||
FIELD_SIZEOF(struct prev_params, csup),
|
||||
sizeof_field(struct prev_params, csup),
|
||||
offsetof(struct omap3isp_prev_update_config, csup),
|
||||
}, /* OMAP3ISP_PREV_WB */ {
|
||||
preview_config_whitebalance,
|
||||
NULL,
|
||||
offsetof(struct prev_params, wbal),
|
||||
FIELD_SIZEOF(struct prev_params, wbal),
|
||||
sizeof_field(struct prev_params, wbal),
|
||||
offsetof(struct omap3isp_prev_update_config, wbal),
|
||||
}, /* OMAP3ISP_PREV_BLKADJ */ {
|
||||
preview_config_blkadj,
|
||||
NULL,
|
||||
offsetof(struct prev_params, blkadj),
|
||||
FIELD_SIZEOF(struct prev_params, blkadj),
|
||||
sizeof_field(struct prev_params, blkadj),
|
||||
offsetof(struct omap3isp_prev_update_config, blkadj),
|
||||
}, /* OMAP3ISP_PREV_RGB2RGB */ {
|
||||
preview_config_rgb_blending,
|
||||
NULL,
|
||||
offsetof(struct prev_params, rgb2rgb),
|
||||
FIELD_SIZEOF(struct prev_params, rgb2rgb),
|
||||
sizeof_field(struct prev_params, rgb2rgb),
|
||||
offsetof(struct omap3isp_prev_update_config, rgb2rgb),
|
||||
}, /* OMAP3ISP_PREV_COLOR_CONV */ {
|
||||
preview_config_csc,
|
||||
NULL,
|
||||
offsetof(struct prev_params, csc),
|
||||
FIELD_SIZEOF(struct prev_params, csc),
|
||||
sizeof_field(struct prev_params, csc),
|
||||
offsetof(struct omap3isp_prev_update_config, csc),
|
||||
}, /* OMAP3ISP_PREV_YC_LIMIT */ {
|
||||
preview_config_yc_range,
|
||||
NULL,
|
||||
offsetof(struct prev_params, yclimit),
|
||||
FIELD_SIZEOF(struct prev_params, yclimit),
|
||||
sizeof_field(struct prev_params, yclimit),
|
||||
offsetof(struct omap3isp_prev_update_config, yclimit),
|
||||
}, /* OMAP3ISP_PREV_DEFECT_COR */ {
|
||||
preview_config_dcor,
|
||||
preview_enable_dcor,
|
||||
offsetof(struct prev_params, dcor),
|
||||
FIELD_SIZEOF(struct prev_params, dcor),
|
||||
sizeof_field(struct prev_params, dcor),
|
||||
offsetof(struct omap3isp_prev_update_config, dcor),
|
||||
}, /* Previously OMAP3ISP_PREV_GAMMABYPASS, not used anymore */ {
|
||||
NULL,
|
||||
@@ -828,13 +828,13 @@ static const struct preview_update update_attrs[] = {
|
||||
preview_config_noisefilter,
|
||||
preview_enable_noisefilter,
|
||||
offsetof(struct prev_params, nf),
|
||||
FIELD_SIZEOF(struct prev_params, nf),
|
||||
sizeof_field(struct prev_params, nf),
|
||||
offsetof(struct omap3isp_prev_update_config, nf),
|
||||
}, /* OMAP3ISP_PREV_GAMMA */ {
|
||||
preview_config_gammacorrn,
|
||||
preview_enable_gammacorrn,
|
||||
offsetof(struct prev_params, gamma),
|
||||
FIELD_SIZEOF(struct prev_params, gamma),
|
||||
sizeof_field(struct prev_params, gamma),
|
||||
offsetof(struct omap3isp_prev_update_config, gamma),
|
||||
}, /* OMAP3ISP_PREV_CONTRAST */ {
|
||||
preview_config_contrast,
|
||||
|
||||
@@ -2652,7 +2652,7 @@ struct v4l2_ioctl_info {
|
||||
/* Zero struct from after the field to the end */
|
||||
#define INFO_FL_CLEAR(v4l2_struct, field) \
|
||||
((offsetof(struct v4l2_struct, field) + \
|
||||
FIELD_SIZEOF(struct v4l2_struct, field)) << 16)
|
||||
sizeof_field(struct v4l2_struct, field)) << 16)
|
||||
#define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
|
||||
|
||||
#define DEFINE_V4L_STUB_FUNC(_vidioc) \
|
||||
|
||||
@@ -129,13 +129,13 @@ struct xgbe_stats {
|
||||
|
||||
#define XGMAC_MMC_STAT(_string, _var) \
|
||||
{ _string, \
|
||||
FIELD_SIZEOF(struct xgbe_mmc_stats, _var), \
|
||||
sizeof_field(struct xgbe_mmc_stats, _var), \
|
||||
offsetof(struct xgbe_prv_data, mmc_stats._var), \
|
||||
}
|
||||
|
||||
#define XGMAC_EXT_STAT(_string, _var) \
|
||||
{ _string, \
|
||||
FIELD_SIZEOF(struct xgbe_ext_stats, _var), \
|
||||
sizeof_field(struct xgbe_ext_stats, _var), \
|
||||
offsetof(struct xgbe_prv_data, ext_stats._var), \
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user