/* Distribution data is a variable size payload containing signed 16 bit values.  */
static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
/* Distribution data is a variable size payload containing signed 16 bit values.  */
static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
{
	struct netem_sched_data *q = qdisc_priv(sch);
	unsigned long n = nla_len(attr)/sizeof(__s16);
	const __s16 *data = nla_data(attr);
	spinlock_t *root_lock;
	struct disttable *d;
	int i;
	if (n > 65536)
		return -EINVAL;
	d = kmalloc(sizeof(*d) + n*sizeof(d->table[0]), GFP_KERNEL);
	if (!d)
		return -ENOMEM;
	d->size = n;
	for (i = 0; i < n; i++)
		d->table[i] = data[i];
	root_lock = qdisc_root_sleeping_lock(sch);
	spin_lock_bh(root_lock);
	kfree(q->delay_dist);
	q->delay_dist = d;
	spin_unlock_bh(root_lock);
	return 0;
}