diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index 2a355971dc56..43124cf18039 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -649,6 +649,7 @@ static inline struct comp_buffer *comp_dev_get_first_data_producer(struct comp_d /** * Get a pointer to the next comp_buffer object providing data to the component * The function will return NULL if there're no more data providers + * _save version also checks if producer != NULL */ static inline struct comp_buffer *comp_dev_get_next_data_producer(struct comp_dev *component, struct comp_buffer *producer) @@ -657,6 +658,12 @@ static inline struct comp_buffer *comp_dev_get_next_data_producer(struct comp_de list_item(producer->sink_list.next, struct comp_buffer, sink_list); } +static inline struct comp_buffer *comp_dev_get_next_data_producer_safe(struct comp_dev *component, + struct comp_buffer *producer) +{ + return producer ? comp_dev_get_next_data_producer(component, producer) : NULL; +} + /** * Get a pointer to the first comp_buffer object receiving data from the component * The function will return NULL if there's no data consumers @@ -670,6 +677,7 @@ static inline struct comp_buffer *comp_dev_get_first_data_consumer(struct comp_d /** * Get a pointer to the next comp_buffer object receiving data from the component * The function will return NULL if there're no more data consumers + * _safe version also checks if consumer is != NULL */ static inline struct comp_buffer *comp_dev_get_next_data_consumer(struct comp_dev *component, struct comp_buffer *consumer) @@ -678,6 +686,12 @@ static inline struct comp_buffer *comp_dev_get_next_data_consumer(struct comp_de list_item(consumer->source_list.next, struct comp_buffer, source_list); } +static inline struct comp_buffer *comp_dev_get_next_data_consumer_safe(struct comp_dev *component, + struct comp_buffer *consumer) +{ + return consumer ? comp_dev_get_next_data_consumer(component, consumer : NULL; +} + /* * a macro for easy iteration through component's list of producers */ @@ -692,12 +706,12 @@ static inline struct comp_buffer *comp_dev_get_next_data_consumer(struct comp_de * * additional "safe storage" pointer to struct comp_buffer must be provided */ -#define comp_dev_for_each_producer_safe(_dev, _producer, _next_producer) \ - for (_producer = comp_dev_get_first_data_producer(_dev), \ - _next_producer = comp_dev_get_next_data_producer(_dev, _producer); \ - _producer != NULL; \ - _producer = _next_producer, \ - _next_producer = comp_dev_get_next_data_producer(_dev, _producer)) +#define comp_dev_for_each_producer_safe(_dev, _producer, _next_producer) \ + for (_producer = comp_dev_get_first_data_producer(_dev), \ + _next_producer = comp_dev_get_next_data_producer_safe(_dev, _producer); \ + _producer != NULL; \ + _producer = _next_producer, \ + _next_producer = comp_dev_get_next_data_producer_safe(_dev, _producer)) /* * a macro for easy iteration through component's list of consumers @@ -713,12 +727,12 @@ static inline struct comp_buffer *comp_dev_get_next_data_consumer(struct comp_de * * additional "safe storage" pointer to struct comp_buffer must be provided */ -#define comp_dev_for_each_consumer_safe(_dev, _consumer, _next_consumer) \ - for (_consumer = comp_dev_get_first_data_consumer(_dev), \ - _next_consumer = comp_dev_get_next_data_consumer(_dev, _consumer); \ - _consumer != NULL; \ - _consumer = _next_consumer, \ - _next_consumer = comp_dev_get_next_data_consumer(_dev, _consumer)) +#define comp_dev_for_each_consumer_safe(_dev, _consumer, _next_consumer) \ + for (_consumer = comp_dev_get_first_data_consumer(_dev), \ + _next_consumer = comp_dev_get_next_data_consumer_safe(_dev, _consumer); \ + _consumer != NULL; \ + _consumer = _next_consumer, \ + _next_consumer = comp_dev_get_next_data_consumer_safe(_dev, _consumer)) /** @}*/