Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
(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:
klist_iter_init(&theDriverList);
while((node=klist_next(&iterator))!=NULL){
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;
}
}
klist_iter_exit(&iterator);
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.
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.
A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it. subscribe
Open Source Security Myths Dispelled Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization subscribe
InformationWeek InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology. subscribe