Bug 72851

Summary: The funtion "clk_find" in "drivers/clk/clkdev.c" deviated its original idea
Product: Drivers Reporter: ChengyongLin (msecurity)
Component: OtherAssignee: drivers_other
Status: NEW ---    
Severity: normal CC: alan, rmk
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.13.6/3.14-rc7 Subsystem:
Regression: No Bisected commit-id:

Description ChengyongLin 2014-03-24 03:29:32 UTC
Hello.
The funtion "clk_find(dev_id, con_id)" takes the most specific entry - with the following order of precedence: dev_id+con_id > dev_id only > con_id only,but actually it doesn't work very well. 
In the code,
"		if (p->dev_id) {
			if (!dev_id || strcmp(p->dev_id, dev_id))
				continue;
			match += 2;
		}
		if (p->con_id) {
			if (!con_id || strcmp(p->con_id, con_id))
				continue;
			match += 1;
		}
		if (match > best_found) {
			cl = p;
			if (match != best_possible)
				best_found = match;
			else
				break;
		}
"
it uses the "continue", then we can assume that if only dev_id matches,and con_id doesn't match,it enters into next loop,so c1 is equal to NULL.After the lists has been traversed,the c1 is still equal to NULL.But in fact we can find a clock that matches the dev_id.This function only works well when dev_id and con_id are all matched at the same time.
I suggest that we could modify like this for example:
"		if (p->dev_id) {
			if (!dev_id || strcmp(p->dev_id, dev_id))
				match = match;
                        else
			        match += 2;
		}
		if (p->con_id) {
			if (!con_id || strcmp(p->con_id, con_id))
				match = match;
                        else
			        match += 1;
		}
 "
Thanks for your reading!
Comment 1 Alan 2014-04-08 10:35:54 UTC
Bugzilla is only used for bug tracking. Changes should be discussed on the mailing lists.