From patchwork Fri Apr 8 15:12:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ingo Molnar X-Patchwork-Id: 694881 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p38FCk8F005358 for ; Fri, 8 Apr 2011 15:12:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756753Ab1DHPMm (ORCPT ); Fri, 8 Apr 2011 11:12:42 -0400 Received: from mx3.mail.elte.hu ([157.181.1.138]:41220 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752550Ab1DHPMm (ORCPT ); Fri, 8 Apr 2011 11:12:42 -0400 Received: from elvis.elte.hu ([157.181.1.14]) by mx3.mail.elte.hu with esmtp (Exim) id 1Q8DMW-0006Hu-Mi from ; Fri, 08 Apr 2011 17:12:40 +0200 Received: by elvis.elte.hu (Postfix, from userid 1004) id A7D683E250F; Fri, 8 Apr 2011 17:12:38 +0200 (CEST) Date: Fri, 8 Apr 2011 17:12:38 +0200 From: Ingo Molnar To: Pekka Enberg Cc: KVM devel mailing list Subject: [PATCH] kvm tools: Fix segfault when running 'kvm' without a disk image Message-ID: <20110408151238.GA13940@elte.hu> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) Received-SPF: neutral (mx3: 157.181.1.14 is neither permitted nor denied by domain of elte.hu) client-ip=157.181.1.14; envelope-from=mingo@elte.hu; helo=elvis.elte.hu; X-ELTE-SpamScore: -2.0 X-ELTE-SpamLevel: X-ELTE-SpamCheck: no X-ELTE-SpamVersion: ELTE 2.0 X-ELTE-SpamCheck-Details: score=-2.0 required=5.9 tests=BAYES_00 autolearn=no SpamAssassin version=3.3.1 -2.0 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 08 Apr 2011 15:12:46 +0000 (UTC) When running a simple, diskless 'kvm ./bzImage' KVM session we currently segfault at the end of the session: [ 4.895488] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) [ 4.899371] Rebooting in 1 seconds.. Program received signal SIGSEGV, Segmentation fault. disk_image__close (self=0x0) at disk-image.c:93 93 if (self->ops->close) (gdb) Because disk_image__close() assumes that 'self' is never NULL. Add a NULL check to allow a clean exit. Signed-off-by: Ingo Molnar --- tools/kvm/disk-image.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c index 80999c1..4099720 100644 --- a/tools/kvm/disk-image.c +++ b/tools/kvm/disk-image.c @@ -90,6 +90,10 @@ struct disk_image *disk_image__open(const char *filename) void disk_image__close(struct disk_image *self) { + /* If there was no disk image then there's nothing to do: */ + if (!self) + return; + if (self->ops->close) self->ops->close(self);