aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/uwb/rsv.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/uwb/rsv.c')
-rw-r--r--drivers/uwb/rsv.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/drivers/uwb/rsv.c b/drivers/uwb/rsv.c
index e4facae46e0d..bcc41a4a6606 100644
--- a/drivers/uwb/rsv.c
+++ b/drivers/uwb/rsv.c
@@ -82,6 +82,23 @@ static void uwb_rsv_dump(struct uwb_rsv *rsv)
82 dev_dbg(dev, "rsv %s -> %s: %s\n", owner, target, uwb_rsv_state_str(rsv->state)); 82 dev_dbg(dev, "rsv %s -> %s: %s\n", owner, target, uwb_rsv_state_str(rsv->state));
83} 83}
84 84
85static void uwb_rsv_release(struct kref *kref)
86{
87 struct uwb_rsv *rsv = container_of(kref, struct uwb_rsv, kref);
88
89 kfree(rsv);
90}
91
92static void uwb_rsv_get(struct uwb_rsv *rsv)
93{
94 kref_get(&rsv->kref);
95}
96
97static void uwb_rsv_put(struct uwb_rsv *rsv)
98{
99 kref_put(&rsv->kref, uwb_rsv_release);
100}
101
85/* 102/*
86 * Get a free stream index for a reservation. 103 * Get a free stream index for a reservation.
87 * 104 *
@@ -325,6 +342,7 @@ static struct uwb_rsv *uwb_rsv_alloc(struct uwb_rc *rc)
325 342
326 INIT_LIST_HEAD(&rsv->rc_node); 343 INIT_LIST_HEAD(&rsv->rc_node);
327 INIT_LIST_HEAD(&rsv->pal_node); 344 INIT_LIST_HEAD(&rsv->pal_node);
345 kref_init(&rsv->kref);
328 init_timer(&rsv->timer); 346 init_timer(&rsv->timer);
329 rsv->timer.function = uwb_rsv_timer; 347 rsv->timer.function = uwb_rsv_timer;
330 rsv->timer.data = (unsigned long)rsv; 348 rsv->timer.data = (unsigned long)rsv;
@@ -334,14 +352,6 @@ static struct uwb_rsv *uwb_rsv_alloc(struct uwb_rc *rc)
334 return rsv; 352 return rsv;
335} 353}
336 354
337static void uwb_rsv_free(struct uwb_rsv *rsv)
338{
339 uwb_dev_put(rsv->owner);
340 if (rsv->target.type == UWB_RSV_TARGET_DEV)
341 uwb_dev_put(rsv->target.dev);
342 kfree(rsv);
343}
344
345/** 355/**
346 * uwb_rsv_create - allocate and initialize a UWB reservation structure 356 * uwb_rsv_create - allocate and initialize a UWB reservation structure
347 * @rc: the radio controller 357 * @rc: the radio controller
@@ -375,23 +385,23 @@ void uwb_rsv_remove(struct uwb_rsv *rsv)
375 if (rsv->state != UWB_RSV_STATE_NONE) 385 if (rsv->state != UWB_RSV_STATE_NONE)
376 uwb_rsv_set_state(rsv, UWB_RSV_STATE_NONE); 386 uwb_rsv_set_state(rsv, UWB_RSV_STATE_NONE);
377 del_timer_sync(&rsv->timer); 387 del_timer_sync(&rsv->timer);
378 list_del(&rsv->rc_node); 388 uwb_dev_put(rsv->owner);
379 uwb_rsv_free(rsv); 389 if (rsv->target.type == UWB_RSV_TARGET_DEV)
390 uwb_dev_put(rsv->target.dev);
391
392 list_del_init(&rsv->rc_node);
393 uwb_rsv_put(rsv);
380} 394}
381 395
382/** 396/**
383 * uwb_rsv_destroy - free a UWB reservation structure 397 * uwb_rsv_destroy - free a UWB reservation structure
384 * @rsv: the reservation to free 398 * @rsv: the reservation to free
385 * 399 *
386 * The reservation will be terminated if it is pending or established. 400 * The reservation must already be terminated.
387 */ 401 */
388void uwb_rsv_destroy(struct uwb_rsv *rsv) 402void uwb_rsv_destroy(struct uwb_rsv *rsv)
389{ 403{
390 struct uwb_rc *rc = rsv->rc; 404 uwb_rsv_put(rsv);
391
392 mutex_lock(&rc->rsvs_mutex);
393 uwb_rsv_remove(rsv);
394 mutex_unlock(&rc->rsvs_mutex);
395} 405}
396EXPORT_SYMBOL_GPL(uwb_rsv_destroy); 406EXPORT_SYMBOL_GPL(uwb_rsv_destroy);
397 407
@@ -423,6 +433,7 @@ int uwb_rsv_establish(struct uwb_rsv *rsv)
423 goto out; 433 goto out;
424 } 434 }
425 435
436 uwb_rsv_get(rsv);
426 list_add_tail(&rsv->rc_node, &rc->reservations); 437 list_add_tail(&rsv->rc_node, &rc->reservations);
427 rsv->owner = &rc->uwb_dev; 438 rsv->owner = &rc->uwb_dev;
428 uwb_dev_get(rsv->owner); 439 uwb_dev_get(rsv->owner);
@@ -478,9 +489,14 @@ EXPORT_SYMBOL_GPL(uwb_rsv_terminate);
478 * 489 *
479 * Reservation requests from peers are denied unless a PAL accepts it 490 * Reservation requests from peers are denied unless a PAL accepts it
480 * by calling this function. 491 * by calling this function.
492 *
493 * The PAL call uwb_rsv_destroy() for all accepted reservations before
494 * calling uwb_pal_unregister().
481 */ 495 */
482void uwb_rsv_accept(struct uwb_rsv *rsv, uwb_rsv_cb_f cb, void *pal_priv) 496void uwb_rsv_accept(struct uwb_rsv *rsv, uwb_rsv_cb_f cb, void *pal_priv)
483{ 497{
498 uwb_rsv_get(rsv);
499
484 rsv->callback = cb; 500 rsv->callback = cb;
485 rsv->pal_priv = pal_priv; 501 rsv->pal_priv = pal_priv;
486 rsv->state = UWB_RSV_STATE_T_ACCEPTED; 502 rsv->state = UWB_RSV_STATE_T_ACCEPTED;