boot time variable

Tobin C. Harding me at tobin.cc
Mon Oct 9 19:17:09 EDT 2017


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.



More information about the Kernelnewbies mailing list