From nobody Thu Sep 29 16:37:43 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 4MdfD76B7gz4dgjp; Thu, 29 Sep 2022 16:37:43 +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 4MdfD75GLtz43Cn; Thu, 29 Sep 2022 16:37:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664469463; 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=MrWiSLqyoxxQtb7xTqK7g9LtzPkOuui5aB7jGCBnnRA=; b=kE02Hsk6bI3+/pnwOcXmVel0CybY1u7+de0T7p26oSUOpM8YSTAI/VjPdNRVdMFyoNYLaL MdfODzCkBK+KD06iZ1t3LhH2dwWZMEq+mNnct8cBiGlQeEXvhH/Z61BeOwHNusirE/IVY4 UIx9/wPl/IVLhC4eJelPyQU2b94cggvIkl0pZp4S6OmEUDY+nAY2niAgHL00vnIEMdCXE/ 5jWycD5x+A1BYdTX+AgX2nf4niPiZzyUAt47eb2AmfgxgStFIxfLukPmVusCSmd44QRmP0 f/TVw602+xOAaCLZGXr+tQYyMUnFG6C9fzs7vaSgq4TZoVtGmP3BQZ8PJR6Nwg== 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 4MdfD741BHzsjX; Thu, 29 Sep 2022 16:37:43 +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 28TGbhqN090441; Thu, 29 Sep 2022 16:37:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28TGbhfS090440; Thu, 29 Sep 2022 16:37:43 GMT (envelope-from git) Date: Thu, 29 Sep 2022 16:37:43 GMT Message-Id: <202209291637.28TGbhfS090440@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: ee83710bc492 - main - 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/main X-Git-Reftype: branch X-Git-Commit: ee83710bc492c0b2e7d66dd61f45fa657a14d169 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664469463; 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=MrWiSLqyoxxQtb7xTqK7g9LtzPkOuui5aB7jGCBnnRA=; b=ZlHATqm3fuYzaLaHElbVSlpocH9306bSd29sAGnvWbGidTda+eR8WKhNUIN0vBaE+OBK0x gX/GigG/hNC12JPyObV2uLVWGzllYjO4CWyR2NGhZ2mkDX+Rogm1leAHdTuheA2M7N2xrw 2QnTRUmFluRJIIdejOThw1qPUWwKyFlnHJ0YFioRQhcpkNN/1BeCwwa6blCes8t5p1d740 bCanKmq1sGm9svR+G9fJfS38HQZmxNdYd2LQpan0nnxUYaKwYKfd4Lo5qb2CuWSS3dYtuT +ZXpE+oiWq9u/VXfwIf5D3NJdsyllZqjqENq0e6+gHUbiA9AKxrW9hUDX0tChA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664469463; a=rsa-sha256; cv=none; b=hDOJV4IybDXJNnOI91bPLwwgtwaGSCz06ORwJFjdBHy+3Yf/sOcx4ZycdpkOdQBYxki2dU Ed43RuUmq9ESD5zI7FRcRTfXiFgPoH21tlO00T1t/Bgb5AyZpYcNHJQ5h3b8hIjLkg2Row LM0TEFdthMSdy9NQTGG4tX/2rGCryJyd59zZR493L7PiZgoUikI58lwgaTsXXqymDxSK4V yBdg4x+anG8g8cJsofHed9clasvVhiaW5pWHno+LvyzjLwmrQZ30on/yM1dA5Vc9cYqqFO 2pjSW4OAEoPw+Oo5mhCEV48xzPSrX0vQqF9F4cSF4h2oWm9lpsNqi+AwPzVWkQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ee83710bc492c0b2e7d66dd61f45fa657a14d169 commit ee83710bc492c0b2e7d66dd61f45fa657a14d169 Author: Mark Johnston AuthorDate: 2022-09-08 22:48:53 +0000 Commit: Mark Johnston CommitDate: 2022-09-29 16:36:44 +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. MFC after: 2 weeks --- 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 88f4dc8709c4..143030b29ae7 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_ */