Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Does klist_iter_exit delete the entry from list??

    (Sorry if this is a double-post -- don't know what happened to the first one.)

    As I read klist.c, calling klist_iter_exit to close an iteration will delete the current entry (if any) from the list.

    Am I reading this correctly? Is this the intended result?

    Psuedo-code example: Assume that you have a list of devices (or something similar) and need to look up the device with ID = x. The code could be something like this:

    struct device *find_device(int ID){
    struct klist_iter iterator;
    struct klist_node *node;
    struct device *dev;

    dev = (node coerced to device *)..
    if(dev.ID==x){ // Found the one you wanted
    klist_iter_exit(&iterator); // This does a KLIST_DEL!!!
    return dev;
    return null;

    So this form of the code would not only "look up" the desired entry, but has the side-effect of removing it from the list??? Is this true?

    I understand that it would be possible to set the 'dev' pointer when we find the desired entry, and then just let the iteration continue until it finishes the list. Then the klist_iter_exit is OK. But if the list is potentially very long, this seems like a waste of processor resource.

    Thanks for any help or suggestions.


  2. #2


    klist operation is correct.

    When an entry is added to the list the ref count is set to 1. The iterator increments the ref count when it arrives at an entry. If the iteration breaks early, the klist_iter_exit function calls klist_del. This will decrement the ref count, but since it is still non-zero will not actually remove it from the list.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts