mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-04-11 08:21:07 -04:00
spa: alsa: fix some coverity warnings
NULL checks. Change pa_x* malloc functions act like the pulseaudio ones: assert on failure, as code assumes that.
This commit is contained in:
parent
7f2bdab8ea
commit
3539374ba7
4 changed files with 30 additions and 15 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <spa/utils/string.h>
|
#include <spa/utils/string.h>
|
||||||
#include <spa/utils/json.h>
|
#include <spa/utils/json.h>
|
||||||
|
#include <spa/utils/cleanup.h>
|
||||||
#include <spa/param/audio/iec958-types.h>
|
#include <spa/param/audio/iec958-types.h>
|
||||||
|
|
||||||
int _acp_log_level = 1;
|
int _acp_log_level = 1;
|
||||||
|
|
@ -372,7 +373,7 @@ static int add_pro_profile(pa_card *impl, uint32_t index)
|
||||||
|
|
||||||
dev = -1;
|
dev = -1;
|
||||||
while (1) {
|
while (1) {
|
||||||
char desc[128], devstr[128], *name;
|
char desc[128], devstr[128];
|
||||||
|
|
||||||
if ((err = snd_ctl_pcm_next_device(ctl_hndl, &dev)) < 0) {
|
if ((err = snd_ctl_pcm_next_device(ctl_hndl, &dev)) < 0) {
|
||||||
pa_log_error("error iterating devices: %s", snd_strerror(err));
|
pa_log_error("error iterating devices: %s", snd_strerror(err));
|
||||||
|
|
@ -396,8 +397,13 @@ static int add_pro_profile(pa_card *impl, uint32_t index)
|
||||||
pa_log_error("error pcm info: %s", snd_strerror(err));
|
pa_log_error("error pcm info: %s", snd_strerror(err));
|
||||||
}
|
}
|
||||||
if (err >= 0) {
|
if (err >= 0) {
|
||||||
|
spa_autofree char *name = NULL;
|
||||||
pa_assert_se(asprintf(&name, "Mapping pro-output-%d", dev) >= 0);
|
pa_assert_se(asprintf(&name, "Mapping pro-output-%d", dev) >= 0);
|
||||||
m = pa_alsa_mapping_get(ps, name);
|
m = pa_alsa_mapping_get(ps, name);
|
||||||
|
} else {
|
||||||
|
m = NULL;
|
||||||
|
}
|
||||||
|
if (m) {
|
||||||
m->description = pa_xstrdup(desc);
|
m->description = pa_xstrdup(desc);
|
||||||
m->device_strings = pa_split_spaces_strv(devstr);
|
m->device_strings = pa_split_spaces_strv(devstr);
|
||||||
|
|
||||||
|
|
@ -419,7 +425,6 @@ static int add_pro_profile(pa_card *impl, uint32_t index)
|
||||||
n_playback++;
|
n_playback++;
|
||||||
}
|
}
|
||||||
pa_idxset_put(ap->output_mappings, m, NULL);
|
pa_idxset_put(ap->output_mappings, m, NULL);
|
||||||
free(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE);
|
snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE);
|
||||||
|
|
@ -428,8 +433,13 @@ static int add_pro_profile(pa_card *impl, uint32_t index)
|
||||||
pa_log_error("error pcm info: %s", snd_strerror(err));
|
pa_log_error("error pcm info: %s", snd_strerror(err));
|
||||||
}
|
}
|
||||||
if (err >= 0) {
|
if (err >= 0) {
|
||||||
|
spa_autofree char *name = NULL;
|
||||||
pa_assert_se(asprintf(&name, "Mapping pro-input-%d", dev) >= 0);
|
pa_assert_se(asprintf(&name, "Mapping pro-input-%d", dev) >= 0);
|
||||||
m = pa_alsa_mapping_get(ps, name);
|
m = pa_alsa_mapping_get(ps, name);
|
||||||
|
} else {
|
||||||
|
m = NULL;
|
||||||
|
}
|
||||||
|
if (m) {
|
||||||
m->description = pa_xstrdup(desc);
|
m->description = pa_xstrdup(desc);
|
||||||
m->device_strings = pa_split_spaces_strv(devstr);
|
m->device_strings = pa_split_spaces_strv(devstr);
|
||||||
|
|
||||||
|
|
@ -451,7 +461,6 @@ static int add_pro_profile(pa_card *impl, uint32_t index)
|
||||||
n_capture++;
|
n_capture++;
|
||||||
}
|
}
|
||||||
pa_idxset_put(ap->input_mappings, m, NULL);
|
pa_idxset_put(ap->input_mappings, m, NULL);
|
||||||
free(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snd_ctl_close(ctl_hndl);
|
snd_ctl_close(ctl_hndl);
|
||||||
|
|
@ -1190,7 +1199,7 @@ uint32_t acp_card_find_best_profile_index(struct acp_card *card, const char *nam
|
||||||
|
|
||||||
static void find_mixer(pa_card *impl, pa_alsa_device *dev, const char *element, bool ignore_dB)
|
static void find_mixer(pa_card *impl, pa_alsa_device *dev, const char *element, bool ignore_dB)
|
||||||
{
|
{
|
||||||
const char *mdev;
|
const char *mdev = NULL;
|
||||||
pa_alsa_mapping *mapping = dev->mapping;
|
pa_alsa_mapping *mapping = dev->mapping;
|
||||||
|
|
||||||
if (!mapping && !element)
|
if (!mapping && !element)
|
||||||
|
|
@ -1199,7 +1208,8 @@ static void find_mixer(pa_card *impl, pa_alsa_device *dev, const char *element,
|
||||||
if (!element && mapping && pa_alsa_path_set_is_empty(dev->mixer_path_set))
|
if (!element && mapping && pa_alsa_path_set_is_empty(dev->mixer_path_set))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mdev = pa_proplist_gets(mapping->proplist, "alsa.mixer_device");
|
if (mapping)
|
||||||
|
mdev = pa_proplist_gets(mapping->proplist, "alsa.mixer_device");
|
||||||
if (mdev) {
|
if (mdev) {
|
||||||
dev->mixer_handle = pa_alsa_open_mixer_by_name(impl->ucm.mixers, mdev, true);
|
dev->mixer_handle = pa_alsa_open_mixer_by_name(impl->ucm.mixers, mdev, true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1741,7 +1741,7 @@ int pa_alsa_ucm_set_profile(pa_alsa_ucm_config *ucm, pa_card *card, pa_alsa_prof
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (ucm->active_verb) {
|
} else if (ucm->active_verb && old_profile) {
|
||||||
/* Disable modifiers not in new profile. Has to be done before
|
/* Disable modifiers not in new profile. Has to be done before
|
||||||
* devices, because _dismod fails if a modifier's supported
|
* devices, because _dismod fails if a modifier's supported
|
||||||
* devices are disabled. */
|
* devices are disabled. */
|
||||||
|
|
|
||||||
|
|
@ -327,18 +327,23 @@ static inline size_t pa_snprintf(char *str, size_t size, const char *format, ...
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define pa_xstrdup(s) ((s) != NULL ? strdup(s) : NULL)
|
#define pa_xnullcheck(p) ({ void *_mem_alloc = (p); spa_assert_se(_mem_alloc); _mem_alloc; })
|
||||||
#define pa_xstrndup(s,n) ((s) != NULL ? strndup(s,n) : NULL)
|
#define pa_xstrdup(s) ((s) != NULL ? pa_xnullcheck(strdup(s)) : NULL)
|
||||||
|
#define pa_xstrndup(s,n) ((s) != NULL ? pa_xnullcheck(strndup(s,n)) : NULL)
|
||||||
#define pa_xfree free
|
#define pa_xfree free
|
||||||
#define pa_xmalloc malloc
|
#define pa_xmalloc(n) pa_xnullcheck(malloc(n))
|
||||||
#define pa_xnew0(t,n) calloc(n, sizeof(t))
|
#define pa_xnew0(t,n) pa_xnullcheck(calloc((n), sizeof(t)))
|
||||||
#define pa_xnew(t,n) pa_xnew0(t,n)
|
#define pa_xnew(t,n) pa_xnew0(t,n)
|
||||||
#define pa_xrealloc realloc
|
#define pa_xrenew(t,p,n) ((t*) pa_xnullcheck(realloc(p, (n)*sizeof(t))))
|
||||||
#define pa_xrenew(t,p,n) ((t*) realloc(p, (n)*sizeof(t)))
|
|
||||||
|
|
||||||
static inline void* pa_xmemdup(const void *p, size_t l) {
|
static inline void* pa_xmemdup(const void *p, size_t l) {
|
||||||
return memcpy(malloc(l), p, l);
|
if (!p) {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
void *dst = pa_xmalloc(l);
|
||||||
|
memcpy(dst, p, l);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#define pa_xnewdup(t,p,n) ((t*) pa_xmemdup((p), (n)*sizeof(t)))
|
#define pa_xnewdup(t,p,n) ((t*) pa_xmemdup((p), (n)*sizeof(t)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -968,7 +968,7 @@ int spa_alsa_init(struct state *state, const struct spa_dict *info)
|
||||||
|
|
||||||
snd_config_update_free_global();
|
snd_config_update_free_global();
|
||||||
|
|
||||||
if ((str = spa_dict_lookup(info, "device.profile.pro")) != NULL)
|
if (info && (str = spa_dict_lookup(info, "device.profile.pro")) != NULL)
|
||||||
state->is_pro = spa_atob(str);
|
state->is_pro = spa_atob(str);
|
||||||
|
|
||||||
state->multi_rate = true;
|
state->multi_rate = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue