Skip to content

Commit

Permalink
net/802: use struct_size over open coded arithmetic
Browse files Browse the repository at this point in the history
Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kmalloc(). For example:

struct garp_attr {
	struct rb_node			node;
	enum garp_applicant_state	state;
	u8				type;
	u8				dlen;
	unsigned char			data[];
};

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
  • Loading branch information
Minghao Chi (CGEL ZTE) authored and intel-lab-lkp committed Jan 28, 2022
1 parent 72d044e commit 9b64e50
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion net/802/garp.c
Expand Up @@ -184,7 +184,7 @@ static struct garp_attr *garp_attr_create(struct garp_applicant *app,
return attr;
}
}
attr = kmalloc(sizeof(*attr) + len, GFP_ATOMIC);
attr = kmalloc(struct_size(*attr, data, len), GFP_ATOMIC);
if (!attr)
return attr;
attr->state = GARP_APPLICANT_VO;
Expand Down
2 changes: 1 addition & 1 deletion net/802/mrp.c
Expand Up @@ -273,7 +273,7 @@ static struct mrp_attr *mrp_attr_create(struct mrp_applicant *app,
return attr;
}
}
attr = kmalloc(sizeof(*attr) + len, GFP_ATOMIC);
attr = kmalloc(struct_size(*attr, value, len), GFP_ATOMIC);
if (!attr)
return attr;
attr->state = MRP_APPLICANT_VO;
Expand Down

0 comments on commit 9b64e50

Please sign in to comment.