From: Andrew Cooper Subject: [PATCH 20/32] hw/device-hotplug: fix test of drive_add() return Date: Wed, 22 Apr 2015 16:08:33 +0100 Message-ID: <1429715325-5027-20-git-send-email-andrew.cooper3@citrix.com> References: <1429715235-4759-1-git-send-email-andrew.cooper3@citrix.com> <1429715325-5027-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1429715325-5027-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel List-Id: xen-devel@lists.xenproject.org From: Kaifeng Zhu drive_opt_idx could be -1 in case error occurs inside drive_add, so the error check should be "if (drive_opt_idx < 0)" instead of original "if (!drive_opt_idx)". Signed-off-by: Kaifeng Zhu Coverity-ID: 1055574 Reviewed-by: Andrew Cooper --- hw/device-hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/device-hotplug.c b/hw/device-hotplug.c index 3bdc048..97d3529 100644 --- a/hw/device-hotplug.c +++ b/hw/device-hotplug.c @@ -34,7 +34,7 @@ int add_init_drive(const char *opts) int ret = -1; drive_opt_idx = drive_add(NULL, "%s", opts); - if (!drive_opt_idx) + if (drive_opt_idx < 0) return ret; drive_idx = drive_init(&drives_opt[drive_opt_idx], 0, current_machine); -- 1.7.10.4