net: devlink: add port type spinlock

Add spinlock to protect port type and type_dev pointer consistency.
Without that, userspace may see inconsistent type and type_dev
combinations.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
v1->v2:
- rebased
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jiri Pirko 2019-03-24 11:14:37 +01:00 committed by David S. Miller
parent 2b239e7090
commit b8f975545c
2 changed files with 17 additions and 4 deletions

View file

@ -16,6 +16,7 @@
#include <linux/gfp.h>
#include <linux/list.h>
#include <linux/netdevice.h>
#include <linux/spinlock.h>
#include <net/net_namespace.h>
#include <uapi/linux/devlink.h>
@ -53,6 +54,9 @@ struct devlink_port {
struct devlink *devlink;
unsigned index;
bool registered;
spinlock_t type_lock; /* Protects type and type_dev
* pointer consistency.
*/
enum devlink_port_type type;
enum devlink_port_type desired_type;
void *type_dev;