aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2022-09-08 22:48:53 +0000
committerMark Johnston <markj@FreeBSD.org>2022-10-13 00:45:38 +0000
commit04a3462235c45c6c9adf6b9af6641601e220e40c (patch)
tree9e43aafc19c2bef9b4c935479645c834e1ea9f85
parent16d4c1de7b40f1cc0d323b9ecc5a38afb7a42f8a (diff)
downloadsrc-04a3462235c45c6c9adf6b9af6641601e220e40c.tar.gz
src-04a3462235c45c6c9adf6b9af6641601e220e40c.zip
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)
-rw-r--r--usr.sbin/bhyve/audio.c28
-rw-r--r--usr.sbin/bhyve/audio.h4
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_ */