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 "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
* 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);
#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"
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",
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;
}
}
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,