Patchwork flash_erase: use pwrite() rather than lseek() && write()

login
register
mail settings
Submitter Mike Frysinger
Date May 2, 2013, 4:33 p.m.
Message ID <1367512401-14689-1-git-send-email-vapier@gentoo.org>
Download mbox | patch
Permalink /patch/241040/
State Accepted
Commit d51d421d1b8f1afcedb8593ce835819c57792f45
Headers show

Comments

Mike Frysinger - May 2, 2013, 4:33 p.m.
Saves a syscall.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 flash_erase.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
Artem Bityutskiy - May 29, 2013, 12:36 p.m.
On Thu, 2013-05-02 at 12:33 -0400, Mike Frysinger wrote:
> Saves a syscall.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Pushed to mtd-utils.git, thanks!

Patch

diff --git a/flash_erase.c b/flash_erase.c
index 326a299..1421cf9 100644
--- a/flash_erase.c
+++ b/flash_erase.c
@@ -277,11 +277,7 @@  int main(int argc, char *argv[])
 				continue;
 			}
 		} else {
-			if (lseek(fd, offset, SEEK_SET) < 0) {
-				sys_errmsg("%s: MTD lseek failure", mtd_device);
-				continue;
-			}
-			if (write(fd, &cleanmarker, sizeof(cleanmarker)) != sizeof(cleanmarker)) {
+			if (pwrite(fd, &cleanmarker, sizeof(cleanmarker), (loff_t)offset) != sizeof(cleanmarker)) {
 				sys_errmsg("%s: MTD write failure", mtd_device);
 				continue;
 			}