[U-Boot] [PATCH 2/6] Separate flash read and write operations

Guennadi Liakhovetski lg at denx.de
Sun Aug 31 21:45:45 CEST 2008


On Sun, 31 Aug 2008, Wolfgang Denk wrote:

> Dear Guennadi Liakhovetski,
> 
> In message <Pine.LNX.4.64.0808311757460.3747 at axis700.grange> you wrote:
> > 
> > So, no, this is not because I didn't like somebody else's coding style. 
> > This is because with NAND addition this function would become an 
> > absolutely unreadable monster. So, I would consider this patch a 
> > readability improvement.
> 
> But you are duplicating code. It may be just 20 lines or so, but  the
> better  approach  would  be to leave the common code as is and factor
> out two new functions being called from the common code.

Yes, the original code was:

...
	flash_io(O_RDONLY);
...
	flash_io(O_RDONLY);
...
	flash_io(O_RDWR);

int flash_io(int mode)
{
	fd = open(path, mode);

	if (mode == O_RDONLY) {
		...
	} else {
		...
	}

	close(fd);
}

I changed it to

...
	flash_read();
...
	flash_read();
...
	flash_write();
...

int flash_read(void)
{
	fd = open(path, O_RDONLY);

	...

	close(fd);
}

int flash_write(void)
{
	fd = open(path, O_RDWR);

	...

	close(fd);
}

yes, I thus duplicate "open" and "close". We could do

...
	flash_io(O_RDONLY);
...
	flash_io(O_RDONLY);
...
	flash_io(O_RDWR);

int flash_io(int mode)
{
	fd = open(path, mode);

	if (mode == O_RDONLY) {
		do_flash_read(fd);
	} else {
		do_flash_write(fd);
	}

	close(fd);
}

but, honestly, I prefer my version. If you disagree, I can change it to 
variant 3, no problem. This will mean redoing all patches 2-6 though...

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.

DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de


More information about the U-Boot mailing list