Skip to content

Commit 93cce3d

Browse files
G. LiakhovetskiDavid S. Miller
authored andcommitted
[IrDA]: tsap init routine factorisation.
This patch extracts common code from irttp_open_tsap() and irttp_dup() into a new function to 1) avoid code duplication, 2) help avoid forgetting object initialization in the tsap duplication path in the future. Signed-off-by: G. Liakhovetski <gl@dsa-ac.de> Signed-off-by: Samuel Ortiz <samuel@sortiz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 66f5e51 commit 93cce3d

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

‎net/irda/irttp.c‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,20 @@ static int irttp_param_max_sdu_size(void *instance, irda_param_t *param,
368368
/************************** LMP CALLBACKS **************************/
369369
/* Everything is happily mixed up. Waiting for next clean up - Jean II */
370370

371+
/*
372+
* Initialization, that has to be done on new tsap
373+
* instance allocation and on duplication
374+
*/
375+
static void irttp_init_tsap(struct tsap_cb *tsap)
376+
{
377+
spin_lock_init(&tsap->lock);
378+
init_timer(&tsap->todo_timer);
379+
380+
skb_queue_head_init(&tsap->rx_queue);
381+
skb_queue_head_init(&tsap->tx_queue);
382+
skb_queue_head_init(&tsap->rx_fragments);
383+
}
384+
371385
/*
372386
* Function irttp_open_tsap (stsap, notify)
373387
*
@@ -395,10 +409,11 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
395409
IRDA_DEBUG(0, "%s(), unable to kmalloc!\n", __FUNCTION__);
396410
return NULL;
397411
}
398-
spin_lock_init(&self->lock);
412+
413+
/* Initialize internal objects */
414+
irttp_init_tsap(self);
399415

400416
/* Initialise todo timer */
401-
init_timer(&self->todo_timer);
402417
self->todo_timer.data = (unsigned long) self;
403418
self->todo_timer.function = &irttp_todo_expired;
404419

@@ -418,9 +433,6 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
418433
self->magic = TTP_TSAP_MAGIC;
419434
self->connected = FALSE;
420435

421-
skb_queue_head_init(&self->rx_queue);
422-
skb_queue_head_init(&self->tx_queue);
423-
skb_queue_head_init(&self->rx_fragments);
424436
/*
425437
* Create LSAP at IrLMP layer
426438
*/
@@ -1455,12 +1467,9 @@ struct tsap_cb *irttp_dup(struct tsap_cb *orig, void *instance)
14551467

14561468
/* Not everything should be copied */
14571469
new->notify.instance = instance;
1458-
spin_lock_init(&new->lock);
1459-
init_timer(&new->todo_timer);
14601470

1461-
skb_queue_head_init(&new->rx_queue);
1462-
skb_queue_head_init(&new->tx_queue);
1463-
skb_queue_head_init(&new->rx_fragments);
1471+
/* Initialize internal objects */
1472+
irttp_init_tsap(new);
14641473

14651474
/* This is locked */
14661475
hashbin_insert(irttp->tsaps, (irda_queue_t *) new, (long) new, NULL);

0 commit comments

Comments
 (0)