coreboot-kgpe-d16/util
Carl-Daniel Hailfinger 59c36f97db During the conversion of flash chip accesses to helper functions, I
spotted assignments to volatile variables which were neither placed
inside the mmapped ROM area nor were they counters.
Due to the use of accessor functions, volatile usage can be reduced
significantly because the accessor functions take care of actually
performing the reads/writes correctly.

The following semantic patch spotted them (linebreak in python string
for readability reasons, please remove before usage):
@r exists@
expression b;
typedef uint8_t;
volatile uint8_t a;
position p1;
@@
 a@p1 = readb(b);

@script:python@
p1 << r.p1;
a << r.a;
b << r.b;
@@
print "* file: %s line %s has assignment to unnecessarily volatile
variable: %s = readb(%s);" % (p1[0].file, p1[0].line, a, b)

Result was:
HANDLING: sst28sf040.c
* file: sst28sf040.c line 44 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 43 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 42 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 41 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 40 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 39 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 38 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 58 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 57 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 56 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 55 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 54 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 53 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);
* file: sst28sf040.c line 52 has assignment to unnecessarily volatile
variable: tmp = readb(TODO: Binary);

The following semantic patch uses the spatch builtin match printing
functionality by prepending a "*" to the line with the pattern:
@@
expression b;
typedef uint8_t;
volatile uint8_t a;
@@
* a = readb(b);

Result is:
HANDLING: sst28sf040.c
diff =
--- sst28sf040.c        2009-03-06 01:04:49.000000000 +0100
@@ -35,13 +35,6 @@ static __inline__ void protect_28sf040(v
        /* ask compiler not to optimize this */
        volatile uint8_t tmp;
 
-       tmp = readb(bios + 0x1823);
-       tmp = readb(bios + 0x1820);
-       tmp = readb(bios + 0x1822);
-       tmp = readb(bios + 0x0418);
-       tmp = readb(bios + 0x041B);
-       tmp = readb(bios + 0x0419);
-       tmp = readb(bios + 0x040A);
 }
 
 static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
@@ -49,13 +42,6 @@ static __inline__ void unprotect_28sf040
        /* ask compiler not to optimize this */
        volatile uint8_t tmp;
 
-       tmp = readb(bios + 0x1823);
-       tmp = readb(bios + 0x1820);
-       tmp = readb(bios + 0x1822);
-       tmp = readb(bios + 0x0418);
-       tmp = readb(bios + 0x041B);
-       tmp = readb(bios + 0x0419);
-       tmp = readb(bios + 0x041A);
 }
 
 static __inline__ int erase_sector_28sf040(volatile uint8_t *bios,

It's arguably a bit easier to read if you get used to the leading "-"
for matching lines.

This patch was enabled by Coccinelle:
http://www.emn.fr/x-info/coccinelle/


Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Joseph Smith <joe@settoplinux.org>
-- 
http://www.hailfinger.org/


git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3973 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
2009-03-06 00:40:25 +00:00
..
ADLO Changes Makefile generation so that recursive "make" calls read 2008-06-08 23:05:24 +00:00
abuild Add an abuild command line option for -fno-stack-protect for toolchains that might require it. 2008-09-30 17:09:44 +00:00
analysis Rename almost all occurences of LinuxBIOS to coreboot. 2008-01-18 15:08:58 +00:00
buildrom fix build warnings for buildrom (trivial) 2008-08-01 11:20:33 +00:00
dump_mmcr small ts5300 update, fix endian problem in dummmcr. 2006-03-18 00:10:29 +00:00
flashrom During the conversion of flash chip accesses to helper functions, I 2009-03-06 00:40:25 +00:00
getpir cosmetic update for getpir. 2008-11-10 13:52:14 +00:00
inteltool Patch to util/inteltool: 2008-12-04 15:18:20 +00:00
k8resdump K8 resource dump utility from Rudolf Marek 2007-10-30 01:12:20 +00:00
lbtdump Fix a typo in lbtdump output (trivial). 2008-05-07 19:21:18 +00:00
mkelfImage Add the contents of buildrom's 2008-08-06 20:37:38 +00:00
mptable fix typo 2008-03-15 16:30:39 +00:00
msrtool msrtool: Allow MSR symbols (names) to also be used as addresses. 2009-01-26 17:18:31 +00:00
newconfig coreboot-v2: drop this ugly historic union name in v2 that was dropped in v3 2009-02-28 20:10:20 +00:00
nrv2b - Minor mod to reset16.inc to work with newer binutils hopefully this works with older ones... 2003-06-17 08:42:17 +00:00
nvramtool Move the nvramtool manpage to section 8 (as it's only really usable as root), 2008-10-31 05:40:04 +00:00
optionlist Rename almost all occurences of LinuxBIOS to coreboot. 2008-01-18 15:08:58 +00:00
options build_opt_tbl: 2008-12-02 12:26:17 +00:00
resetcf epia-m support 2004-10-06 17:33:54 +00:00
romcc Rename almost all occurences of LinuxBIOS to coreboot. 2008-01-18 15:08:58 +00:00
superiotool This adds register map based on NSC PC87392 datasheet. LDN#2 can be 2008-12-20 19:35:54 +00:00
vgabios Change 0x%p to %p. Thanks Stefan for catching the one I introduced in 3931. 2009-02-10 03:02:05 +00:00