fsm_instance * init_fsm(char *name, const char **state_names, const char **event_names, int nr_states, int nr_events, const fsm_node *tmpl, int tmpl_len, int order) { int i; fsm_instance *this; fsm_function_t *m; fsm *f; this = (fsm_instance *)kmalloc(sizeof(fsm_instance), order); if (this == NULL) { printk(KERN_WARNING "fsm(%s): init_fsm: Couldn't alloc instance\n", name); return NULL; } memset(this, 0, sizeof(fsm_instance)); strlcpy(this->name, name, sizeof(this->name)); f = (fsm *)kmalloc(sizeof(fsm), order); if (f == NULL) { printk(KERN_WARNING "fsm(%s): init_fsm: Couldn't alloc fsm\n", name); kfree_fsm(this); return NULL; } memset(f, 0, sizeof(fsm)); f->nr_events = nr_events; f->nr_states = nr_states; f->event_names = event_names; f->state_names = state_names; this->f = f; m = (fsm_function_t *)kmalloc( sizeof(fsm_function_t) * nr_states * nr_events, order); if (m == NULL) { printk(KERN_WARNING "fsm(%s): init_fsm: Couldn't alloc jumptable\n", name); kfree_fsm(this); return NULL; } memset(m, 0, sizeof(fsm_function_t) * f->nr_states * f->nr_events); f->jumpmatrix = m; for (i = 0; i < tmpl_len; i++) { if ((tmpl[i].cond_state >= nr_states) || (tmpl[i].cond_event >= nr_events) ) { printk(KERN_ERR "fsm(%s): init_fsm: Bad template l=%d st(%ld/%ld) ev(%ld/%ld)\n", name, i, (long)tmpl[i].cond_state, (long)f->nr_states, (long)tmpl[i].cond_event, (long)f->nr_events); kfree_fsm(this); return NULL; } else m[nr_states * tmpl[i].cond_event + tmpl[i].cond_state] = tmpl[i].function; } return this; }
/** * Remove a specific channel in the channel list. * * ch Pointer to channel struct to be released. */ static void channel_remove(struct channel *ch) { struct channel **c = &channels; char chid[CTCM_ID_SIZE+1]; int ok = 0; if (ch == NULL) return; else strncpy(chid, ch->id, CTCM_ID_SIZE); channel_free(ch); while (*c) { if (*c == ch) { *c = ch->next; fsm_deltimer(&ch->timer); if (IS_MPC(ch)) fsm_deltimer(&ch->sweep_timer); kfree_fsm(ch->fsm); clear_normalized_cda(&ch->ccw[4]); if (ch->trans_skb != NULL) { clear_normalized_cda(&ch->ccw[1]); dev_kfree_skb_any(ch->trans_skb); } if (IS_MPC(ch)) { tasklet_kill(&ch->ch_tasklet); tasklet_kill(&ch->ch_disc_tasklet); kfree(ch->discontact_th); } kfree(ch->ccw); kfree(ch->irb); kfree(ch); ok = 1; break; } c = &((*c)->next); } CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL, chid, ok ? "OK" : "failed"); }
fsm_instance * init_fsm(char *name, const char **state_names, const char **event_names, int nr_states, int nr_events, const fsm_node *tmpl, int tmpl_len, gfp_t order) { int i; fsm_instance *this; fsm_function_t *m; fsm *f; this = kzalloc(sizeof(fsm_instance), order); if (this == NULL) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_WARNING "fsm(%s): init_fsm: Couldn't alloc instance\n", name); #else ; #endif return NULL; } strlcpy(this->name, name, sizeof(this->name)); init_waitqueue_head(&this->wait_q); f = kzalloc(sizeof(fsm), order); if (f == NULL) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_WARNING "fsm(%s): init_fsm: Couldn't alloc fsm\n", name); #else ; #endif kfree_fsm(this); return NULL; } f->nr_events = nr_events; f->nr_states = nr_states; f->event_names = event_names; f->state_names = state_names; this->f = f; m = kcalloc(nr_states*nr_events, sizeof(fsm_function_t), order); if (m == NULL) { #ifdef CONFIG_DEBUG_PRINTK printk(KERN_WARNING "fsm(%s): init_fsm: Couldn't alloc jumptable\n", name); #else ; #endif kfree_fsm(this); return NULL; } f->jumpmatrix = m; for (i = 0; i < tmpl_len; i++) { if ((tmpl[i].cond_state >= nr_states) || (tmpl[i].cond_event >= nr_events) ) { printk(KERN_ERR "fsm(%s): init_fsm: Bad template l=%d st(%ld/%ld) ev(%ld/%ld)\n", name, i, (long)tmpl[i].cond_state, (long)f->nr_states, (long)tmpl[i].cond_event, (long)f->nr_events); kfree_fsm(this); return NULL; } else m[nr_states * tmpl[i].cond_event + tmpl[i].cond_state] = tmpl[i].function; } return this; }