From nobody Thu Oct 13 00:51:22 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MnrYk602Yz4fVwN; Thu, 13 Oct 2022 00:51:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MnrYk5NS3z3FP4; Thu, 13 Oct 2022 00:51:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665622282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=r+/IrVyap1lgfusdR17VK3/8vDjZzTjw19AHE/nDJaQ=; b=XifqDPJyhmHkKRivnvS2yWYbcpGvG3zaADg4fAb9IcIwd2UH/q4oRbXcOmZAwF3N5j7nsv ZRvCXX2PVVge8XVfdan4+HpHueAvZcqzb9Gt6+9tVJZXsRuLtEnrB9akY3cEZIDG4TdScu nfCilgor+TslXvha8MiqFl9v8RFw8HYVFWWrpsCx7ryGS6X63tw3/EZM3HQRMSfsffumKP o9GK5+mPWN0aMNlwtyW+p6C+D8vqHQ/UKUDsu6XDxj51fozW+EFpYKRqB2vE48aMtF96Sj QKzrvJ1ahE75z0+GuiHD/OSXJsA/Zk+Yi2sThOa3VpoNY4yln5hdY9wmWGYBQA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MnrYk4VK7zFsJ; Thu, 13 Oct 2022 00:51:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29D0pMuX015104; Thu, 13 Oct 2022 00:51:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29D0pM8h015102; Thu, 13 Oct 2022 00:51:22 GMT (envelope-from git) Date: Thu, 13 Oct 2022 00:51:22 GMT Message-Id: <202210130051.29D0pM8h015102@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 04a3462235c4 - stable/13 - bhyve: Address compiler warnings in audio.c List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 04a3462235c45c6c9adf6b9af6641601e220e40c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665622282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=r+/IrVyap1lgfusdR17VK3/8vDjZzTjw19AHE/nDJaQ=; b=uP0WZXcIZUeuQ7BjD0SZPoCZoF9XPbSrYJKBkrLriKx5Iq747jJNcQCXHXoVT5rFRRT+2Z p9dxdwAhOrpl6q+U2C3mEr7fbz7DIjH34e3ZUUxT1frO90DETu6s60zgwNaEBK+5Ao5buK ayZDAQSn+SeJ4XYM6Nrc50HNdZwObxBqMqYSev+e3OujUVgX3O5paVPDqoj2N0QA1+zlDd tz/pX4aPr6SSnTMBkMxolM6IvFREI9Z61IlKGik2YynSFtEYW0yIS+HkxOrrz8lJNuRePI yE5J//0MOcYwIj4ujbFE3gYVgHNovAKbI+Fmyt++9IxaNtOBhO6xCtiNwvhj6A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665622282; a=rsa-sha256; cv=none; b=vHQG+earLgDlhhxANzD+jZYjGHIm6y5vSvvzVKWliTv3bUh96TseZfcskitSWfJ+2SU5Ds MLOqfkfX1KsEEZBNr+uD5aq6UnF1rgkGt3IhM+dxg/at+0HwyDl1t2TNiSP3tAZpFxWybx O0zd0sOC0tbW44iuMg+bxYxyultSI6z3gSFYVLeZpD8g9mO06AYCnd75GNdI5OAhkkvohF mAOCOfJJCZcbulAfWlJh96eX7NtHJkyrnDAlNqqG9HEkpRnW215NxX6goyLGLuBhIskIs4 i7jSg7cd7dfh6rv6/VBHwA82FmssXx5QaCVuz0nHVQlVqYsiJjDGvnQBgjg/GA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=04a3462235c45c6c9adf6b9af6641601e220e40c commit 04a3462235c45c6c9adf6b9af6641601e220e40c Author: Mark Johnston AuthorDate: 2022-09-08 22:48:53 +0000 Commit: Mark Johnston CommitDate: 2022-10-13 00:45:38 +0000 bhyve: Address compiler warnings in audio.c - Avoid arithmetic on void pointers. - Avoid a signed/unsigned comparison in loops which write or fill audio data buffers. Convert while loops to for loops while here. (cherry picked from commit ee83710bc492c0b2e7d66dd61f45fa657a14d169) --- usr.sbin/bhyve/audio.c | 28 ++++++++++++---------------- usr.sbin/bhyve/audio.h | 4 ++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/usr.sbin/bhyve/audio.c b/usr.sbin/bhyve/audio.c index ee6bdabc541c..165face5862c 100644 --- a/usr.sbin/bhyve/audio.c +++ b/usr.sbin/bhyve/audio.c @@ -221,10 +221,11 @@ audio_set_params(struct audio *aud, struct audio_params *params) * @count - the number of bytes in buffer */ int -audio_playback(struct audio *aud, const void *buf, size_t count) +audio_playback(struct audio *aud, const uint8_t *buf, size_t count) { - int audio_fd = -1; - ssize_t len = 0, total = 0; + ssize_t len; + size_t total; + int audio_fd; assert(aud); assert(aud->dir); @@ -233,16 +234,13 @@ audio_playback(struct audio *aud, const void *buf, size_t count) audio_fd = aud->fd; assert(audio_fd != -1); - total = 0; - while (total < count) { + for (total = 0; total < count; total += len) { len = write(audio_fd, buf + total, count - total); - if (len == -1) { + if (len < 0) { DPRINTF("Fail to write to fd: %d, errno: %d", audio_fd, errno); return -1; } - - total += len; } return 0; @@ -257,10 +255,11 @@ audio_playback(struct audio *aud, const void *buf, size_t count) * Returns -1 on error and 0 on success */ int -audio_record(struct audio *aud, void *buf, size_t count) +audio_record(struct audio *aud, uint8_t *buf, size_t count) { - int audio_fd = -1; - ssize_t len = 0, total = 0; + ssize_t len; + size_t total; + int audio_fd; assert(aud); assert(!aud->dir); @@ -269,16 +268,13 @@ audio_record(struct audio *aud, void *buf, size_t count) audio_fd = aud->fd; assert(audio_fd != -1); - total = 0; - while (total < count) { + for (total = 0; total < count; total += len) { len = read(audio_fd, buf + total, count - total); - if (len == -1) { + if (len < 0) { DPRINTF("Fail to write to fd: %d, errno: %d", audio_fd, errno); return -1; } - - total += len; } return 0; diff --git a/usr.sbin/bhyve/audio.h b/usr.sbin/bhyve/audio.h index 2b559a43e5df..f433fe29af72 100644 --- a/usr.sbin/bhyve/audio.h +++ b/usr.sbin/bhyve/audio.h @@ -73,7 +73,7 @@ int audio_set_params(struct audio *aud, struct audio_params *params); * @count - the number of bytes in buffer * Returns -1 on error and 0 on success */ -int audio_playback(struct audio *aud, const void *buf, size_t count); +int audio_playback(struct audio *aud, const uint8_t *buf, size_t count); /* * audio_record - records samples from the sound device using blocking @@ -83,6 +83,6 @@ int audio_playback(struct audio *aud, const void *buf, size_t count); * @count - the number of bytes to capture in buffer * Returns -1 on error and 0 on success */ -int audio_record(struct audio *aud, void *buf, size_t count); +int audio_record(struct audio *aud, uint8_t *buf, size_t count); #endif /* _AUDIO_EMUL_H_ */