예제 #1
0
void klist_init_klist(klist *self, klist *init_list) {
    struct klist_iter list_iter;
    kiter *iter = (kiter *)&list_iter;
    void *data;

    klist_init(self);

    klist_iter_init(&list_iter, init_list);
    while (kiter_next(iter, &data))
        klist_append(self, data);
}
예제 #2
0
파일: core.c 프로젝트: kzlin129/tt-gpl
/**
 *	device_for_each_child - device child iterator.
 *	@dev:	parent struct device.
 *	@data:	data for the callback.
 *	@fn:	function to be called for each device.
 *
 *	Iterate over @dev's child devices, and call @fn for each,
 *	passing it @data.
 *
 *	We check the return of @fn each time. If it returns anything
 *	other than 0, we break out and return that value.
 */
int device_for_each_child(struct device * parent, void * data,
		     int (*fn)(struct device *, void *))
{
	struct klist_iter i;
	struct device * child;
	int error = 0;

	klist_iter_init(&parent->klist_children, &i);
	while ((child = next_device(&i)) && !error)
		error = fn(child, data);
	klist_iter_exit(&i);
	return error;
}
예제 #3
0
int klist_get(klist *self, int pos, void **el) {
    struct klist_iter list_iter;
    kiter *iter = (kiter *)&list_iter;

    klist_iter_init(&list_iter, self);
    for (; pos >= 0; pos --) {
        if (kiter_next(iter, el)) {
            KTOOLS_ERROR_SET("the list is too short");
            return -1;
        }
    }
    return 0;
}
예제 #4
0
int suspend_devices_rooted(struct device *root, pm_message_t state)
{
       struct klist_iter i;
       struct device *child;
       int error = 0;
       if (!root->p)
	return 0;

       klist_iter_init(&root->p->klist_children, &i);
       while ((child = next_device(&i)) && !error)
               error = suspend_devices_rooted(child, state);
       klist_iter_exit(&i);

       if(error)
               return error;
       return suspend_device(root, state);
}
예제 #5
0
void test_klist_iterator_remove() {
    char * item_ptr;
    struct klist_iter list_iter;
    kiter *iter = (kiter *)&list_iter;
    klist_iter_init(&list_iter, l1);

    kiter_next(iter, NULL); //go to first element.
    kiter_next(iter, NULL); //go to second.

    kiter_remove(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item2);
    kiter_get(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item3);
    klist_get(l1, 0, (void **) &item_ptr);
    TASSERT(item_ptr == item1);
    klist_get(l1, 1, (void **) &item_ptr);
    TASSERT(item_ptr == item3);
}
예제 #6
0
파일: gsc.c 프로젝트: kizukukoto/WDN900_GPL
void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
			void (*choose_irq)(struct parisc_device *, void *))
{
	struct device *dev;
	struct klist_iter i;

	klist_iter_init(&parent->dev.klist_children, &i);
	while ((dev = next_device(&i))) {
		struct parisc_device *padev = to_parisc_device(dev);

		/* work-around for 715/64 and others which have parent 
		   at path [5] and children at path [5/0/x] */
		if (padev->id.hw_type == HPHW_FAULTY)
			return gsc_fixup_irqs(padev, ctrl, choose_irq);
		choose_irq(padev, ctrl);
	}
	klist_iter_exit(&i);
}
예제 #7
0
void test_klist_iterator() {
    int i=0;
    int d1 = 1;
    int d2 = 2;
    int *d;
    klist_reset(l1);
    klist_append(l1, &d1);
    klist_append(l1, &d2);

    struct klist_iter iter;
    klist_iter_init(&iter, l1);

    kiter_next(&iter, NULL);
    while (kiter_remove(&iter, &d) == 0) {
        i++;
        TASSERT(*d == i);
    }
    TASSERT(i == 2);
}
예제 #8
0
void test_klist_iterator_iter() {
    char * item_ptr;
    struct klist_iter list_iter;
    kiter *iter = (kiter *)&list_iter;
    klist_iter_init(&list_iter, l1);

    kiter_next(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item1);
    kiter_next(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item2);
    kiter_next(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item3);

    TASSERT(kiter_next(iter, (void **) &item_ptr) != 0);

    kiter_prev(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item3);
    kiter_prev(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item2);
    kiter_prev(iter, (void **) &item_ptr);
    TASSERT(item_ptr == item1);
}