Skip to content

Commit 0b6b9e3

Browse files
authored
Merge pull request #102 from igoropaniuk/sahara_warning_fix
sahara: fix ignoring return value warning
2 parents 3ed79be + 8a996e5 commit 0b6b9e3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

sahara.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
306306
{
307307
struct sahara_pkt read_req;
308308
uint64_t remain;
309-
size_t offset;
309+
size_t offset, buf_offset;
310310
size_t chunk;
311+
size_t written;
311312
ssize_t n;
312313
void *buf;
313314
int fd;
@@ -318,7 +319,7 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
318319

319320
char path[PATH_MAX];
320321
snprintf(path, sizeof(path), "%s/%s", ramdump_path, region.filename);
321-
322+
322323
fd = open(path, O_WRONLY | O_CREAT | O_BINARY, 0644);
323324
if (fd < 0) {
324325
warn("failed to open \"%s\"", region.filename);
@@ -339,14 +340,23 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
339340

340341
offset = 0;
341342
while (offset < remain) {
343+
buf_offset = 0;
342344
n = qdl_read(qdl, buf, DEBUG_BLOCK_SIZE, 30000);
343345
if (n < 0) {
344346
warn("failed to read ramdump chunk");
345347
goto out;
346348
}
347349

348-
write(fd, buf, n);
349-
offset += n;
350+
while (buf_offset < n) {
351+
written = write(fd, buf + buf_offset, n - buf_offset);
352+
if (written <= 0) {
353+
warn("failed to write ramdump chunk to \"%s\"", region.filename);
354+
goto out;
355+
}
356+
buf_offset += written;
357+
}
358+
359+
offset += buf_offset;
350360
}
351361

352362
qdl_read(qdl, buf, DEBUG_BLOCK_SIZE, 10);

0 commit comments

Comments
 (0)