Skip to content

Commit 9f5f8cc

Browse files
committed
compress_ops: add magic and look for compress_plugin_mops symbol
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. Link: alsa-project#29 Link: alsa-project#30 Fixes: 0bd5530 ("compress_ops: add get_tstamp64") Signed-off-by: Jaroslav Kysela <perex@perex.cz>
1 parent 7e53d57 commit 9f5f8cc

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

include/tinycompress/compress_ops.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "sound/compress_offload.h"
99
#include "tinycompress.h"
1010

11+
#define COMPRESS_OPS_V2 0xadcc0002 /* version 2 magic */
12+
1113
/*
1214
* struct compress_ops:
1315
* ops structure containing ops corresponding to exposed
@@ -16,6 +18,7 @@
1618
* done in compress_hw.c
1719
*/
1820
struct compress_ops {
21+
unsigned int magic; /* version of this structure */
1922
void *(*open_by_name)(const char *name,
2023
unsigned int flags, struct compr_config *config);
2124
void (*close)(void *compress_data);

src/lib/compress.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <dlfcn.h>
5959
#include <stdio.h>
6060
#include <string.h>
61+
#include <sys/errno.h>
6162
#include <sys/time.h>
6263
#include "tinycompress/tinycompress.h"
6364
#include "tinycompress/compress_ops.h"
@@ -136,14 +137,20 @@ static int populate_compress_plugin_ops(struct compress *compress, const char *n
136137
return ret;
137138
}
138139

139-
compress->ops = dlsym(dl_hdl, "compress_plugin_ops");
140+
compress->ops = dlsym(dl_hdl, "compress_plugin_mops");
140141
err = dlerror();
141142
if (err) {
142143
fprintf(stderr, "%s: dlsym to ops failed, err = '%s'\n",
143144
__func__, err);
144145
dlclose(dl_hdl);
145146
return ret;
146147
}
148+
if (compress->ops->magic != COMPRESS_OPS_V2) {
149+
fprintf(stderr, "%s: dlsym to ops failed, bad magic (%08x)\n",
150+
__func__, compress->ops->magic);
151+
dlclose(dl_hdl);
152+
return -ENXIO;
153+
}
147154
compress->dl_hdl = dl_hdl;
148155
return 0;
149156
}

src/lib/compress_hw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ static int compress_hw_set_codec_params(void *data, struct snd_codec *codec)
641641
}
642642

643643
struct compress_ops compress_hw_ops = {
644+
.magic = COMPRESS_OPS_V2,
644645
.open_by_name = compress_hw_open_by_name,
645646
.close = compress_hw_close,
646647
.get_hpointer = compress_hw_get_hpointer,

0 commit comments

Comments
 (0)