bool config_parser_handle_int(struct list_head *head, void *data) { struct ptoken *t, *first; int *target = data; char *endp; long long tmp; first = list_entry(head->next, struct ptoken, list); t = config_token_after_equal(head); if(!t) { logg(LOGF_NOTICE, "Parsing config file %s@%zu: Option \"%s\" wants a value assigned, will ignore\n", first->ctx->in_filename, first->ctx->line_num, first->d.t); return true; } tmp = strtoll(t->d.t, &endp, 0); if(t->d.t == endp) { logg(LOGF_NOTICE, "Parsing config file %s@%zu: Option \"%s\" wants a numerical value, not \"%s\", will ignore\n", first->ctx->in_filename, first->ctx->line_num, first->d.t, endp); return true; } if(*endp) logg(LOGF_INFO, "Parsing config file %s@%zu: Junk (\"%s\") after numerical value %lli, hopefully OK\n", first->ctx->in_filename, first->ctx->line_num, endp, tmp); if(tmp < INT_MIN || tmp > INT_MAX) { logg(LOGF_NOTICE, "Parsing config file %s@%zu: Value \"%s\" is to large for option \"%s\", will ignore\n", first->ctx->in_filename, first->ctx->line_num, t->d.t, first->d.t); return true; } *target = (int)tmp; if(!list_is_last(&t->list, head)) logg(LOGF_INFO, "Parsing config file %s@%zu: ignored tokens after \"%s\", hopefully OK\n", first->ctx->in_filename, first->ctx->line_num, t->d.t); return true; }
/** * Finds the first node in an avl-tree with a key greater or equal * than the specified key * @param tree pointer to avl-tree * @param key pointer to specified key * @return pointer to avl-node, NULL if no node with * key greater or equal specified key exists. */ struct avl_node * avl_find_greaterequal(const struct avl_tree *tree, const void *key) { struct avl_node *node, *next; int diff; if (tree->root == NULL) return NULL; node = _avl_find_rec(tree->root, key, tree->comp, &diff); /* go right as long as key>node.key */ while (diff > 0) { if (list_is_last(&tree->list_head, &node->list)) { return NULL; } node = (struct avl_node *)node->list.next; diff = (*tree->comp) (key, node->key); } /* go left as long as key<=next_node.key */ next = node; while (diff <= 0) { node = next; if (list_is_first(&tree->list_head, &node->list)) { break; } next = (struct avl_node *)node->list.prev; diff = (*tree->comp) (key, next->key); } return node; }
bool config_parser_handle_string(struct list_head *head, void *data) { struct ptoken *t, *first; char **target = data; char *tmp; first = list_entry(head->next, struct ptoken, list); t = config_token_after_equal(head); if(!t) { logg(LOGF_NOTICE, "Parsing config file %s@%zu: Option \"%s\" wants a value assigned, will ignore\n", first->ctx->in_filename, first->ctx->line_num, first->d.t); return true; } tmp = malloc(t->d.len + 1); if(!tmp) { logg(LOGF_NOTICE, "Parsing config file %s@%zu: Couldn't allocate memory for option \"%s\", will ignore\n", first->ctx->in_filename, first->ctx->line_num, first->d.t); return true; } memcpy(tmp, t->d.t, t->d.len); tmp[t->d.len] = '\0'; *target = tmp; if(!list_is_last(&t->list, head)) logg(LOGF_INFO, "Parsing config file %s@%zu: ignored tokens after \"%s\", hopefully OK\n", first->ctx->in_filename, first->ctx->line_num, t->d.t); return true; }
/* remove node form list */ void list_remove_data(List * L, void * data) { List *p, *tmpcell; p = list_find_prev( L , data ); if ( !list_is_last( p ) ) { /* data is found; delete it */ tmpcell = p->next; p->next = tmpcell->next; /* Bypass deleted cell */ free( tmpcell ); } else { if ( L->next == NULL ) { L->data = NULL; return; } else { /*swap 1st and 2st*/ p = list_get_first_entry( L ); tmpcell = p->next; p->data = tmpcell->data; if (!p->next->next) p->next = NULL; else p->next = tmpcell->next; free( tmpcell ); } } }
//ÊͷŵÄʱºòºÏ²¢,Ïà¶ÔÓÚbinder¶øÑÔ£¬ÕâÀïµÄ»º³åÇø»áÀ©Õ¹£¬ËùÒÔÄÚ´æ²»ÊÇÈ«²¿Á¬Ðø£¬¶øÊÇÒ»¶Î¶ÎÁ¬Ðø void fms_mem_free(fms_mem_pool *mem_pool, void *data) { fms_mem_block *block = (fms_mem_block *)((fms_u8 *)data - sizeof(fms_mem_block));//×îºÃÓúêÀ´ÊµÏÖ rb_erase(&block->rb_node, &mem_pool->allocated_blocks); if (!list_is_last(&block->entry, &mem_pool->blocks)) {//Èç¹û²»ÊÇ×îºóÒ»¸ö£¬ÏòºóºÏ²¢ fms_mem_block *next = list_entry(&block->entry.next, fms_mem_block, entry); if (next->free && next->id == block->id) { //IDÏàͬ²ÅÊÇͬһ¶ÎÁ¬ÐøÄڴ棬²Å¿ÉÄܺϲ¢ rb_erase(&next->rb_node, &mem_pool->free_blocks); list_del(&next->entry); block->data_size += sizeof(fms_mem_block) + next->data_size;//Êý¾ÝÇøÀ©Õ¹£¬ºÏ²¢ } } if (!list_is_first(&block->entry, &mem_pool->blocks)) {//Èç¹û²»ÊÇ×îÇ°ÃæµÄÒ»¸ö£¬ÏòÇ°ºÏ²¢ fms_mem_block *prev = list_entry(&block->entry.prev, fms_mem_block, entry); if (prev->free && prev->id == block->id) { rb_erase(&prev->rb_node, &mem_pool->free_blocks); prev->data_size += sizeof(fms_mem_block) + block->data_size; list_del(&block->entry); block = prev; } } block->free = FMS_TRUE; mem_block_insert_free(mem_pool, block); }
/* Looks up a heavy-hitter flow in a chaining list of table T. */ static struct hh_flow_state *seek_list(const u32 hash, struct list_head *head, struct hhf_sched_data *q) { struct hh_flow_state *flow, *next; u32 now = hhf_time_stamp(); if (list_empty(head)) return NULL; list_for_each_entry_safe(flow, next, head, flowchain) { u32 prev = flow->hit_timestamp + q->hhf_evict_timeout; if (hhf_time_before(prev, now)) { /* Delete expired heavy-hitters, but preserve one entry * to avoid kzalloc() when next time this slot is hit. */ if (list_is_last(&flow->flowchain, head)) return NULL; list_del(&flow->flowchain); kfree(flow); q->hh_flows_current_cnt--; } else if (flow->hash_id == hash) { return flow; } }
static size_t binder_alloc_buffer_size(struct binder_alloc *alloc, struct binder_buffer *buffer) { if (list_is_last(&buffer->entry, &alloc->buffers)) return (u8 *)alloc->buffer + alloc->buffer_size - (u8 *)buffer->data; return (u8 *)binder_buffer_next(buffer)->data - (u8 *)buffer->data; }
static void configure_next_req(struct tegra_dma_channel *ch, struct tegra_dma_req *hreq) { struct tegra_dma_req *next_req; if (!list_is_last(&hreq->node, &ch->list)) { next_req = list_entry(hreq->node.next, typeof(*next_req), node); tegra_dma_update_hw_partial(ch, next_req); } }
static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos) { struct list_head *list = v; if (list_is_last(list, &smack_rule_list)) { *pos = SEQ_READ_FINISHED; return NULL; } return list->next; }
static int count_list(struct list_head *list) { int count; struct list_head *p; count = 0; p = list; while (!list_is_last(p, list)) { count += 1; p = p->next; } return count; }
/** * Finds the end of linked list from the avl node * @param tree pointer to tree * @param node pointer * @return pointer to last node of the list */ struct avl_node* _avl_find_last(struct avl_tree *tree, struct avl_node* last) { struct avl_node *next; while (!list_is_last(&tree->list_head, &last->list)) { next = list_next_element(last, list); if (!next->follower) { break; } last = next; } return last; }
/* * the number of commands */ int command_number(void) { int i = 0; struct list_head * pos = (&command_list->entry)->next; while(!list_is_last(pos, (&command_list->entry)->next)) { pos = pos->next; i++; } return i; }
void shm_destroy_context(shm_context_t *context) { iterator_t it = iterator_create(context->phys_pages); list_set_first(&it); while( ! list_is_last(&it) ) { void *addr = list_get_current(&it); pmm_mark_page_as_free(addr); list_next(&it); } free(context); }
static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos) { struct list_head *list = v; /* * labels with no associated cipso value wont be printed * in cipso_seq_show */ if (list_is_last(list, &smack_known_list)) { *pos = SEQ_READ_FINISHED; return NULL; } return list->next; }
/** * ccp_del_device - remove a CCP device from the list * * @ccp: ccp_device struct pointer * * Remove this unit from the list of devices. If the next device * up for use is this one, adjust the pointer. If this is the last * device, NULL the pointer. */ void ccp_del_device(struct ccp_device *ccp) { unsigned long flags; write_lock_irqsave(&ccp_unit_lock, flags); if (ccp_rr == ccp) { /* ccp_unit_lock is read/write; any read access * will be suspended while we make changes to the * list and RR pointer. */ if (list_is_last(&ccp_rr->entry, &ccp_units)) ccp_rr = list_first_entry(&ccp_units, struct ccp_device, entry); else ccp_rr = list_next_entry(ccp_rr, entry); }
static void start_head_req(struct tegra_dma_channel *ch) { struct tegra_dma_req *head_req; struct tegra_dma_req *next_req; if (!list_empty(&ch->list)) { head_req = list_entry(ch->list.next, typeof(*head_req), node); tegra_dma_update_hw(ch, head_req); /* Set next request to idle. */ if (!list_is_last(&head_req->node, &ch->list)) { next_req = list_entry(head_req->node.next, typeof(*head_req), node); next_req->status = TEGRA_DMA_REQ_PENDING; } } }
struct uld_ctx *assign_chcr_device(void) { struct uld_ctx *u_ctx = NULL; /* * When multiple devices are present in system select * device in round-robin fashion for crypto operations * Although One session must use the same device to * maintain request-response ordering. */ mutex_lock(&dev_mutex); if (!list_empty(&uld_ctx_list)) { u_ctx = ctx_rr; if (list_is_last(&ctx_rr->entry, &uld_ctx_list)) ctx_rr = list_first_entry(&uld_ctx_list, struct uld_ctx, entry); else
bool config_parser_handle_bool(struct list_head *head, void *data) { static const struct tr_vals { bool val; char txt[6]; } tr_vals[] = { {true, "true"}, {false, "false"}, {true, "yes"}, {false, "no"}, {true, "1"}, {false, "0"}, {true, "t"}, {false, "f"}, {true, "y"}, {false, "n"}, }; struct ptoken *t, *first; bool *target = data, found; unsigned i; first = list_entry(head->next, struct ptoken, list); t = config_token_after_equal(head); if(!t) { logg(LOGF_NOTICE, "Parsing config file %s@%zu: Option \"%s\" wants a value assigned, will ignore\n", first->ctx->in_filename, first->ctx->line_num, first->d.t); return true; } for(i = 0, found = false; i < anum(tr_vals); i++) { if(0 == strcmp(tr_vals[i].txt, t->d.t)) { *target = tr_vals[i].val; found = true; break; } } if(!found) { logg(LOGF_NOTICE, "Parsing config file %s@%zu: I don't understand \"%s\" for a boolean value, will ignore\n", first->ctx->in_filename, first->ctx->line_num, t->d.t); return true; } if(!list_is_last(&t->list, head)) logg(LOGF_INFO, "Parsing config file %s@%zu: ignored tokens after \"%s\", hopefully OK\n", first->ctx->in_filename, first->ctx->line_num, t->d.t); return true; }
void *shm_attach(vmm_context_t *vmm_context, shm_context_t *shm_context, uintptr_t offset) { if(offset >= shm_context->size) return -1; uintptr_t base = 0xB0000000; /* TODO */ uintptr_t start = (base + offset) & PAGE_MASK; iterator_t it = iterator_create(shm_context->phys_pages); list_set_first(&it); int i = 0; while( ! list_is_last(&it) ) { vaddr_t vaddr = start + i * PAGE_SIZE; paddr_t paddr = list_get_current(&it); vmm_map(vmm_context, paddr, vaddr, VMM_PRESENT | VMM_WRITABLE | VMM_USER); i++; } return start; }
static int __klp_disable_patch(struct klp_patch *patch) { struct klp_object *obj; if (WARN_ON(!patch->enabled)) return -EINVAL; if (klp_transition_patch) return -EBUSY; /* enforce stacking: only the last enabled patch can be disabled */ if (!list_is_last(&patch->list, &klp_patches) && list_next_entry(patch, list)->enabled) return -EBUSY; klp_init_transition(patch, KLP_UNPATCHED); klp_for_each_object(patch, obj) if (obj->patched) klp_pre_unpatch_callback(obj); /* * Enforce the order of the func->transition writes in * klp_init_transition() and the TIF_PATCH_PENDING writes in * klp_start_transition(). In the rare case where klp_ftrace_handler() * is called shortly after klp_update_patch_state() switches the task, * this ensures the handler sees that func->transition is set. */ smp_wmb(); klp_start_transition(); klp_try_complete_transition(); patch->enabled = false; return 0; }
static inline int tapdisk_vbd_is_last_image(td_vbd_t *vbd, td_image_t *image) { return list_is_last(&image->next, &vbd->images); }