forked from Sricharanti/sricharan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coccinelle: semantic patches related to devm_ functions (part 1)
devm_ functions allocate memory that is to remain allocated until the device is detached. This patch checks for opportunities for using the function devm_request_and_ioremap. Signed-off-by: Julia Lawall <[email protected]> Signed-off-by: Michal Marek <[email protected]>
- Loading branch information
1 parent
f95ab20
commit 22e0059
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/// Reimplement a call to devm_request_mem_region followed by a call to ioremap | ||
/// or ioremap_nocache by a call to devm_request_and_ioremap. | ||
/// Devm_request_and_ioremap was introduced in | ||
/// 72f8c0bfa0de64c68ee59f40eb9b2683bffffbb0. It makes the code much more | ||
/// concise. | ||
/// | ||
/// | ||
// Confidence: High | ||
// Copyright: (C) 2011 Julia Lawall, INRIA/LIP6. GPLv2. | ||
// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2. | ||
// URL: http://coccinelle.lip6.fr/ | ||
// Comments: | ||
// Options: -no_includes -include_headers | ||
|
||
virtual patch | ||
virtual org | ||
virtual report | ||
virtual context | ||
|
||
@nm@ | ||
expression myname; | ||
identifier i; | ||
@@ | ||
|
||
struct platform_driver i = { .driver = { .name = myname } }; | ||
|
||
@depends on patch@ | ||
expression dev,res,size; | ||
@@ | ||
|
||
-if (!devm_request_mem_region(dev, res->start, size, | ||
- \(res->name\|dev_name(dev)\))) { | ||
- ... | ||
- return ...; | ||
-} | ||
... when != res->start | ||
( | ||
-devm_ioremap(dev,res->start,size) | ||
+devm_request_and_ioremap(dev,res) | ||
| | ||
-devm_ioremap_nocache(dev,res->start,size) | ||
+devm_request_and_ioremap(dev,res) | ||
) | ||
... when any | ||
when != res->start | ||
|
||
// this rule is separate from the previous one, because a single file can | ||
// have multiple values of myname | ||
@depends on patch@ | ||
expression dev,res,size; | ||
expression nm.myname; | ||
@@ | ||
|
||
-if (!devm_request_mem_region(dev, res->start, size,myname)) { | ||
- ... | ||
- return ...; | ||
-} | ||
... when != res->start | ||
( | ||
-devm_ioremap(dev,res->start,size) | ||
+devm_request_and_ioremap(dev,res) | ||
| | ||
-devm_ioremap_nocache(dev,res->start,size) | ||
+devm_request_and_ioremap(dev,res) | ||
) | ||
... when any | ||
when != res->start | ||
|
||
|
||
@pb depends on org || report || context@ | ||
expression dev,res,size; | ||
expression nm.myname; | ||
position p1,p2; | ||
@@ | ||
|
||
*if | ||
(!devm_request_mem_region@p1(dev, res->start, size, | ||
\(res->name\|dev_name(dev)\|myname\))) { | ||
... | ||
return ...; | ||
} | ||
... when != res->start | ||
( | ||
*devm_ioremap@p2(dev,res->start,size) | ||
| | ||
*devm_ioremap_nocache@p2(dev,res->start,size) | ||
) | ||
... when any | ||
when != res->start | ||
|
||
@script:python depends on org@ | ||
p1 << pb.p1; | ||
p2 << pb.p2; | ||
@@ | ||
cocci.print_main("INFO: replace by devm_request_and_ioremap",p1) | ||
cocci.print_secs("",p2) | ||
@script:python depends on report@ | ||
p1 << pb.p1; | ||
p2 << pb.p2; | ||
@@ | ||
msg = "INFO: devm_request_mem_region followed by ioremap on line %s can be replaced by devm_request_and_ioremap" % (p2[0].line) | ||
coccilib.report.print_report(p1[0],msg) |