mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
tools/hv: Check for read/write errors
commit 436473bc21
upstream.
hv_kvp_daemon currently does not check whether fread() or fwrite()
succeed. Add the necessary checks. Also, remove the incorrect use of
feof() before fread().
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
de5d66e635
commit
1eafb0280d
1 changed files with 19 additions and 3 deletions
|
@ -144,7 +144,12 @@ static void kvp_update_file(int pool)
|
|||
sizeof(struct kvp_record),
|
||||
kvp_file_info[pool].num_records, filep);
|
||||
|
||||
fclose(filep);
|
||||
if (ferror(filep) || fclose(filep)) {
|
||||
kvp_release_lock(pool);
|
||||
syslog(LOG_ERR, "Failed to write file, pool: %d", pool);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
kvp_release_lock(pool);
|
||||
}
|
||||
|
||||
|
@ -165,12 +170,17 @@ static void kvp_update_mem_state(int pool)
|
|||
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (!feof(filep)) {
|
||||
for (;;) {
|
||||
readp = &record[records_read];
|
||||
records_read += fread(readp, sizeof(struct kvp_record),
|
||||
ENTRIES_PER_BLOCK * num_blocks,
|
||||
filep);
|
||||
|
||||
if (ferror(filep)) {
|
||||
syslog(LOG_ERR, "Failed to read file, pool: %d", pool);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!feof(filep)) {
|
||||
/*
|
||||
* We have more data to read.
|
||||
|
@ -233,12 +243,18 @@ static int kvp_file_init(void)
|
|||
fclose(filep);
|
||||
return 1;
|
||||
}
|
||||
while (!feof(filep)) {
|
||||
for (;;) {
|
||||
readp = &record[records_read];
|
||||
records_read += fread(readp, sizeof(struct kvp_record),
|
||||
ENTRIES_PER_BLOCK,
|
||||
filep);
|
||||
|
||||
if (ferror(filep)) {
|
||||
syslog(LOG_ERR, "Failed to read file, pool: %d",
|
||||
i);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!feof(filep)) {
|
||||
/*
|
||||
* We have more data to read.
|
||||
|
|
Loading…
Reference in a new issue