Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /// Find missing put_device for every of_find_device_by_node.
0003 ///
0004 // Confidence: Moderate
0005 // Copyright: (C) 2018-2019 Wen Yang, ZTE.
0006 // Comments:
0007 // Options: --no-includes --include-headers
0008 
0009 virtual report
0010 virtual org
0011 
0012 @search exists@
0013 local idexpression id;
0014 expression x,e,e1;
0015 position p1,p2;
0016 type T,T1,T2,T3;
0017 @@
0018 
0019 id = of_find_device_by_node@p1(x)
0020 ... when != e = id
0021 if (id == NULL || ...) { ... return ...; }
0022 ... when != put_device(&id->dev)
0023     when != platform_device_put(id)
0024     when != if (id) { ... put_device(&id->dev) ... }
0025     when != e1 = (T)id
0026     when != e1 = (T)(&id->dev)
0027     when != e1 = get_device(&id->dev)
0028     when != e1 = (T1)platform_get_drvdata(id)
0029 (
0030   return
0031 (    id
0032 |    (T2)dev_get_drvdata(&id->dev)
0033 |    (T3)platform_get_drvdata(id)
0034 |    &id->dev
0035 );
0036 | return@p2 ...;
0037 )
0038 
0039 @script:python depends on report@
0040 p1 << search.p1;
0041 p2 << search.p2;
0042 @@
0043 
0044 coccilib.report.print_report(p2[0],
0045                              "ERROR: missing put_device; call of_find_device_by_node on line "
0046                              + p1[0].line
0047                              + ", but without a corresponding object release within this function.")
0048 
0049 @script:python depends on org@
0050 p1 << search.p1;
0051 p2 << search.p2;
0052 @@
0053 
0054 cocci.print_main("of_find_device_by_node", p1)
0055 cocci.print_secs("needed put_device", p2)