]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress_hw: cache ioctl version
authorGeorge Verhaegen <verhaegen@google.com>
Fri, 1 Aug 2025 10:47:43 +0000 (11:47 +0100)
committerVinod Koul <3178504+vinodkoul@users.noreply.github.com>
Wed, 21 Jan 2026 06:29:57 +0000 (11:59 +0530)
Read the version when opened and cache it to reduce ioctl calls.

src/lib/compress_hw.c

index 277363948c6c1b0f8002ad72474395469be5eab6..a07fa8dadf56cc05ed20c7e44320779f1b99ac1d 100644 (file)
@@ -36,6 +36,7 @@ struct compress_hw_data {
        int fd;
        unsigned int flags;
        char error[COMPR_ERR_MAX];
+       int ioctl_version;
        struct compr_config *config;
        int running;
        int max_poll_wait_ms;
@@ -88,13 +89,7 @@ static int is_compress_hw_ready(void *data)
 
 static int get_compress_hw_version(struct compress_hw_data *compress)
 {
-       int version = 0;
-
-       if (ioctl(compress->fd, SNDRV_COMPRESS_IOCTL_VERSION, &version)) {
-               oops(compress, errno, "cant read version");
-               return -1;
-       }
-       return version;
+       return compress->ioctl_version;
 }
 
 static bool _is_codec_type_supported(int fd, struct snd_codec *codec)
@@ -178,6 +173,11 @@ static void *compress_hw_open_by_name(const char *name,
                goto config_fail;
        }
 
+       if (ioctl(compress->fd, SNDRV_COMPRESS_IOCTL_VERSION, &compress->ioctl_version)) {
+               oops(&bad_compress, errno, "cannot read version");
+               goto codec_fail;
+       }
+
        if (ioctl(compress->fd, SNDRV_COMPRESS_GET_CAPS, &caps)) {
                oops(compress, errno, "cannot get device caps");
                goto codec_fail;