* Re: Modified floppies can crash Linux (fwd)
@ 1998-03-24 18:43 Colin Plumb
0 siblings, 0 replies; only message in thread
From: Colin Plumb @ 1998-03-24 18:43 UTC (permalink / raw)
To: linux-kernel
Something that might be helpful when fixing this:
A very efficient way to detect loops in a chain is to compare each element
chain[i] with chain[j], where j is the largest power of 2 less than i.
E.g.
void
traverse_linked_list(struct linked_list *p)
{
struct linked_list *bookmark = NULL;
unsigned counter = 0;
while (p && p != bookmark) {
process_node(p);
counter++;
if (!(counter & (counter-1)) /* Is counter a power of 2? */
bookmark = p;
p = p->next;
}
if (p) {
/* We have processed part of the chain twice, but
* at least we can escape the loop.
*/
printk("Bad chain, aborting traversal.");
}
}
Hacking this into kernel code is left as an exercise for the reader...
--
-Colin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1998-03-24 18:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-24 18:43 Modified floppies can crash Linux (fwd) Colin Plumb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®