From patchwork Thu Jan 14 13:46:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= X-Patchwork-Id: 567477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B1A7D1402DE for ; Fri, 15 Jan 2016 01:10:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=poaAoBxU; dkim-atps=neutral Received: from localhost ([::1]:42765 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJic1-0007cy-J7 for incoming@patchwork.ozlabs.org; Thu, 14 Jan 2016 09:10:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEq-00023E-AV for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJiEk-0003cx-W6 for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:56 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEk-0003cr-Qq for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:50 -0500 Received: by mail-wm0-x243.google.com with SMTP id l65so43664464wmf.3 for ; Thu, 14 Jan 2016 05:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=ceRcAgqXoWm+hhFLVQzFAaaONAxxBl32xxpggZpJc0Q=; b=poaAoBxUWbPHVekf18AOvm+pPDo22/Ync3BaEJNymaBvEio4VpGEUXVZBvewsdAXrS /CUPK75ix0rSbyezdeInXQiQ/lYZniuQiUbIsA3abq97Y9EntyneXmEjmVLFSkVNMD0j a381IrwipRXbawNK5RsyMtyUMLonK3NRMEU3e0PlsWg98Ukh6+GinTy1OBkU4jZsIdS1 vZjUCQjkc44HgNLY+XjowxAIImbRIaidlhMpexHLZL006vNq10p5t+emAxcixqdDEqvP lkJWS9Pk6Osjlg1ljhubIlYkJKbVV4PuDzoCbe3zVZHhmV/g90J2IevoO5+7piyA4z+y +oqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=ceRcAgqXoWm+hhFLVQzFAaaONAxxBl32xxpggZpJc0Q=; b=DG3CUMmQs/8GGozYXUiSEW3NjDkhxkcDY3IYv77d46Q6abWMPaslHczVnASHs2MH+C fXBhnQJIB53AjWs3pisMgkOClpgkMewMfEnjXtMefbzjWJNsCb/T65lXqz0+0C7IG/Qi j1MbKlgn1LEKiJjKRtvF1rznotnCQulEhn+b6oqYLduJnSNy3p6ICwfaTC7HOfjqsCnZ 85TmLGswQ6scn0LnQmAh/vCwQyrx1UDGlwyj3WkxB4z9lDGlKdzHqdnJbWzw7UTCLFNp GLRh72J25hEQyLHPQ3bLp9ztTX4G3kOE95bh8oK5jLoAvsP6VM37pvZD2iAUkIZnCVRa jVcA== X-Gm-Message-State: ALoCoQkDEzK4y1VfA7DbtZFFf2s48KoLRiucAmbYSnvxq3laGJYKEhIzEQQej8pfekJTKCudS9wEDi7484OU7+AA0z61TCMWuQ== X-Received: by 10.28.98.198 with SMTP id w189mr30604185wmb.39.1452779210313; Thu, 14 Jan 2016 05:46:50 -0800 (PST) Received: from nullptr.home.dirty-ice.org (188-143-126-18.pool.digikabel.hu. [188.143.126.18]) by smtp.gmail.com with ESMTPSA id 79sm7398061wmo.7.2016.01.14.05.46.49 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Jan 2016 05:46:49 -0800 (PST) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Date: Thu, 14 Jan 2016 14:46:04 +0100 Message-Id: <1b0dcbc711d476b87b11a03f655132291b0c5b6b.1452776884.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 51/51] usbaudio: change playback counters to 64 bit 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org With stereo playback, they need about 375 minutes of continuous audio playback to overflow, which is usually not a problem (as stopping and later resuming playback resets the counters). But with 7.1 audio, they only need about 95 minutes to overflow. After the overflow, the buf->prod % USBAUDIO_PACKET_SIZE(channels) assertion no longer holds true, which will result in overflowing the buffer. With 64 bit variables, it would take some 762000 years to overflow. Signed-off-by: Kővágó, Zoltán --- hw/usb/dev-audio.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c index 7f28996..63f3c4e 100644 --- a/hw/usb/dev-audio.c +++ b/hw/usb/dev-audio.c @@ -576,9 +576,9 @@ static const USBDesc desc_audio_multi = { struct streambuf { uint8_t *data; - uint32_t size; - uint32_t prod; - uint32_t cons; + size_t size; + uint64_t prod; + uint64_t cons; }; static void streambuf_init(struct streambuf *buf, uint32_t size, @@ -599,12 +599,14 @@ static void streambuf_fini(struct streambuf *buf) static int streambuf_put(struct streambuf *buf, USBPacket *p, uint32_t channels) { - uint32_t free = buf->size - (buf->prod - buf->cons); + uint64_t free = buf->size - (buf->prod - buf->cons); if (free < USBAUDIO_PACKET_SIZE(channels)) { return 0; } + /* can happen if prod overflows */ + assert(buf->prod % USBAUDIO_PACKET_SIZE(channels) == 0); usb_packet_copy(p, buf->data + (buf->prod % buf->size), USBAUDIO_PACKET_SIZE(channels)); buf->prod += USBAUDIO_PACKET_SIZE(channels); @@ -613,7 +615,7 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p, uint32_t channels) static uint8_t *streambuf_get(struct streambuf *buf, size_t *len) { - uint32_t used = buf->prod - buf->cons; + uint64_t used = buf->prod - buf->cons; uint8_t *data; if (!used) {