qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc()
@ 2014-12-04 13:12 Markus Armbruster
  2014-12-04 13:12 ` [Qemu-devel] [PATCH 1/3] scsi: Drop superfluous conditionals around g_free() Markus Armbruster
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Markus Armbruster @ 2014-12-04 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini

Markus Armbruster (3):
  scsi: Drop superfluous conditionals around g_free()
  scsi: Fuse g_malloc(); memset() into  g_malloc0()
  scsi: Use g_new() & friends where that makes obvious sense

 hw/scsi/lsi53c895a.c   | 2 +-
 hw/scsi/megasas.c      | 6 ++----
 hw/scsi/scsi-generic.c | 6 ++----
 hw/scsi/virtio-scsi.c  | 2 +-
 4 files changed, 6 insertions(+), 10 deletions(-)

-- 
1.9.3

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

* [Qemu-devel] [PATCH 1/3] scsi: Drop superfluous conditionals around g_free()
  2014-12-04 13:12 [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Markus Armbruster
@ 2014-12-04 13:12 ` Markus Armbruster
  2014-12-04 13:12 ` [Qemu-devel] [PATCH 2/3] scsi: Fuse g_malloc(); memset() into g_malloc0() Markus Armbruster
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2014-12-04 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi/scsi-generic.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 6b9e4e1..e53470f 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -298,8 +298,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *cmd)
 #endif
 
     if (r->req.cmd.xfer == 0) {
-        if (r->buf != NULL)
-            g_free(r->buf);
+        g_free(r->buf);
         r->buflen = 0;
         r->buf = NULL;
         /* The request is used as the AIO opaque value, so add a ref.  */
@@ -314,8 +313,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *cmd)
     }
 
     if (r->buflen != r->req.cmd.xfer) {
-        if (r->buf != NULL)
-            g_free(r->buf);
+        g_free(r->buf);
         r->buf = g_malloc(r->req.cmd.xfer);
         r->buflen = r->req.cmd.xfer;
     }
-- 
1.9.3

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

* [Qemu-devel] [PATCH 2/3] scsi: Fuse g_malloc(); memset() into  g_malloc0()
  2014-12-04 13:12 [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Markus Armbruster
  2014-12-04 13:12 ` [Qemu-devel] [PATCH 1/3] scsi: Drop superfluous conditionals around g_free() Markus Armbruster
@ 2014-12-04 13:12 ` Markus Armbruster
  2014-12-04 13:12 ` [Qemu-devel] [PATCH 3/3] scsi: Use g_new() & friends where that makes obvious sense Markus Armbruster
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2014-12-04 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini

Coccinelle semantic patch:

    @@
    expression LHS, SZ;
    @@
    -       LHS = g_malloc(SZ);
    -       memset(LHS, 0, SZ);
    +       LHS = g_malloc0(SZ);

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi/megasas.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 604252a..4852237 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -1018,8 +1018,7 @@ static int megasas_pd_get_info_submit(SCSIDevice *sdev, int lun,
     size_t len, resid;
 
     if (!cmd->iov_buf) {
-        cmd->iov_buf = g_malloc(dcmd_size);
-        memset(cmd->iov_buf, 0, dcmd_size);
+        cmd->iov_buf = g_malloc0(dcmd_size);
         info = cmd->iov_buf;
         info->inquiry_data[0] = 0x7f; /* Force PQual 0x3, PType 0x1f */
         info->vpd_page83[0] = 0x7f;
@@ -1221,8 +1220,7 @@ static int megasas_ld_get_info_submit(SCSIDevice *sdev, int lun,
     uint64_t ld_size;
 
     if (!cmd->iov_buf) {
-        cmd->iov_buf = g_malloc(dcmd_size);
-        memset(cmd->iov_buf, 0x0, dcmd_size);
+        cmd->iov_buf = g_malloc0(dcmd_size);
         info = cmd->iov_buf;
         megasas_setup_inquiry(cdb, 0x83, sizeof(info->vpd_page83));
         req = scsi_req_new(sdev, cmd->index, lun, cdb, cmd);
-- 
1.9.3

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

* [Qemu-devel] [PATCH 3/3] scsi: Use g_new() & friends where that makes obvious sense
  2014-12-04 13:12 [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Markus Armbruster
  2014-12-04 13:12 ` [Qemu-devel] [PATCH 1/3] scsi: Drop superfluous conditionals around g_free() Markus Armbruster
  2014-12-04 13:12 ` [Qemu-devel] [PATCH 2/3] scsi: Fuse g_malloc(); memset() into g_malloc0() Markus Armbruster
@ 2014-12-04 13:12 ` Markus Armbruster
  2014-12-05  4:57 ` [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Eric Blake
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2014-12-04 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini

g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,
for two reasons.  One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.

This commit only touches allocations with size arguments of the form
sizeof(T).

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi/lsi53c895a.c  | 2 +-
 hw/scsi/virtio-scsi.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index d9b4c7e..ec92048 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -781,7 +781,7 @@ static void lsi_do_command(LSIState *s)
     }
 
     assert(s->current == NULL);
-    s->current = g_malloc0(sizeof(lsi_request));
+    s->current = g_new0(lsi_request, 1);
     s->current->tag = s->select_tag;
     s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun, buf,
                                    s->current);
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index ef48550..b06dd39 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -829,7 +829,7 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
         virtio_cleanup(vdev);
         return;
     }
-    s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
+    s->cmd_vqs = g_new0(VirtQueue *, s->conf.num_queues);
     s->sense_size = VIRTIO_SCSI_SENSE_SIZE;
     s->cdb_size = VIRTIO_SCSI_CDB_SIZE;
 
-- 
1.9.3

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

* Re: [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc()
  2014-12-04 13:12 [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Markus Armbruster
                   ` (2 preceding siblings ...)
  2014-12-04 13:12 ` [Qemu-devel] [PATCH 3/3] scsi: Use g_new() & friends where that makes obvious sense Markus Armbruster
@ 2014-12-05  4:57 ` Eric Blake
  2014-12-05  6:51 ` Fam Zheng
  2014-12-05 15:55 ` Paolo Bonzini
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Blake @ 2014-12-05  4:57 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel; +Cc: pbonzini

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

On 12/04/2014 06:12 AM, Markus Armbruster wrote:
> Markus Armbruster (3):
>   scsi: Drop superfluous conditionals around g_free()
>   scsi: Fuse g_malloc(); memset() into  g_malloc0()
>   scsi: Use g_new() & friends where that makes obvious sense

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

> 
>  hw/scsi/lsi53c895a.c   | 2 +-
>  hw/scsi/megasas.c      | 6 ++----
>  hw/scsi/scsi-generic.c | 6 ++----
>  hw/scsi/virtio-scsi.c  | 2 +-
>  4 files changed, 6 insertions(+), 10 deletions(-)
> 

-- 
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: 539 bytes --]

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

* Re: [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc()
  2014-12-04 13:12 [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Markus Armbruster
                   ` (3 preceding siblings ...)
  2014-12-05  4:57 ` [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Eric Blake
@ 2014-12-05  6:51 ` Fam Zheng
  2014-12-05 15:55 ` Paolo Bonzini
  5 siblings, 0 replies; 7+ messages in thread
From: Fam Zheng @ 2014-12-05  6:51 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: pbonzini, qemu-devel

On Thu, 12/04 14:12, Markus Armbruster wrote:
> Markus Armbruster (3):
>   scsi: Drop superfluous conditionals around g_free()
>   scsi: Fuse g_malloc(); memset() into  g_malloc0()
>   scsi: Use g_new() & friends where that makes obvious sense
> 
>  hw/scsi/lsi53c895a.c   | 2 +-
>  hw/scsi/megasas.c      | 6 ++----
>  hw/scsi/scsi-generic.c | 6 ++----
>  hw/scsi/virtio-scsi.c  | 2 +-
>  4 files changed, 6 insertions(+), 10 deletions(-)
> 
> -- 
> 1.9.3
> 
> 

Reviewed-by: Fam Zheng <famz@redhat.com>

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

* Re: [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc()
  2014-12-04 13:12 [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Markus Armbruster
                   ` (4 preceding siblings ...)
  2014-12-05  6:51 ` Fam Zheng
@ 2014-12-05 15:55 ` Paolo Bonzini
  5 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2014-12-05 15:55 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel



On 04/12/2014 14:12, Markus Armbruster wrote:
> Markus Armbruster (3):
>   scsi: Drop superfluous conditionals around g_free()
>   scsi: Fuse g_malloc(); memset() into  g_malloc0()
>   scsi: Use g_new() & friends where that makes obvious sense
> 
>  hw/scsi/lsi53c895a.c   | 2 +-
>  hw/scsi/megasas.c      | 6 ++----
>  hw/scsi/scsi-generic.c | 6 ++----
>  hw/scsi/virtio-scsi.c  | 2 +-
>  4 files changed, 6 insertions(+), 10 deletions(-)
> 

Applied, thanks.

Paolo

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

end of thread, other threads:[~2014-12-05 15:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-04 13:12 [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Markus Armbruster
2014-12-04 13:12 ` [Qemu-devel] [PATCH 1/3] scsi: Drop superfluous conditionals around g_free() Markus Armbruster
2014-12-04 13:12 ` [Qemu-devel] [PATCH 2/3] scsi: Fuse g_malloc(); memset() into g_malloc0() Markus Armbruster
2014-12-04 13:12 ` [Qemu-devel] [PATCH 3/3] scsi: Use g_new() & friends where that makes obvious sense Markus Armbruster
2014-12-05  4:57 ` [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc() Eric Blake
2014-12-05  6:51 ` Fam Zheng
2014-12-05 15:55 ` Paolo Bonzini

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).