break;
}
if (dev)
- spin_lock(&dev->lock);
+ mutex_lock(&dev->sw_mutex);
else
DPRINTF("device %d not found\n", id);
swconfig_unlock();
static inline void
swconfig_put_dev(struct switch_dev *dev)
{
- spin_unlock(&dev->lock);
+ mutex_unlock(&dev->sw_mutex);
}
static int
int id = cb->args[0];
void *hdr;
- hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq, &switch_fam,
+ hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq, &switch_fam,
NLM_F_MULTI, SWITCH_CMD_NEW_ATTR);
if (IS_ERR(hdr))
return -1;
- NLA_PUT_U32(msg, SWITCH_ATTR_OP_ID, id);
- NLA_PUT_U32(msg, SWITCH_ATTR_OP_TYPE, op->type);
- NLA_PUT_STRING(msg, SWITCH_ATTR_OP_NAME, op->name);
+ if (nla_put_u32(msg, SWITCH_ATTR_OP_ID, id))
+ goto nla_put_failure;
+ if (nla_put_u32(msg, SWITCH_ATTR_OP_TYPE, op->type))
+ goto nla_put_failure;
+ if (nla_put_string(msg, SWITCH_ATTR_OP_NAME, op->name))
+ goto nla_put_failure;
if (op->description)
- NLA_PUT_STRING(msg, SWITCH_ATTR_OP_DESCRIPTION,
- op->description);
+ if (nla_put_string(msg, SWITCH_ATTR_OP_DESCRIPTION,
+ op->description))
+ goto nla_put_failure;
return genlmsg_end(msg, hdr);
nla_put_failure:
if (!p)
goto error;
- NLA_PUT_U32(cb->msg, SWITCH_PORT_ID, port->id);
- if (port->flags & (1 << SWITCH_PORT_FLAG_TAGGED))
- NLA_PUT_FLAG(cb->msg, SWITCH_PORT_FLAG_TAGGED);
+ if (nla_put_u32(cb->msg, SWITCH_PORT_ID, port->id))
+ goto nla_put_failure;
+ if (port->flags & (1 << SWITCH_PORT_FLAG_TAGGED)) {
+ if (nla_put_flag(cb->msg, SWITCH_PORT_FLAG_TAGGED))
+ goto nla_put_failure;
+ }
nla_nest_end(cb->msg, p);
return 0;
if (!msg)
goto error;
- hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq, &switch_fam,
+ hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq, &switch_fam,
0, cmd);
if (IS_ERR(hdr))
goto nla_put_failure;
switch(attr->type) {
case SWITCH_TYPE_INT:
- NLA_PUT_U32(msg, SWITCH_ATTR_OP_VALUE_INT, val.value.i);
+ if (nla_put_u32(msg, SWITCH_ATTR_OP_VALUE_INT, val.value.i))
+ goto nla_put_failure;
break;
case SWITCH_TYPE_STRING:
- NLA_PUT_STRING(msg, SWITCH_ATTR_OP_VALUE_STR, val.value.s);
+ if (nla_put_string(msg, SWITCH_ATTR_OP_VALUE_STR, val.value.s))
+ goto nla_put_failure;
break;
case SWITCH_TYPE_PORTS:
err = swconfig_send_ports(&msg, info,
if (IS_ERR(hdr))
return -1;
- NLA_PUT_U32(msg, SWITCH_ATTR_ID, dev->id);
- NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname);
- NLA_PUT_STRING(msg, SWITCH_ATTR_ALIAS, dev->alias);
- NLA_PUT_STRING(msg, SWITCH_ATTR_NAME, dev->name);
- NLA_PUT_U32(msg, SWITCH_ATTR_VLANS, dev->vlans);
- NLA_PUT_U32(msg, SWITCH_ATTR_PORTS, dev->ports);
- NLA_PUT_U32(msg, SWITCH_ATTR_CPU_PORT, dev->cpu_port);
+ if (nla_put_u32(msg, SWITCH_ATTR_ID, dev->id))
+ goto nla_put_failure;
+ if (nla_put_string(msg, SWITCH_ATTR_DEV_NAME, dev->devname))
+ goto nla_put_failure;
+ if (nla_put_string(msg, SWITCH_ATTR_ALIAS, dev->alias))
+ goto nla_put_failure;
+ if (nla_put_string(msg, SWITCH_ATTR_NAME, dev->name))
+ goto nla_put_failure;
+ if (nla_put_u32(msg, SWITCH_ATTR_VLANS, dev->vlans))
+ goto nla_put_failure;
+ if (nla_put_u32(msg, SWITCH_ATTR_PORTS, dev->ports))
+ goto nla_put_failure;
+ if (nla_put_u32(msg, SWITCH_ATTR_CPU_PORT, dev->cpu_port))
+ goto nla_put_failure;
return genlmsg_end(msg, hdr);
nla_put_failure:
list_for_each_entry(dev, &swdevs, dev_list) {
if (++idx <= start)
continue;
- if (swconfig_send_switch(skb, NETLINK_CB(cb->skb).pid,
+ if (swconfig_send_switch(skb, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, NLM_F_MULTI,
dev) < 0)
break;
return -ENOMEM;
}
swconfig_defaults_init(dev);
- spin_lock_init(&dev->lock);
+ mutex_init(&dev->sw_mutex);
swconfig_lock();
dev->id = ++swdev_id;
{
swconfig_destroy_led_trigger(dev);
kfree(dev->portbuf);
- spin_lock(&dev->lock);
+ mutex_lock(&dev->sw_mutex);
swconfig_lock();
list_del(&dev->dev_list);
swconfig_unlock();
- spin_unlock(&dev->lock);
+ mutex_unlock(&dev->sw_mutex);
}
EXPORT_SYMBOL_GPL(unregister_switch);