qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] nbd: Don't use cpu_to_*w() functions
@ 2016-06-10 16:15 Peter Maydell
  2016-06-10 19:13 ` Eric Blake
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2016-06-10 16:15 UTC (permalink / raw)
  To: qemu-devel; +Cc: patches, Paolo Bonzini, Eric Blake

The cpu_to_*w() functions just compose a pointer dereference
with a byteswap. Instead use st*_p(), which handles potential
pointer misalignment and avoids the need to cast the pointer.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 nbd/client.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/nbd/client.c b/nbd/client.c
index bb8981f..6d9c74d 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -686,11 +686,11 @@ ssize_t nbd_send_request(QIOChannel *ioc, struct nbd_request *request)
           "{ .from = %" PRIu64", .len = %u, .handle = %" PRIu64", .type=%i}",
           request->from, request->len, request->handle, request->type);
 
-    cpu_to_be32w((uint32_t*)buf, NBD_REQUEST_MAGIC);
-    cpu_to_be32w((uint32_t*)(buf + 4), request->type);
-    cpu_to_be64w((uint64_t*)(buf + 8), request->handle);
-    cpu_to_be64w((uint64_t*)(buf + 16), request->from);
-    cpu_to_be32w((uint32_t*)(buf + 24), request->len);
+    stl_be_p(buf, NBD_REQUEST_MAGIC);
+    stl_be_p(buf + 4, request->type);
+    stq_be_p(buf + 8, request->handle);
+    stq_be_p(buf + 16, request->from);
+    stl_be_p(buf + 24, request->len);
 
     ret = write_sync(ioc, buf, sizeof(buf));
     if (ret < 0) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] nbd: Don't use cpu_to_*w() functions
  2016-06-10 16:15 [Qemu-devel] [PATCH] nbd: Don't use cpu_to_*w() functions Peter Maydell
@ 2016-06-10 19:13 ` Eric Blake
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2016-06-10 19:13 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: patches, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

On 06/10/2016 10:15 AM, Peter Maydell wrote:
> The cpu_to_*w() functions just compose a pointer dereference
> with a byteswap. Instead use st*_p(), which handles potential
> pointer misalignment and avoids the need to cast the pointer.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  nbd/client.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-10 19:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-10 16:15 [Qemu-devel] [PATCH] nbd: Don't use cpu_to_*w() functions Peter Maydell
2016-06-10 19:13 ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).