mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Colin Plumb <colin@nyx.net>
To: linux-kernel@vger.rutgers.edu
Subject: Re: Modified floppies can crash Linux (fwd)
Date: Tue, 24 Mar 1998 11:43:28 -0700 (MST)	[thread overview]
Message-ID: <199803241843.LAA25640@nyx10.nyx.net> (raw)

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

                 reply	other threads:[~1998-03-24 18:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199803241843.LAA25640@nyx10.nyx.net \
    --to=colin@nyx.net \
    --cc=linux-kernel@vger.rutgers.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®