kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: me@tobin.cc (Tobin C. Harding)
To: kernelnewbies@lists.kernelnewbies.org
Subject: boot time variable
Date: Tue, 10 Oct 2017 10:17:09 +1100	[thread overview]
Message-ID: <20171009231709.GB20083@eros> (raw)

Hi,

I would like to create a boot time variable i.e a variable that is set once at boot time. Variable
does not need to be globally accessible. (actually I am using two variables).

Could any one point me to examples of this already intree please?

I have tried the following but it has a race condition on the zero check and assignment of randval/oddval.

/* Maps a pointer to a unique identifier. */
static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
{
	long hashval;
	static long randval = 0;
	static long oddval = 0;

	if (oddval == 0 && randval == 0) {
		randval = get_random_long();
		oddval = get_random_odd_long();
	}

	hashval = ptr_obfuscate((unsigned long)ptr, randval, oddval);
	spec.base = 16;

	return number(buf, end, hashval, spec);
}

And the compiler doesn't like

        static long randval = get_random_long();
	static long oddval = get_random_odd_long();


I thought of wrapping oddval/randval in a struct and protecting it with a lock but I don't know
how/where to initialize the lock in a race free manner?

Any tips or pointers please?

thanks,
Tobin.

             reply	other threads:[~2017-10-09 23:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09 23:17 Tobin C. Harding [this message]
2017-10-10  7:08 ` boot time variable Greg KH
2017-10-10 10:33   ` Tobin C. Harding
2017-10-10  7:50 ` valdis.kletnieks at vt.edu

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=20171009231709.GB20083@eros \
    --to=me@tobin.cc \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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;
as well as URLs for NNTP newsgroup(s).