mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-10-15 07:22:46 +00:00
nbd: Don't use *_to_cpup() functions
The *_to_cpup() functions are not very useful, as they simply do a pointer dereference and then a *_to_cpu(). Instead use either: * ld*_*_p(), if the data is at an address that might not be correctly aligned for the load * a local dereference and *_to_cpu(), if the pointer is the correct type and known to be correctly aligned Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <1465570836-22211-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
0fb2331254
commit
773dce3c72
|
@ -572,7 +572,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags,
|
||||||
error_setg(errp, "Failed to read export flags");
|
error_setg(errp, "Failed to read export flags");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
*flags = be32_to_cpup(flags);
|
*flags = be32_to_cpu(*flags);
|
||||||
} else {
|
} else {
|
||||||
error_setg(errp, "Bad magic received");
|
error_setg(errp, "Bad magic received");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -726,9 +726,9 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, struct nbd_reply *reply)
|
||||||
[ 7 .. 15] handle
|
[ 7 .. 15] handle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
magic = be32_to_cpup((uint32_t*)buf);
|
magic = ldl_be_p(buf);
|
||||||
reply->error = be32_to_cpup((uint32_t*)(buf + 4));
|
reply->error = ldl_be_p(buf + 4);
|
||||||
reply->handle = be64_to_cpup((uint64_t*)(buf + 8));
|
reply->handle = ldq_be_p(buf + 8);
|
||||||
|
|
||||||
reply->error = nbd_errno_to_system_errno(reply->error);
|
reply->error = nbd_errno_to_system_errno(reply->error);
|
||||||
|
|
||||||
|
|
10
nbd/server.c
10
nbd/server.c
|
@ -646,11 +646,11 @@ static ssize_t nbd_receive_request(QIOChannel *ioc, struct nbd_request *request)
|
||||||
[24 .. 27] len
|
[24 .. 27] len
|
||||||
*/
|
*/
|
||||||
|
|
||||||
magic = be32_to_cpup((uint32_t*)buf);
|
magic = ldl_be_p(buf);
|
||||||
request->type = be32_to_cpup((uint32_t*)(buf + 4));
|
request->type = ldl_be_p(buf + 4);
|
||||||
request->handle = be64_to_cpup((uint64_t*)(buf + 8));
|
request->handle = ldq_be_p(buf + 8);
|
||||||
request->from = be64_to_cpup((uint64_t*)(buf + 16));
|
request->from = ldq_be_p(buf + 16);
|
||||||
request->len = be32_to_cpup((uint32_t*)(buf + 24));
|
request->len = ldl_be_p(buf + 24);
|
||||||
|
|
||||||
TRACE("Got request: "
|
TRACE("Got request: "
|
||||||
"{ magic = 0x%x, .type = %d, from = %" PRIu64" , len = %u }",
|
"{ magic = 0x%x, .type = %d, from = %" PRIu64" , len = %u }",
|
||||||
|
|
|
@ -154,8 +154,8 @@ static void read_partition(uint8_t *p, struct partition_record *r)
|
||||||
r->end_cylinder = p[7] | ((p[6] << 2) & 0x300);
|
r->end_cylinder = p[7] | ((p[6] << 2) & 0x300);
|
||||||
r->end_sector = p[6] & 0x3f;
|
r->end_sector = p[6] & 0x3f;
|
||||||
|
|
||||||
r->start_sector_abs = le32_to_cpup((uint32_t *)(p + 8));
|
r->start_sector_abs = ldl_le_p(p + 8);
|
||||||
r->nb_sectors_abs = le32_to_cpup((uint32_t *)(p + 12));
|
r->nb_sectors_abs = ldl_le_p(p + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_partition(BlockBackend *blk, int partition,
|
static int find_partition(BlockBackend *blk, int partition,
|
||||||
|
|
Loading…
Reference in a new issue