From dc848566a17eb62109b0e682e8c62628e420ea19 Mon Sep 17 00:00:00 2001 From: Biao Lu Date: Thu, 28 Jan 2016 16:10:54 +0800 Subject: [PATCH] init: Fix load_firmware error In function 'load_firmware', parameter 'buf' passed to 'write' is wrong. To fix it, use android::base::WriteFully to replace. Change-Id: I13f79bdc9be9e5eb669f6bd975535b1dce965ef0 Signed-off-by: Biao Lu --- init/devices.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/init/devices.cpp b/init/devices.cpp index d556e307c..39cd70656 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -769,21 +770,13 @@ static int load_firmware(int fw_fd, int loading_fd, int data_fd) ret = -1; break; } - - len_to_copy -= nr; - while (nr > 0) { - ssize_t nw = 0; - - nw = write(data_fd, buf + nw, nr); - if(nw <= 0) { - ret = -1; - goto out; - } - nr -= nw; + if (!android::base::WriteFully(data_fd, buf, nr)) { + ret = -1; + break; } + len_to_copy -= nr; } -out: if(!ret) write(loading_fd, "0", 1); /* successful end of transfer */ else