/* If the target is a DevAddr (e.g., a WUSB cluster reservation) then the stream is allocated from a pool of per-RC stream indexes, otherwise a unique stream index for the target is selected.  */
static int uwb_rsv_get_stream(struct uwb_rsv *rsv)
/* If the target is a DevAddr (e.g., a WUSB cluster reservation) then the stream is allocated from a pool of per-RC stream indexes, otherwise a unique stream index for the target is selected.  */
static int uwb_rsv_get_stream(struct uwb_rsv *rsv)
{
	struct uwb_rc *rc = rsv->rc;
	struct device *dev = &rc->uwb_dev.dev;
	unsigned long *streams_bm;
	int stream;
	switch (rsv->target.type) {
	case UWB_RSV_TARGET_DEV:
		streams_bm = rsv->target.dev->streams;
		break;
	case UWB_RSV_TARGET_DEVADDR:
		streams_bm = rc->uwb_dev.streams;
		break;
	default:
		return -EINVAL;
	}
	stream = find_first_zero_bit(streams_bm, UWB_NUM_STREAMS);
	if (stream >= UWB_NUM_STREAMS)
		return -EBUSY;
	rsv->stream = stream;
	set_bit(stream, streams_bm);
	dev_dbg(dev, "get stream %d\n", rsv->stream);
	return 0;
}