]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress_ops: add magic and look for compress_plugin_mops symbol
authorJaroslav Kysela <perex@perex.cz>
Wed, 21 Jan 2026 10:31:55 +0000 (11:31 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 28 May 2026 14:34:09 +0000 (16:34 +0200)
We need more validation of passed ops structure to allow
further API changes in future.

This change looks for compress_plugin_mops symbol in the
dynamic plugin library to make sure that the new magic
and new get_tstamp64 members are handled correctly.

Closes: https://github.com/alsa-project/tinycompress/pull/31
Link: https://github.com/alsa-project/tinycompress/pull/29
Link: https://github.com/alsa-project/tinycompress/pull/30
Fixes: 0bd5530 ("compress_ops: add get_tstamp64")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/tinycompress/compress_ops.h
src/lib/compress.c
src/lib/compress_hw.c

index 290a8311a69e58f9a957be4b7e5ed1d0d2d75d08..e8166325456568fa69ce3efa52be02969244e558 100644 (file)
@@ -8,6 +8,8 @@
 #include "sound/compress_offload.h"
 #include "tinycompress.h"
 
+#define COMPRESS_OPS_V2                0xadcc0002      /* version 2 magic */
+
 /*
  * struct compress_ops:
  * ops structure containing ops corresponding to exposed
@@ -16,6 +18,7 @@
  * done in compress_hw.c
  */
 struct compress_ops {
+       unsigned int magic;     /* version of this structure */
        void *(*open_by_name)(const char *name,
                        unsigned int flags, struct compr_config *config);
        void (*close)(void *compress_data);
index cf0b29516df447b094349f85c11976f985d34456..1ff3dfeb11aa26244c149a208cecd4462779b27c 100644 (file)
@@ -58,6 +58,7 @@
 #include <dlfcn.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/errno.h>
 #include <sys/time.h>
 #include "tinycompress/tinycompress.h"
 #include "tinycompress/compress_ops.h"
@@ -136,7 +137,7 @@ static int populate_compress_plugin_ops(struct compress *compress, const char *n
                return ret;
        }
 
-       compress->ops = dlsym(dl_hdl, "compress_plugin_ops");
+       compress->ops = dlsym(dl_hdl, "compress_plugin_mops");
        err = dlerror();
        if (err) {
                fprintf(stderr, "%s: dlsym to ops failed, err = '%s'\n",
@@ -144,6 +145,12 @@ static int populate_compress_plugin_ops(struct compress *compress, const char *n
                dlclose(dl_hdl);
                return ret;
        }
+       if (compress->ops->magic != COMPRESS_OPS_V2) {
+               fprintf(stderr, "%s: dlsym to ops failed, bad magic (%08x)\n",
+                               __func__, compress->ops->magic);
+               dlclose(dl_hdl);
+               return -ENXIO;
+       }
        compress->dl_hdl = dl_hdl;
        return 0;
 }
index 52550ef219c649e76607dc4d338058538f56edec..f576d04115beb9d94a347b96bc67009eb081d7aa 100644 (file)
@@ -641,6 +641,7 @@ static int compress_hw_set_codec_params(void *data, struct snd_codec *codec)
 }
 
 struct compress_ops compress_hw_ops = {
+       .magic = COMPRESS_OPS_V2,
        .open_by_name = compress_hw_open_by_name,
        .close = compress_hw_close,
        .get_hpointer = compress_hw_get_hpointer,