All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] qemu-pr-helper: do not free reply when multipath_process_cmd() fails
@ 2026-10-27 20:07 Stefan Hajnoczi
  2026-10-28 12:17 ` Eric Blake
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hajnoczi @ 2026-10-27 20:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-block, Fam Zheng, Paolo Bonzini, Stefan Hajnoczi,
	Benjamin Marzinski, kwolf, eblake, berrange

Kevin Wolf pointed out that the multipath_process_cmd() documentation
only defines the value of reply on success. Don't touch it when the
function returns -1.

The libmpathcmd implementation as of c78cf64a9e8e does not set *reply to
NULL when its internal mpath_send_cmd() call fails, so I think Kevin's
interpretation is correct.

As it stands, there is no observable bug in the QEMU code though because
reply is initialized to NULL before calling multipath_process_cmd().
This patch is just a cleanup.

Cc: Benjamin Marzinski <bmarzins@redhat.com>
Cc: kwolf@redhat.com
Cc: eblake@redhat.com
Cc: berrange@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
v2:
- Use g_autofree instead of manual free(3) calls [Eric]
---
 scsi/qemu-pr-helper.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index 54d196a503f..1f97a5c4bfe 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -559,7 +559,7 @@ static char *get_dm_name(int fd, Error **errp)
 static bool multipathd_cmd(int fd, const char *cmd, Error **errp)
 {
     const unsigned int timeout_ms = 60000;
-    char *reply = NULL;
+    g_autofree char *reply = NULL;
     int last_errno;
     int ret;
 
@@ -568,11 +568,16 @@ static bool multipathd_cmd(int fd, const char *cmd, Error **errp)
     if (reply && strcmp(reply, "ok\n") != 0) {
         error_setg(errp, "mpath_process_cmd(%d, \"%s\") replied \"%s\"",
                    fd, cmd, reply);
-        free(reply);
         return false;
     }
-    free(reply);
     if (ret == -1) {
+        /*
+         * It should already be NULL but the mpath_process_cmd() documentation
+         * only defines it when the function returns success, so don't depend
+         * on its value when ret == -1.
+         */
+        reply = NULL;
+
         error_setg_errno(errp, last_errno,
                          "mpath_process_cmd(%d, \"%s\") failed",
                          fd, cmd);
-- 
2.56.0



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

* Re: [PATCH v2] qemu-pr-helper: do not free reply when multipath_process_cmd() fails
  2026-10-27 20:07 [PATCH v2] qemu-pr-helper: do not free reply when multipath_process_cmd() fails Stefan Hajnoczi
@ 2026-10-28 12:17 ` Eric Blake
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2026-10-28 12:17 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: qemu-devel, qemu-block, Fam Zheng, Paolo Bonzini,
	Benjamin Marzinski, kwolf, berrange

On Tue, Oct 27, 2026 at 04:07:57PM -0400, Stefan Hajnoczi wrote:
> Kevin Wolf pointed out that the multipath_process_cmd() documentation
> only defines the value of reply on success. Don't touch it when the
> function returns -1.
> 
> The libmpathcmd implementation as of c78cf64a9e8e does not set *reply to
> NULL when its internal mpath_send_cmd() call fails, so I think Kevin's
> interpretation is correct.
> 
> As it stands, there is no observable bug in the QEMU code though because
> reply is initialized to NULL before calling multipath_process_cmd().
> This patch is just a cleanup.
> 
> Cc: Benjamin Marzinski <bmarzins@redhat.com>
> Cc: kwolf@redhat.com
> Cc: eblake@redhat.com
> Cc: berrange@redhat.com
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> v2:
> - Use g_autofree instead of manual free(3) calls [Eric]

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

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

end of thread, other threads:[~2026-10-28 12:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 20:07 [PATCH v2] qemu-pr-helper: do not free reply when multipath_process_cmd() fails Stefan Hajnoczi
2026-10-28 12:17 ` Eric Blake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.