Skip to content

Commit 25c6206

Browse files
committed
comp_dev: Eliminate use of drvdata for module backpointer
The current SOF architecture splits a "module" across two structs, the legacy comp_dev and a newer struct processing_module. The latter contains a pointer to the former, but in many places existing code has needed a backpointer to recover the module from a component. So far this has abused the drvdata mechanism to store this as a void*, but that's fragile as many components are already (!) using drvdata for other purposes and will clobber the setting. The fact that it worked is seeming just by luck. That pointer is for the exclusive use of the comp_driver code associated with a component to store its own data. We can't be touching it from the global module code. Just give the pointer a properly-typed field of its own and make sure the two are initialized in tandem. Longer term, SOF really needs to fix this bifurcation and unify the two structs. Signed-off-by: Andy Ross <andyross@google.com>
1 parent de5bfbf commit 25c6206

25 files changed

Lines changed: 104 additions & 92 deletions

File tree

src/audio/asrc/asrc_ipc4.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int asrc_dai_configure_timestamp(struct comp_data *cd)
2727
if (!cd->dai_dev)
2828
return -ENODEV;
2929

30-
struct processing_module *mod = comp_get_drvdata(cd->dai_dev);
30+
struct processing_module *mod = comp_mod(cd->dai_dev);
3131
const struct module_interface *const ops = mod->dev->drv->adapter_ops;
3232

3333
return ops->endpoint_ops->dai_ts_config(cd->dai_dev);
@@ -38,7 +38,7 @@ int asrc_dai_start_timestamp(struct comp_data *cd)
3838
if (!cd->dai_dev)
3939
return -ENODEV;
4040

41-
struct processing_module *mod = comp_get_drvdata(cd->dai_dev);
41+
struct processing_module *mod = comp_mod(cd->dai_dev);
4242
const struct module_interface *const ops = mod->dev->drv->adapter_ops;
4343

4444
return ops->endpoint_ops->dai_ts_start(cd->dai_dev);
@@ -49,7 +49,7 @@ int asrc_dai_stop_timestamp(struct comp_data *cd)
4949
if (!cd->dai_dev)
5050
return -ENODEV;
5151

52-
struct processing_module *mod = comp_get_drvdata(cd->dai_dev);
52+
struct processing_module *mod = comp_mod(cd->dai_dev);
5353
const struct module_interface *const ops = mod->dev->drv->adapter_ops;
5454

5555
return ops->endpoint_ops->dai_ts_stop(cd->dai_dev);
@@ -64,7 +64,7 @@ int asrc_dai_get_timestamp(struct comp_data *cd, struct timestamp_data *tsd)
6464
if (!cd->dai_dev)
6565
return -ENODEV;
6666

67-
struct processing_module *mod = comp_get_drvdata(cd->dai_dev);
67+
struct processing_module *mod = comp_mod(cd->dai_dev);
6868
const struct module_interface *const ops = mod->dev->drv->adapter_ops;
6969

7070
return ops->endpoint_ops->dai_ts_get(cd->dai_dev, tsd);

src/audio/copier/copier.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static int copier_reset(struct processing_module *mod)
293293

294294
static int copier_comp_trigger(struct comp_dev *dev, int cmd)
295295
{
296-
struct processing_module *mod = comp_get_drvdata(dev);
296+
struct processing_module *mod = comp_mod(dev);
297297
struct copier_data *cd = module_get_private_data(mod);
298298
struct sof_ipc_stream_posn posn;
299299
struct comp_dev *dai_copier;
@@ -660,7 +660,7 @@ static int copier_set_sink_fmt(struct comp_dev *dev, const void *data,
660660
int max_data_size)
661661
{
662662
const struct ipc4_copier_config_set_sink_format *sink_fmt = data;
663-
struct processing_module *mod = comp_get_drvdata(dev);
663+
struct processing_module *mod = comp_mod(dev);
664664
struct copier_data *cd = module_get_private_data(mod);
665665
struct list_item *sink_list;
666666
struct comp_buffer *sink;
@@ -711,7 +711,7 @@ static int copier_set_sink_fmt(struct comp_dev *dev, const void *data,
711711

712712
static int set_attenuation(struct comp_dev *dev, uint32_t data_offset, const char *data)
713713
{
714-
struct processing_module *mod = comp_get_drvdata(dev);
714+
struct processing_module *mod = comp_mod(dev);
715715
struct copier_data *cd = module_get_private_data(mod);
716716
uint32_t attenuation;
717717
enum sof_ipc_frame valid_fmt, frame_fmt;
@@ -860,7 +860,7 @@ static int copier_get_configuration(struct processing_module *mod,
860860

861861
static uint64_t copier_get_processed_data(struct comp_dev *dev, uint32_t stream_no, bool input)
862862
{
863-
struct processing_module *mod = comp_get_drvdata(dev);
863+
struct processing_module *mod = comp_mod(dev);
864864
struct copier_data *cd = module_get_private_data(mod);
865865
uint64_t ret = 0;
866866
bool source;
@@ -905,7 +905,7 @@ static uint64_t copier_get_processed_data(struct comp_dev *dev, uint32_t stream_
905905

906906
static int copier_position(struct comp_dev *dev, struct sof_ipc_stream_posn *posn)
907907
{
908-
struct processing_module *mod = comp_get_drvdata(dev);
908+
struct processing_module *mod = comp_mod(dev);
909909
struct copier_data *cd = module_get_private_data(mod);
910910
int ret = 0;
911911

@@ -933,7 +933,7 @@ static int copier_position(struct comp_dev *dev, struct sof_ipc_stream_posn *pos
933933

934934
static int copier_dai_ts_config_op(struct comp_dev *dev)
935935
{
936-
struct processing_module *mod = comp_get_drvdata(dev);
936+
struct processing_module *mod = comp_mod(dev);
937937
struct copier_data *cd = module_get_private_data(mod);
938938
struct dai_data *dd = cd->dd[0];
939939

@@ -942,7 +942,7 @@ static int copier_dai_ts_config_op(struct comp_dev *dev)
942942

943943
static int copier_dai_ts_start_op(struct comp_dev *dev)
944944
{
945-
struct processing_module *mod = comp_get_drvdata(dev);
945+
struct processing_module *mod = comp_mod(dev);
946946
struct copier_data *cd = module_get_private_data(mod);
947947
struct dai_data *dd = cd->dd[0];
948948

@@ -957,7 +957,7 @@ static int copier_dai_ts_get_op(struct comp_dev *dev, struct dai_ts_data *tsd)
957957
static int copier_dai_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd)
958958
#endif
959959
{
960-
struct processing_module *mod = comp_get_drvdata(dev);
960+
struct processing_module *mod = comp_mod(dev);
961961
struct copier_data *cd = module_get_private_data(mod);
962962
struct dai_data *dd = cd->dd[0];
963963

@@ -968,7 +968,7 @@ static int copier_dai_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd
968968

969969
static int copier_dai_ts_stop_op(struct comp_dev *dev)
970970
{
971-
struct processing_module *mod = comp_get_drvdata(dev);
971+
struct processing_module *mod = comp_mod(dev);
972972
struct copier_data *cd = module_get_private_data(mod);
973973
struct dai_data *dd = cd->dd[0];
974974

@@ -980,7 +980,7 @@ static int copier_dai_ts_stop_op(struct comp_dev *dev)
980980
static int copier_get_hw_params(struct comp_dev *dev, struct sof_ipc_stream_params *params,
981981
int dir)
982982
{
983-
struct processing_module *mod = comp_get_drvdata(dev);
983+
struct processing_module *mod = comp_mod(dev);
984984
struct copier_data *cd = module_get_private_data(mod);
985985
struct dai_data *dd = cd->dd[0];
986986

src/audio/copier/copier_dai.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static int copier_set_alh_multi_gtw_channel_map(struct comp_dev *dev,
3535
const struct ipc4_copier_module_cfg *copier_cfg,
3636
int index)
3737
{
38-
struct processing_module *mod = comp_get_drvdata(dev);
38+
struct processing_module *mod = comp_mod(dev);
3939
struct copier_data *cd = module_get_private_data(mod);
4040
const struct sof_alh_configuration_blob *alh_blob;
4141
uint8_t chan_bitmask;
@@ -71,7 +71,7 @@ static int copier_alh_assign_dai_index(struct comp_dev *dev,
7171
int *dai_index,
7272
int *dai_count)
7373
{
74-
struct processing_module *mod = comp_get_drvdata(dev);
74+
struct processing_module *mod = comp_mod(dev);
7575
struct copier_data *cd = module_get_private_data(mod);
7676
const struct sof_alh_configuration_blob *alh_blob = gtw_cfg_data;
7777
uint8_t *dma_config;
@@ -162,7 +162,7 @@ static int copier_dai_init(struct comp_dev *dev,
162162
enum ipc4_gateway_type type,
163163
int index, int dai_count)
164164
{
165-
struct processing_module *mod = comp_get_drvdata(dev);
165+
struct processing_module *mod = comp_mod(dev);
166166
struct copier_data *cd = module_get_private_data(mod);
167167
struct dai_data *dd;
168168
int ret;
@@ -230,7 +230,7 @@ int copier_dai_create(struct comp_dev *dev, struct copier_data *cd,
230230
const struct ipc4_copier_module_cfg *copier,
231231
struct pipeline *pipeline)
232232
{
233-
struct processing_module *mod = comp_get_drvdata(dev);
233+
struct processing_module *mod = comp_mod(dev);
234234
struct comp_ipc_config *config = &dev->ipc_config;
235235
int dai_index[IPC4_ALH_MAX_NUMBER_OF_GTW];
236236
union ipc4_connector_node_id node_id;

src/audio/copier/copier_host.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void delete_from_fpi_sync_group(struct host_data *hd)
9494
/* Playback only */
9595
static int init_pipeline_reg(struct comp_dev *dev)
9696
{
97-
struct processing_module *mod = comp_get_drvdata(dev);
97+
struct processing_module *mod = comp_mod(dev);
9898
struct copier_data *cd = module_get_private_data(mod);
9999
struct ipc4_pipeline_registers pipe_reg;
100100
uint32_t gateway_id;
@@ -126,7 +126,7 @@ int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
126126
const struct ipc4_copier_module_cfg *copier_cfg,
127127
struct pipeline *pipeline)
128128
{
129-
struct processing_module *mod = comp_get_drvdata(dev);
129+
struct processing_module *mod = comp_mod(dev);
130130
struct comp_ipc_config *config = &dev->ipc_config;
131131
struct ipc_config_host ipc_host;
132132
struct host_data *hd;
@@ -244,7 +244,7 @@ void copier_host_free(struct copier_data *cd)
244244
*/
245245
void copier_host_dma_cb(struct comp_dev *dev, size_t bytes)
246246
{
247-
struct processing_module *mod = comp_get_drvdata(dev);
247+
struct processing_module *mod = comp_mod(dev);
248248
struct copier_data *cd = module_get_private_data(mod);
249249
int ret, frames;
250250

src/audio/eq_fir/eq_fir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int eq_fir_init_coef(struct comp_dev *dev, struct sof_eq_fir_config *conf
9696
/* Called from validate(), we shall find nch and assign it accordingly,
9797
* as the parameter is not valid
9898
*/
99-
struct processing_module *mod = comp_get_drvdata(dev);
99+
struct processing_module *mod = comp_mod(dev);
100100
struct comp_data *cd = module_get_private_data(mod);
101101

102102
nch = cd->nch;

src/audio/mixin_mixout/mixin_mixout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static int mixin_process(struct processing_module *mod,
318318
continue;
319319
}
320320

321-
mixout_mod = comp_get_drvdata(mixout);
321+
mixout_mod = comp_mod(mixout);
322322
active_mixouts[i] = mixout_mod;
323323
mixout_sink = mixout_mod->sinks[0];
324324

src/audio/module_adapter/module/generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int module_load_config(struct comp_dev *dev, const void *cfg, size_t size)
2626
{
2727
int ret;
2828
struct module_config *dst;
29-
struct processing_module *mod = comp_get_drvdata(dev);
29+
struct processing_module *mod = comp_mod(dev);
3030
struct module_data *md = &mod->priv;
3131

3232
comp_dbg(dev, "module_load_config() start");

0 commit comments

Comments
 (0)