mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-02-05 04:06:34 -05:00
ucm: simplify and fix the previous patch (geti)
Use macro to maintain only one code. The status may be 0 or 1 - handle
both values correctly.
Also, fix the possible memory leak in snd_use_case_geti() - string
str should be freed even when the error is returned.
Fixes: 436cd5b6 ("ucm: add existence checks to geti calls")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
436cd5b6d0
commit
c083417b72
1 changed files with 20 additions and 70 deletions
|
|
@ -2415,67 +2415,23 @@ int snd_use_case_get(snd_use_case_mgr_t *uc_mgr,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* \brief check device status and existance
|
* a helper macro to obtain status and existence
|
||||||
* \param uc_mgr Use case manager
|
|
||||||
* \param str device identifier
|
|
||||||
* \param value Value pointer
|
|
||||||
* \return Zero if success, otherwise a negative error code
|
|
||||||
*/
|
*/
|
||||||
static long check_device(snd_use_case_mgr_t *uc_mgr,
|
#define geti(uc_mgr, status, ifind, str, value) ({ \
|
||||||
const char *str,
|
long val = -EINVAL; \
|
||||||
long *value)
|
if (str) { \
|
||||||
{
|
val = (status)((uc_mgr), (str)); \
|
||||||
struct use_case_device *dev;
|
if (val >= 0) { \
|
||||||
int err;
|
if ((ifind)((uc_mgr), (uc_mgr)->active_verb, (str), 0)) { \
|
||||||
|
*(value) = val; \
|
||||||
if (!str) {
|
} else { \
|
||||||
return -EINVAL;
|
val = -ENOENT; \
|
||||||
}
|
} \
|
||||||
err = device_status(uc_mgr, str);
|
} \
|
||||||
if (err > 0) {
|
} \
|
||||||
*value = err;
|
; val; /* return value */ \
|
||||||
err = 0;
|
})
|
||||||
} else if (err < 0) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
dev = find_device(uc_mgr, uc_mgr->active_verb, str, 0);
|
|
||||||
if (!dev) {
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief check modifier status and existance
|
|
||||||
* \param uc_mgr Use case manager
|
|
||||||
* \param str modifier identifier
|
|
||||||
* \param value Value pointer
|
|
||||||
* \return Zero if success, otherwise a negative error code
|
|
||||||
*/
|
|
||||||
static long check_modifier(snd_use_case_mgr_t *uc_mgr,
|
|
||||||
const char *str,
|
|
||||||
long *value)
|
|
||||||
{
|
|
||||||
struct use_case_modifier *mod;
|
|
||||||
long err;
|
|
||||||
|
|
||||||
if (!str) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
err = modifier_status(uc_mgr, str);
|
|
||||||
if (err > 0) {
|
|
||||||
*value = err;
|
|
||||||
return 0;
|
|
||||||
} else if (err < 0) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
mod = find_modifier(uc_mgr, uc_mgr->active_verb, str, 0);
|
|
||||||
if (!mod) {
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Get current - integer
|
* \brief Get current - integer
|
||||||
|
|
@ -2488,7 +2444,7 @@ int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr,
|
||||||
long *value)
|
long *value)
|
||||||
{
|
{
|
||||||
char *str, *str1;
|
char *str, *str1;
|
||||||
long err;
|
int err;
|
||||||
|
|
||||||
pthread_mutex_lock(&uc_mgr->mutex);
|
pthread_mutex_lock(&uc_mgr->mutex);
|
||||||
if (0) {
|
if (0) {
|
||||||
|
|
@ -2505,21 +2461,15 @@ int snd_use_case_geti(snd_use_case_mgr_t *uc_mgr,
|
||||||
str = NULL;
|
str = NULL;
|
||||||
}
|
}
|
||||||
if (check_identifier(identifier, "_devstatus")) {
|
if (check_identifier(identifier, "_devstatus")) {
|
||||||
err = check_device(uc_mgr, str, value);
|
err = geti(uc_mgr, device_status, find_device, str, value);
|
||||||
if (err < 0) {
|
|
||||||
goto __end;
|
|
||||||
}
|
|
||||||
} else if (check_identifier(identifier, "_modstatus")) {
|
} else if (check_identifier(identifier, "_modstatus")) {
|
||||||
err = check_modifier(uc_mgr, str, value);
|
err = geti(uc_mgr, modifier_status, find_modifier, str, value);
|
||||||
if (err < 0) {
|
|
||||||
goto __end;
|
|
||||||
}
|
|
||||||
#if 0
|
#if 0
|
||||||
/*
|
/*
|
||||||
* enable this block if the else clause below is expanded to query
|
* enable this block if the else clause below is expanded to query
|
||||||
* user-supplied values
|
* user-supplied values
|
||||||
*/
|
*/
|
||||||
} else if (identifier[0] == '_')
|
} else if (identifier[0] == '_') {
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
#endif
|
#endif
|
||||||
} else
|
} else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue