From patchwork Tue Feb 16 14:17:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 8326681 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3A5459F6E7 for ; Tue, 16 Feb 2016 14:17:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F465201C0 for ; Tue, 16 Feb 2016 14:17:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFB842015A for ; Tue, 16 Feb 2016 14:17:50 +0000 (UTC) Received: from localhost ([::1]:46394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVgRp-00075d-PN for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Feb 2016 09:17:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVgRd-00075M-1x for qemu-devel@nongnu.org; Tue, 16 Feb 2016 09:17:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVgRX-0003H8-Tc for qemu-devel@nongnu.org; Tue, 16 Feb 2016 09:17:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40899) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVgRX-0003H3-Lk for qemu-devel@nongnu.org; Tue, 16 Feb 2016 09:17:31 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 0F2EFC001260; Tue, 16 Feb 2016 14:17:30 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1GEHQGQ029173; Tue, 16 Feb 2016 09:17:28 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id DACC881A6B; Tue, 16 Feb 2016 15:17:24 +0100 (CET) Message-ID: <1455632244.7504.102.camel@redhat.com> From: Gerd Hoffmann To: P J P Date: Tue, 16 Feb 2016 15:17:24 +0100 In-Reply-To: <1455617054-8481-1-git-send-email-ppandit@redhat.com> References: <1455617054-8481-1-git-send-email-ppandit@redhat.com> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Zuozhi Fzz , Qemu Developers , Prasad J Pandit Subject: Re: [Qemu-devel] [PATCH] usb: ohci avoid multiple eof timers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Di, 2016-02-16 at 15:34 +0530, P J P wrote: > When transitioning an OHCI controller to the OHCI_USB_OPERATIONAL > state, it creates an eof timer object in 'ohci_bus_start'. > It does not check if one already exists. This results in memory > leakage and null dereference issue. Add a check to avoid it. Well, allocating and deallocating the timer all the time isn't a great idea in the first place. Can you try the attached patch instead? thanks, Gerd From d1b07becc481e09225cfe905ec357807ae07f095 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Tue, 16 Feb 2016 15:15:04 +0100 Subject: [PATCH] ohci timer fix Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ohci.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index bed55dd..3d1270d 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1347,16 +1347,6 @@ static void ohci_frame_boundary(void *opaque) */ static int ohci_bus_start(OHCIState *ohci) { - ohci->eof_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, - ohci_frame_boundary, - ohci); - - if (ohci->eof_timer == NULL) { - trace_usb_ohci_bus_eof_timer_failed(ohci->name); - ohci_die(ohci); - return 0; - } - trace_usb_ohci_start(ohci->name); /* Delay the first SOF event by one frame time as @@ -1373,11 +1363,7 @@ static int ohci_bus_start(OHCIState *ohci) static void ohci_bus_stop(OHCIState *ohci) { trace_usb_ohci_stop(ohci->name); - if (ohci->eof_timer) { - timer_del(ohci->eof_timer); - timer_free(ohci->eof_timer); - } - ohci->eof_timer = NULL; + timer_del(ohci->eof_timer); } /* Sets a flag in a port status register but only set it if the port is @@ -1907,6 +1893,9 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, usb_packet_init(&ohci->usb_packet); ohci->async_td = 0; + + ohci->eof_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, + ohci_frame_boundary, ohci); } #define TYPE_PCI_OHCI "pci-ohci" @@ -2041,23 +2030,13 @@ static bool ohci_eof_timer_needed(void *opaque) { OHCIState *ohci = opaque; - return ohci->eof_timer != NULL; -} - -static int ohci_eof_timer_pre_load(void *opaque) -{ - OHCIState *ohci = opaque; - - ohci_bus_start(ohci); - - return 0; + return timer_pending(ohci->eof_timer); } static const VMStateDescription vmstate_ohci_eof_timer = { .name = "ohci-core/eof-timer", .version_id = 1, .minimum_version_id = 1, - .pre_load = ohci_eof_timer_pre_load, .needed = ohci_eof_timer_needed, .fields = (VMStateField[]) { VMSTATE_TIMER_PTR(eof_timer, OHCIState), -- 1.8.3.1