Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 704509b8 authored by Sven Eckelmann's avatar Sven Eckelmann
Browse files

batman-adv: Calculate sizeof using variable insead of types



Documentation/CodingStyle recommends to use the form

	p = kmalloc(sizeof(*p), ...);

to calculate the size of a struct and not the version where the struct
name is spelled out to prevent bugs when the type of p changes. This
also seems appropriate for manipulation of buffers when they are
directly associated with p.

Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
parent 958ca598
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ static void new_aggregated_packet(const unsigned char *packet_buff,
		}
	}

	forw_packet_aggr = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
	forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC);
	if (!forw_packet_aggr) {
		if (!own_packet)
			atomic_inc(&bat_priv->batman_queue_left);
+1 −1
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ static int debug_log_setup(struct bat_priv *bat_priv)
	if (!bat_priv->debug_dir)
		goto err;

	bat_priv->debug_log = kzalloc(sizeof(struct debug_log), GFP_ATOMIC);
	bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
	if (!bat_priv->debug_log)
		goto err;

+6 −6
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ static void gw_node_add(struct bat_priv *bat_priv,
	struct gw_node *gw_node;
	int down, up;

	gw_node = kzalloc(sizeof(struct gw_node), GFP_ATOMIC);
	gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC);
	if (!gw_node)
		return;

@@ -508,7 +508,7 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb)
	/* check for ip header */
	switch (ntohs(ethhdr->h_proto)) {
	case ETH_P_IP:
		if (!pskb_may_pull(skb, header_len + sizeof(struct iphdr)))
		if (!pskb_may_pull(skb, header_len + sizeof(*iphdr)))
			return 0;
		iphdr = (struct iphdr *)(skb->data + header_len);
		header_len += iphdr->ihl * 4;
@@ -519,10 +519,10 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb)

		break;
	case ETH_P_IPV6:
		if (!pskb_may_pull(skb, header_len + sizeof(struct ipv6hdr)))
		if (!pskb_may_pull(skb, header_len + sizeof(*ipv6hdr)))
			return 0;
		ipv6hdr = (struct ipv6hdr *)(skb->data + header_len);
		header_len += sizeof(struct ipv6hdr);
		header_len += sizeof(*ipv6hdr);

		/* check for udp header */
		if (ipv6hdr->nexthdr != IPPROTO_UDP)
@@ -533,10 +533,10 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb)
		return 0;
	}

	if (!pskb_may_pull(skb, header_len + sizeof(struct udphdr)))
	if (!pskb_may_pull(skb, header_len + sizeof(*udphdr)))
		return 0;
	udphdr = (struct udphdr *)(skb->data + header_len);
	header_len += sizeof(struct udphdr);
	header_len += sizeof(*udphdr);

	/* check for bootp port */
	if ((ntohs(ethhdr->h_proto) == ETH_P_IP) &&
+1 −1
Original line number Diff line number Diff line
@@ -459,7 +459,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)

	dev_hold(net_dev);

	hard_iface = kmalloc(sizeof(struct hard_iface), GFP_ATOMIC);
	hard_iface = kmalloc(sizeof(*hard_iface), GFP_ATOMIC);
	if (!hard_iface) {
		pr_err("Can't add interface (%s): out of memory\n",
		       net_dev->name);
+4 −3
Original line number Diff line number Diff line
@@ -46,15 +46,16 @@ struct hashtable_t *hash_new(int size)
{
	struct hashtable_t *hash;

	hash = kmalloc(sizeof(struct hashtable_t), GFP_ATOMIC);
	hash = kmalloc(sizeof(*hash), GFP_ATOMIC);
	if (!hash)
		return NULL;

	hash->table = kmalloc(sizeof(struct element_t *) * size, GFP_ATOMIC);
	hash->table = kmalloc(sizeof(*hash->table) * size, GFP_ATOMIC);
	if (!hash->table)
		goto free_hash;

	hash->list_locks = kmalloc(sizeof(spinlock_t) * size, GFP_ATOMIC);
	hash->list_locks = kmalloc(sizeof(*hash->list_locks) * size,
				   GFP_ATOMIC);
	if (!hash->list_locks)
		goto free_table;

Loading