Subject: Re: another question about bus_space_map
To: der Mouse <mouse@rodents.montreal.qc.ca>
From: Chris G. Demetriou <cgd@CS.cmu.edu>
List: tech-kern
Date: 02/04/1997 14:54:09
> >> Should a probe routine unmap everything and let the attach routine
> >> map it back in?
> > yes.  there should be no permanent allocations or initializations
> > done in the match/probe routine, EVER.
> 
> I've seen this said about four times.  I don't think I've ever seen it
> explained _why_.  I can't see any harm in, for example,
> 
> 	static int table_set_up = 0;
> 	static unsigned int *table;
> 	
> 	static void maybe_set_up_table(void)
> 	{
> 		if (table_set_up) return;
> 		...allocate *table and load it...
> 		table_set_up = 1;
> 	}
> 	
> 	xxx_match() {
> 		maybe_set_up_table();
> 		...check something on the bus using table[]...
> 	}
> 
> Yet this is clearly forbidden by the dictum in question.  So, what am I
> missing?

So, this is "mostly harmless."

However, a non-zero return from match _DOES NOT_ guarantee that the
device will be attached.

In other words, in this case, the space for 'table' would end up being
wasted if no units of 'xxx' were actually attached.

While that's not too much of a concern for indirect-config busses
(i.e. it wouldn't often happen), it still _can_ happen, and so must be
planned for.  On direct-config busses, it's standard operating
procedure to ignore some non-zero error returns (because other devices
can return 'better' values from match).


Like Chris Torek said: you can break the rules if you know exactly how
you're breaking them, and know the implications of what you're doing.
However, most people _don't_, and it's not something that you can
easily figure out by reading an e-mail message, in my opinion.

Therefore, i just tell people "don't do it," because that's the safe
course.


cgd