Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions firehose.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static int firehose_try_configure(struct qdl_device *qdl, bool skip_storage_init
size_t size = 0;
void *buf;
int ret;
int i;
unsigned int i;

ret = firehose_send_configure(qdl, qdl->max_payload_size, skip_storage_init,
storage, &size);
Expand Down Expand Up @@ -454,6 +454,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
int left;
int ret;
int n;
size_t i;
uint32_t fill_value;

/*
Expand Down Expand Up @@ -526,8 +527,8 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
break;
case CHUNK_TYPE_FILL:
fill_value = program->sparse_fill_value;
for (n = 0; n < qdl->max_payload_size; n += sizeof(fill_value))
memcpy(buf + n, &fill_value, sizeof(fill_value));
for (i = 0; i < qdl->max_payload_size; i += sizeof(fill_value))
memcpy(buf + i, &fill_value, sizeof(fill_value));
break;
default:
ux_err("[SPARSE] invalid chunk type\n");
Expand Down Expand Up @@ -555,7 +556,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
goto out;
}

if (n < qdl->max_payload_size)
if ((size_t)n < qdl->max_payload_size)
Copy link
Contributor Author

@igoropaniuk igoropaniuk Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check of n < 0 is above, so safe to cast here

memset(buf + n, 0, qdl->max_payload_size - n);
}

Expand Down Expand Up @@ -587,7 +588,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
goto out;
}

if (n != chunk_size * sector_size) {
if ((size_t)n != chunk_size * sector_size) {
ux_err("USB write truncated\n");
ret = -1;
goto out;
Expand Down Expand Up @@ -686,20 +687,20 @@ static int firehose_issue_read(struct qdl_device *qdl, struct read_op *read_op,
continue;
} else if (expect_empty) {
err(1, "expected empty transfer but received non-empty transfer during read");
} else if (n != chunk_size * sector_size) {
} else if ((size_t)n != chunk_size * sector_size) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check of n < 0 is above, so safe to cast here

err(1, "failed to read full sector");
}

if (out_buf) {
if (n > out_len - out_offset)
if ((size_t)n > out_len - out_offset)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check of n < 0 is already above, so safe to cast here

n = out_len - out_offset;

memcpy(out_buf + out_offset, buf, n);
out_offset += n;
} else {
n = write(fd, buf, n);

if (n != chunk_size * sector_size) {
if (n < 0 || (size_t)n != chunk_size * sector_size) {
err(1, "failed to write");
}
}
Expand Down
2 changes: 1 addition & 1 deletion gpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static int gpt_load_table_from_partition(struct qdl_device *qdl, unsigned int ph
uint16_t name_utf16le[36];
char name[36 * 4];
int ret;
int i;
unsigned int i;

memset(&op, 0, sizeof(op));

Expand Down
10 changes: 5 additions & 5 deletions sahara.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static void sahara_read(struct qdl_device *qdl, struct sahara_pkt *pkt,
}

ret = qdl_write(qdl, image->ptr + offset, len, SAHARA_CMD_TIMEOUT_MS);
if (ret != len)
if (ret < 0 || ((size_t)ret != len))
err(1, "failed to write %zu bytes to sahara", len);
}

Expand Down Expand Up @@ -220,7 +220,7 @@ static void sahara_read64(struct qdl_device *qdl, struct sahara_pkt *pkt,
}

ret = qdl_write(qdl, image->ptr + offset, len, SAHARA_CMD_TIMEOUT_MS);
if (ret != len)
if (ret < 0 || ((size_t)ret != len))
err(1, "failed to write %zu bytes to sahara", len);
}

Expand Down Expand Up @@ -302,7 +302,7 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
goto out;
}

while (buf_offset < n) {
while (buf_offset < (size_t)n) {
written = write(fd, buf + buf_offset, n - buf_offset);
if (written <= 0) {
warn("failed to write ramdump chunk to \"%s\"", region.filename);
Expand Down Expand Up @@ -373,7 +373,7 @@ static void sahara_debug64(struct qdl_device *qdl, struct sahara_pkt *pkt,
struct sahara_debug_region64 *table;
struct sahara_pkt read_req;
ssize_t n;
int i;
size_t i;

assert(pkt->length == SAHARA_MEM_DEBUG64_LENGTH);

Expand Down Expand Up @@ -455,7 +455,7 @@ int sahara_run(struct qdl_device *qdl, const struct sahara_image *images,
}

pkt = (struct sahara_pkt *)buf;
if (n != pkt->length) {
if ((uint32_t)n != pkt->length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check of n < 0 is already above, so safe to cast here

ux_err("request length not matching received request\n");
return -EINVAL;
}
Expand Down
4 changes: 2 additions & 2 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void print_hex_dump(const char *prefix, const void *buf, size_t len)
uint8_t ch;
char line[16 * 3 + 16 + 1];
int li;
int i;
int j;
unsigned int i;
unsigned int j;

for (i = 0; i < len; i += 16) {
linelen = MIN(16, len - i);
Expand Down
6 changes: 3 additions & 3 deletions vip.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,15 @@ int vip_transfer_init(struct qdl_device *qdl, const char *vip_table_path)

out_cleanup:
close(qdl->vip_data.signed_table_fd);
for (int i = 0; i < qdl->vip_data.chained_num - 1; ++i)
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
close(qdl->vip_data.chained_fds[i]);
return -1;
}

void vip_transfer_deinit(struct qdl_device *qdl)
{
close(qdl->vip_data.signed_table_fd);
for (int i = 0; i < qdl->vip_data.chained_num - 1; ++i)
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
close(qdl->vip_data.chained_fds[i]);
}

Expand All @@ -412,7 +412,7 @@ static int vip_transfer_send_raw(struct qdl_device *qdl, int table_fd)
struct stat sb;
int ret;
void *buf;
size_t n;
ssize_t n;

ret = fstat(table_fd, &sb);
if (ret < 0) {
Expand Down
Loading