/* Return: 0 on success -EINVAL invalid (out of range) protocol number -EBUSY protocol already in use -ENOBUF if proto_register() fails  */
int can_proto_register(struct can_proto *cp)
/* Return: 0 on success -EINVAL invalid (out of range) protocol number -EBUSY protocol already in use -ENOBUF if proto_register() fails  */
int can_proto_register(struct can_proto *cp)
{
	int proto = cp->protocol;
	int err = 0;
	if (proto < 0 || proto >= CAN_NPROTO) {
		printk(KERN_ERR "can: protocol number %d out of range\n",
		       proto);
		return -EINVAL;
	}
	err = proto_register(cp->prot, 0);
	if (err < 0)
		return err;
	spin_lock(&proto_tab_lock);
	if (proto_tab[proto]) {
		printk(KERN_ERR "can: protocol %d already registered\n",
		       proto);
		err = -EBUSY;
	} else {
		proto_tab[proto] = cp;
		if (!cp->ops->ioctl)
			cp->ops->ioctl = can_ioctl;
	}
	spin_unlock(&proto_tab_lock);
	if (err < 0)
		proto_unregister(cp->prot);
	return err;
}