[Bridge] [PATCH net-next 01/12] vxlan: Add a function to init switchdev_notifier_vxlan_fdb_info

Petr Machata petrm at mellanox.com
Thu Dec 6 11:42:44 UTC 2018


David Miller <davem at davemloft.net> writes:

> From: Ido Schimmel <idosch at mellanox.com>
> Date: Wed, 5 Dec 2018 15:50:23 +0000
>
>> +static struct switchdev_notifier_vxlan_fdb_info
>> +vxlan_fdb_switchdev_notifier_info(const struct vxlan_dev *vxlan,
>> +				  const struct vxlan_fdb *fdb,
>> +				  const struct vxlan_rdst *rd)
>> +{
>> +	struct switchdev_notifier_vxlan_fdb_info fdb_info = {
>> +		.info.dev = vxlan->dev,
>> +		.remote_ip = rd->remote_ip,
>> +		.remote_port = rd->remote_port,
>> +		.remote_vni = rd->remote_vni,
>> +		.remote_ifindex = rd->remote_ifindex,
>> +		.vni = fdb->vni,
>> +		.offloaded = rd->offloaded,
>> +		.added_by_user = fdb->flags & NTF_VXLAN_ADDED_BY_USER,
>> +	};
>> +
>> +	memcpy(fdb_info.eth_addr, fdb->eth_addr, ETH_ALEN);
>> +	return fdb_info;
>> +}
>
> Never return a structure by value from a function.  Do you have any idea
> how the compiler implement this?
>
> In the one call site in vxlan.c after this patch is applied, _two_
> switchdev_notifier_cxlan_fdb_info objects are allocated on the stack.
>
> vxlan_fdb_swtich_dev_notifier_info() fills in the first one, and
> then the caller copies that into the second one.
>
> A huge waste.
>
> Please just pass "&info" as an argument.

OK


More information about the Bridge mailing list