mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
add snd_strlcpy() and use it everywhere
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
639d404df6
commit
1755df1d9e
14 changed files with 74 additions and 61 deletions
|
|
@ -236,6 +236,7 @@ int safe_strtol(const char *str, long *val);
|
||||||
|
|
||||||
int snd_send_fd(int sock, void *data, size_t len, int fd);
|
int snd_send_fd(int sock, void *data, size_t len, int fd);
|
||||||
int snd_receive_fd(int sock, void *data, size_t len, int *fd);
|
int snd_receive_fd(int sock, void *data, size_t len, int *fd);
|
||||||
|
size_t snd_strlcpy(char *dst, const char *src, size_t size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* error messages
|
* error messages
|
||||||
|
|
|
||||||
|
|
@ -1805,7 +1805,7 @@ void snd_ctl_elem_id_set_subdevice(snd_ctl_elem_id_t *obj, unsigned int val)
|
||||||
void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t *obj, const char *val)
|
void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t *obj, const char *val)
|
||||||
{
|
{
|
||||||
assert(obj);
|
assert(obj);
|
||||||
strncpy((char *)obj->name, val, sizeof(obj->name));
|
snd_strlcpy((char *)obj->name, val, sizeof(obj->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2723,7 +2723,7 @@ void snd_ctl_elem_info_set_subdevice(snd_ctl_elem_info_t *obj, unsigned int val)
|
||||||
void snd_ctl_elem_info_set_name(snd_ctl_elem_info_t *obj, const char *val)
|
void snd_ctl_elem_info_set_name(snd_ctl_elem_info_t *obj, const char *val)
|
||||||
{
|
{
|
||||||
assert(obj);
|
assert(obj);
|
||||||
strncpy((char *)obj->id.name, val, sizeof(obj->id.name));
|
snd_strlcpy((char *)obj->id.name, val, sizeof(obj->id.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2945,7 +2945,7 @@ void snd_ctl_elem_value_set_subdevice(snd_ctl_elem_value_t *obj, unsigned int va
|
||||||
void snd_ctl_elem_value_set_name(snd_ctl_elem_value_t *obj, const char *val)
|
void snd_ctl_elem_value_set_name(snd_ctl_elem_value_t *obj, const char *val)
|
||||||
{
|
{
|
||||||
assert(obj);
|
assert(obj);
|
||||||
strncpy((char *)obj->id.name, val, sizeof(obj->id.name));
|
snd_strlcpy((char *)obj->id.name, val, sizeof(obj->id.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
22
src/error.c
22
src/error.c
|
|
@ -177,3 +177,25 @@ static void snd_err_msg_default(const char *file, int line, const char *function
|
||||||
snd_lib_error_handler_t snd_err_msg = snd_err_msg_default;
|
snd_lib_error_handler_t snd_err_msg = snd_err_msg_default;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Copy a C-string into a sized buffer
|
||||||
|
* \param dst Where to copy the string to
|
||||||
|
* \param src Where to copy the string from
|
||||||
|
* \param size Size of destination buffer
|
||||||
|
* \retval The source string length
|
||||||
|
*
|
||||||
|
* The result is always a valid NUL-terminated string that fits
|
||||||
|
* in the buffer (unless, of course, the buffer size is zero).
|
||||||
|
* It does not pad out the result like strncpy() does.
|
||||||
|
*/
|
||||||
|
size_t snd_strlcpy(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t ret = strlen(src);
|
||||||
|
if (size) {
|
||||||
|
size_t len = ret >= size ? size - 1 : ret;
|
||||||
|
memcpy(dst, src, len);
|
||||||
|
dst[len] = '\0';
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -766,9 +766,9 @@ int snd_pcm_direct_info(snd_pcm_t *pcm, snd_pcm_info_t * info)
|
||||||
info->card = -1;
|
info->card = -1;
|
||||||
/* FIXME: fill this with something more useful: we know the hardware name */
|
/* FIXME: fill this with something more useful: we know the hardware name */
|
||||||
if (pcm->name) {
|
if (pcm->name) {
|
||||||
strncpy((char *)info->id, pcm->name, sizeof(info->id));
|
snd_strlcpy((char *)info->id, pcm->name, sizeof(info->id));
|
||||||
strncpy((char *)info->name, pcm->name, sizeof(info->name));
|
snd_strlcpy((char *)info->name, pcm->name, sizeof(info->name));
|
||||||
strncpy((char *)info->subname, pcm->name, sizeof(info->subname));
|
snd_strlcpy((char *)info->subname, pcm->name, sizeof(info->subname));
|
||||||
}
|
}
|
||||||
info->subdevices_count = 1;
|
info->subdevices_count = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,9 @@ static int snd_pcm_ioplug_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
|
||||||
info->stream = pcm->stream;
|
info->stream = pcm->stream;
|
||||||
info->card = -1;
|
info->card = -1;
|
||||||
if (pcm->name) {
|
if (pcm->name) {
|
||||||
strncpy((char *)info->id, pcm->name, sizeof(info->id));
|
snd_strlcpy((char *)info->id, pcm->name, sizeof(info->id));
|
||||||
strncpy((char *)info->name, pcm->name, sizeof(info->name));
|
snd_strlcpy((char *)info->name, pcm->name, sizeof(info->name));
|
||||||
strncpy((char *)info->subname, pcm->name, sizeof(info->subname));
|
snd_strlcpy((char *)info->subname, pcm->name, sizeof(info->subname));
|
||||||
}
|
}
|
||||||
info->subdevices_count = 1;
|
info->subdevices_count = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,9 @@ static int snd_pcm_null_info(snd_pcm_t *pcm, snd_pcm_info_t * info)
|
||||||
info->stream = pcm->stream;
|
info->stream = pcm->stream;
|
||||||
info->card = -1;
|
info->card = -1;
|
||||||
if (pcm->name) {
|
if (pcm->name) {
|
||||||
strncpy((char *)info->id, pcm->name, sizeof(info->id));
|
snd_strlcpy((char *)info->id, pcm->name, sizeof(info->id));
|
||||||
strncpy((char *)info->name, pcm->name, sizeof(info->name));
|
snd_strlcpy((char *)info->name, pcm->name, sizeof(info->name));
|
||||||
strncpy((char *)info->subname, pcm->name, sizeof(info->subname));
|
snd_strlcpy((char *)info->subname, pcm->name, sizeof(info->subname));
|
||||||
}
|
}
|
||||||
info->subdevices_count = 1;
|
info->subdevices_count = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -1744,7 +1744,7 @@ void snd_seq_client_info_set_client(snd_seq_client_info_t *info, int client)
|
||||||
void snd_seq_client_info_set_name(snd_seq_client_info_t *info, const char *name)
|
void snd_seq_client_info_set_name(snd_seq_client_info_t *info, const char *name)
|
||||||
{
|
{
|
||||||
assert(info && name);
|
assert(info && name);
|
||||||
strncpy(info->name, name, sizeof(info->name));
|
snd_strlcpy(info->name, name, sizeof(info->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2177,7 +2177,7 @@ void snd_seq_port_info_set_addr(snd_seq_port_info_t *info, const snd_seq_addr_t
|
||||||
void snd_seq_port_info_set_name(snd_seq_port_info_t *info, const char *name)
|
void snd_seq_port_info_set_name(snd_seq_port_info_t *info, const char *name)
|
||||||
{
|
{
|
||||||
assert(info && name);
|
assert(info && name);
|
||||||
strncpy(info->name, name, sizeof(info->name));
|
snd_strlcpy(info->name, name, sizeof(info->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -3122,7 +3122,7 @@ unsigned int snd_seq_queue_info_get_flags(const snd_seq_queue_info_t *info)
|
||||||
void snd_seq_queue_info_set_name(snd_seq_queue_info_t *info, const char *name)
|
void snd_seq_queue_info_set_name(snd_seq_queue_info_t *info, const char *name)
|
||||||
{
|
{
|
||||||
assert(info && name);
|
assert(info && name);
|
||||||
strncpy(info->name, name, sizeof(info->name));
|
snd_strlcpy(info->name, name, sizeof(info->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -3198,7 +3198,7 @@ int snd_seq_alloc_named_queue(snd_seq_t *seq, const char *name)
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
info.locked = 1;
|
info.locked = 1;
|
||||||
if (name)
|
if (name)
|
||||||
strncpy(info.name, name, sizeof(info.name) - 1);
|
snd_strlcpy(info.name, name, sizeof(info.name));
|
||||||
return snd_seq_create_queue(seq, &info);
|
return snd_seq_create_queue(seq, &info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3279,7 +3279,7 @@ int snd_seq_query_named_queue(snd_seq_t *seq, const char *name)
|
||||||
int err;
|
int err;
|
||||||
snd_seq_queue_info_t info;
|
snd_seq_queue_info_t info;
|
||||||
assert(seq && name);
|
assert(seq && name);
|
||||||
strncpy(info.name, name, sizeof(info.name));
|
snd_strlcpy(info.name, name, sizeof(info.name));
|
||||||
err = seq->ops->get_named_queue(seq, &info);
|
err = seq->ops->get_named_queue(seq, &info);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
|
||||||
|
|
@ -380,7 +380,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg,
|
||||||
|
|
||||||
be = elem->bytes_ext;
|
be = elem->bytes_ext;
|
||||||
be->size = elem->size;
|
be->size = elem->size;
|
||||||
elem_copy_text(be->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(be->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
be->hdr.type = SND_SOC_TPLG_TYPE_BYTES;
|
be->hdr.type = SND_SOC_TPLG_TYPE_BYTES;
|
||||||
|
|
||||||
tplg_dbg(" Control Bytes: %s\n", elem->id);
|
tplg_dbg(" Control Bytes: %s\n", elem->id);
|
||||||
|
|
@ -505,7 +505,7 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ec = elem->enum_ctrl;
|
ec = elem->enum_ctrl;
|
||||||
elem_copy_text(ec->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(ec->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
ec->hdr.type = SND_SOC_TPLG_TYPE_ENUM;
|
ec->hdr.type = SND_SOC_TPLG_TYPE_ENUM;
|
||||||
ec->size = elem->size;
|
ec->size = elem->size;
|
||||||
tplg->channel_idx = 0;
|
tplg->channel_idx = 0;
|
||||||
|
|
@ -606,7 +606,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg,
|
||||||
|
|
||||||
/* init new mixer */
|
/* init new mixer */
|
||||||
mc = elem->mixer_ctrl;
|
mc = elem->mixer_ctrl;
|
||||||
elem_copy_text(mc->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(mc->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
mc->hdr.type = SND_SOC_TPLG_TYPE_MIXER;
|
mc->hdr.type = SND_SOC_TPLG_TYPE_MIXER;
|
||||||
mc->size = elem->size;
|
mc->size = elem->size;
|
||||||
tplg->channel_idx = 0;
|
tplg->channel_idx = 0;
|
||||||
|
|
@ -721,8 +721,7 @@ static int init_ctl_hdr(struct snd_soc_tplg_ctl_hdr *hdr,
|
||||||
hdr->size = sizeof(struct snd_soc_tplg_ctl_hdr);
|
hdr->size = sizeof(struct snd_soc_tplg_ctl_hdr);
|
||||||
hdr->type = t->type;
|
hdr->type = t->type;
|
||||||
|
|
||||||
elem_copy_text(hdr->name, t->name,
|
snd_strlcpy(hdr->name, t->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
|
||||||
|
|
||||||
/* clean up access flag */
|
/* clean up access flag */
|
||||||
if (t->access == 0)
|
if (t->access == 0)
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,7 @@ static int tplg_parse_line(const char *text,
|
||||||
unsigned int len, i;
|
unsigned int len, i;
|
||||||
const char *source = NULL, *sink = NULL, *control = NULL;
|
const char *source = NULL, *sink = NULL, *control = NULL;
|
||||||
|
|
||||||
elem_copy_text(buf, text, LINE_SIZE);
|
snd_strlcpy(buf, text, LINE_SIZE);
|
||||||
|
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
if (len <= 2) {
|
if (len <= 2) {
|
||||||
|
|
@ -488,7 +488,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg,
|
||||||
tplg_dbg(" Widget: %s\n", elem->id);
|
tplg_dbg(" Widget: %s\n", elem->id);
|
||||||
|
|
||||||
widget = elem->widget;
|
widget = elem->widget;
|
||||||
elem_copy_text(widget->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(widget->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
widget->size = elem->size;
|
widget->size = elem->size;
|
||||||
|
|
||||||
snd_config_for_each(i, next, cfg) {
|
snd_config_for_each(i, next, cfg) {
|
||||||
|
|
@ -523,7 +523,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg,
|
||||||
if (snd_config_get_string(n, &val) < 0)
|
if (snd_config_get_string(n, &val) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
elem_copy_text(widget->sname, val,
|
snd_strlcpy(widget->sname, val,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
tplg_dbg("\t%s: %s\n", id, val);
|
tplg_dbg("\t%s: %s\n", id, val);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -642,11 +642,11 @@ int tplg_add_route(snd_tplg_t *tplg, struct snd_tplg_graph_elem *t)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
line = elem->route;
|
line = elem->route;
|
||||||
elem_copy_text(line->source, t->src, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(line->source, t->src, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
if (t->ctl)
|
if (t->ctl)
|
||||||
elem_copy_text(line->control, t->ctl,
|
snd_strlcpy(line->control, t->ctl,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
elem_copy_text(line->sink, t->sink, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(line->sink, t->sink, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -684,9 +684,9 @@ int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
|
||||||
w->size = elem->size;
|
w->size = elem->size;
|
||||||
|
|
||||||
w->id = wt->id;
|
w->id = wt->id;
|
||||||
elem_copy_text(w->name, wt->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(w->name, wt->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
if (wt->sname)
|
if (wt->sname)
|
||||||
elem_copy_text(w->sname, wt->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(w->sname, wt->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
w->reg = wt->reg;
|
w->reg = wt->reg;
|
||||||
w->shift = wt->shift;
|
w->shift = wt->shift;
|
||||||
w->mask = wt->mask;
|
w->mask = wt->mask;
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,7 @@ static int copy_tuples(struct tplg_elem *elem,
|
||||||
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
|
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
|
||||||
string = &array->string[j];
|
string = &array->string[j];
|
||||||
string->token = token_val;
|
string->token = token_val;
|
||||||
elem_copy_text(string->string, tuple->string,
|
snd_strlcpy(string->string, tuple->string,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -587,7 +587,7 @@ static int parse_tuple_set(snd_config_t *cfg,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tuple = &set->tuple[set->num_tuples];
|
tuple = &set->tuple[set->num_tuples];
|
||||||
elem_copy_text(tuple->token, id,
|
snd_strlcpy(tuple->token, id,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
@ -597,7 +597,7 @@ static int parse_tuple_set(snd_config_t *cfg,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
|
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
|
||||||
elem_copy_text(tuple->string, value,
|
snd_strlcpy(tuple->string, value,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->string);
|
tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->string);
|
||||||
break;
|
break;
|
||||||
|
|
@ -818,7 +818,7 @@ int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg,
|
||||||
if (snd_config_get_string(n, &value) < 0)
|
if (snd_config_get_string(n, &value) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
elem_copy_text(tokens->token[tokens->num_tokens].id, id,
|
snd_strlcpy(tokens->token[tokens->num_tokens].id, id,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
tokens->token[tokens->num_tokens].value = atoi(value);
|
tokens->token[tokens->num_tokens].value = atoi(value);
|
||||||
tplg_dbg("\t\t %s : %d\n", tokens->token[tokens->num_tokens].id,
|
tplg_dbg("\t\t %s : %d\n", tokens->token[tokens->num_tokens].id,
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ int tplg_ref_add_elem(struct tplg_elem *elem, struct tplg_elem *elem_ref)
|
||||||
|
|
||||||
ref->type = elem_ref->type;
|
ref->type = elem_ref->type;
|
||||||
ref->elem = elem_ref;
|
ref->elem = elem_ref;
|
||||||
elem_copy_text(ref->id, elem_ref->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(ref->id, elem_ref->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
list_add_tail(&ref->list, &elem->ref_list);
|
list_add_tail(&ref->list, &elem->ref_list);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -169,7 +169,7 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
|
||||||
/* do we get name from cfg */
|
/* do we get name from cfg */
|
||||||
if (cfg) {
|
if (cfg) {
|
||||||
snd_config_get_id(cfg, &id);
|
snd_config_get_id(cfg, &id);
|
||||||
elem_copy_text(elem->id, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(elem->id, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
elem->id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0;
|
elem->id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0;
|
||||||
/* as we insert new elem based on the index value, move index
|
/* as we insert new elem based on the index value, move index
|
||||||
parsing here */
|
parsing here */
|
||||||
|
|
@ -186,7 +186,7 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (name != NULL)
|
} else if (name != NULL)
|
||||||
elem_copy_text(elem->id, name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(elem->id, name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SND_TPLG_TYPE_DATA:
|
case SND_TPLG_TYPE_DATA:
|
||||||
|
|
|
||||||
|
|
@ -383,7 +383,7 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg,
|
||||||
|
|
||||||
sc = elem->stream_caps;
|
sc = elem->stream_caps;
|
||||||
sc->size = elem->size;
|
sc->size = elem->size;
|
||||||
elem_copy_text(sc->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(sc->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
tplg_dbg(" PCM Capabilities: %s\n", elem->id);
|
tplg_dbg(" PCM Capabilities: %s\n", elem->id);
|
||||||
|
|
||||||
|
|
@ -562,7 +562,7 @@ static int tplg_parse_streams(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
|
||||||
/* store stream caps name, to find and merge
|
/* store stream caps name, to find and merge
|
||||||
* the caps in building phase.
|
* the caps in building phase.
|
||||||
*/
|
*/
|
||||||
elem_copy_text(caps[stream].name, value,
|
snd_strlcpy(caps[stream].name, value,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
tplg_dbg("\t\t%s\n\t\t\t%s\n", id, value);
|
tplg_dbg("\t\t%s\n\t\t\t%s\n", id, value);
|
||||||
|
|
@ -586,7 +586,7 @@ static int tplg_parse_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
snd_config_get_id(cfg, &id);
|
snd_config_get_id(cfg, &id);
|
||||||
tplg_dbg("\t\tFE DAI %s:\n", id);
|
tplg_dbg("\t\tFE DAI %s:\n", id);
|
||||||
elem_copy_text(pcm->dai_name, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(pcm->dai_name, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
snd_config_for_each(i, next, cfg) {
|
snd_config_for_each(i, next, cfg) {
|
||||||
|
|
||||||
|
|
@ -653,7 +653,7 @@ int tplg_parse_pcm(snd_tplg_t *tplg,
|
||||||
|
|
||||||
pcm = elem->pcm;
|
pcm = elem->pcm;
|
||||||
pcm->size = elem->size;
|
pcm->size = elem->size;
|
||||||
elem_copy_text(pcm->pcm_name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(pcm->pcm_name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
tplg_dbg(" PCM: %s\n", elem->id);
|
tplg_dbg(" PCM: %s\n", elem->id);
|
||||||
|
|
||||||
|
|
@ -754,7 +754,7 @@ int tplg_parse_dai(snd_tplg_t *tplg,
|
||||||
|
|
||||||
dai = elem->dai;
|
dai = elem->dai;
|
||||||
dai->size = elem->size;
|
dai->size = elem->size;
|
||||||
elem_copy_text(dai->dai_name, elem->id,
|
snd_strlcpy(dai->dai_name, elem->id,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
tplg_dbg(" DAI: %s\n", elem->id);
|
tplg_dbg(" DAI: %s\n", elem->id);
|
||||||
|
|
@ -920,7 +920,7 @@ int tplg_parse_link(snd_tplg_t *tplg,
|
||||||
|
|
||||||
link = elem->link;
|
link = elem->link;
|
||||||
link->size = elem->size;
|
link->size = elem->size;
|
||||||
elem_copy_text(link->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
snd_strlcpy(link->name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
tplg_dbg(" Link: %s\n", elem->id);
|
tplg_dbg(" Link: %s\n", elem->id);
|
||||||
|
|
||||||
|
|
@ -949,7 +949,7 @@ int tplg_parse_link(snd_tplg_t *tplg,
|
||||||
if (snd_config_get_string(n, &val) < 0)
|
if (snd_config_get_string(n, &val) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
elem_copy_text(link->stream_name, val,
|
snd_strlcpy(link->stream_name, val,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
tplg_dbg("\t%s: %s\n", id, val);
|
tplg_dbg("\t%s: %s\n", id, val);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1319,7 +1319,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
|
||||||
static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm,
|
static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm,
|
||||||
struct snd_tplg_stream_template *strm_tpl)
|
struct snd_tplg_stream_template *strm_tpl)
|
||||||
{
|
{
|
||||||
elem_copy_text(strm->name, strm_tpl->name,
|
snd_strlcpy(strm->name, strm_tpl->name,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
strm->format = strm_tpl->format;
|
strm->format = strm_tpl->format;
|
||||||
strm->rate = strm_tpl->rate;
|
strm->rate = strm_tpl->rate;
|
||||||
|
|
@ -1331,7 +1331,7 @@ static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm,
|
||||||
static void tplg_add_stream_caps(struct snd_soc_tplg_stream_caps *caps,
|
static void tplg_add_stream_caps(struct snd_soc_tplg_stream_caps *caps,
|
||||||
struct snd_tplg_stream_caps_template *caps_tpl)
|
struct snd_tplg_stream_caps_template *caps_tpl)
|
||||||
{
|
{
|
||||||
elem_copy_text(caps->name, caps_tpl->name,
|
snd_strlcpy(caps->name, caps_tpl->name,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
caps->formats = caps_tpl->formats;
|
caps->formats = caps_tpl->formats;
|
||||||
|
|
@ -1370,9 +1370,9 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
|
||||||
pcm = elem->pcm;
|
pcm = elem->pcm;
|
||||||
pcm->size = elem->size;
|
pcm->size = elem->size;
|
||||||
|
|
||||||
elem_copy_text(pcm->pcm_name, pcm_tpl->pcm_name,
|
snd_strlcpy(pcm->pcm_name, pcm_tpl->pcm_name,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
elem_copy_text(pcm->dai_name, pcm_tpl->dai_name,
|
snd_strlcpy(pcm->dai_name, pcm_tpl->dai_name,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
pcm->pcm_id = pcm_tpl->pcm_id;
|
pcm->pcm_id = pcm_tpl->pcm_id;
|
||||||
pcm->dai_id = pcm_tpl->dai_id;
|
pcm->dai_id = pcm_tpl->dai_id;
|
||||||
|
|
@ -1478,9 +1478,9 @@ int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
|
||||||
|
|
||||||
/* ID and names */
|
/* ID and names */
|
||||||
link->id = link_tpl->id;
|
link->id = link_tpl->id;
|
||||||
elem_copy_text(link->name, link_tpl->name,
|
snd_strlcpy(link->name, link_tpl->name,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
elem_copy_text(link->stream_name, link_tpl->stream_name,
|
snd_strlcpy(link->stream_name, link_tpl->stream_name,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
|
|
||||||
/* stream configs */
|
/* stream configs */
|
||||||
|
|
@ -1540,7 +1540,7 @@ int tplg_add_dai_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
|
||||||
dai = elem->dai;
|
dai = elem->dai;
|
||||||
dai->size = elem->size;
|
dai->size = elem->size;
|
||||||
|
|
||||||
elem_copy_text(dai->dai_name, dai_tpl->dai_name,
|
snd_strlcpy(dai->dai_name, dai_tpl->dai_name,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
dai->dai_id = dai_tpl->dai_id;
|
dai->dai_id = dai_tpl->dai_id;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ static int parse_text_values(snd_config_t *cfg, struct tplg_elem *elem)
|
||||||
if (snd_config_get_string(n, &value) < 0)
|
if (snd_config_get_string(n, &value) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
elem_copy_text(&texts->items[j][0], value,
|
snd_strlcpy(&texts->items[j][0], value,
|
||||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||||
tplg_dbg("\t%s\n", &texts->items[j][0]);
|
tplg_dbg("\t%s\n", &texts->items[j][0]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -282,15 +282,6 @@ struct tplg_elem *tplg_elem_lookup(struct list_head *base,
|
||||||
struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
|
struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
|
||||||
snd_config_t *cfg, const char *name, enum snd_tplg_type type);
|
snd_config_t *cfg, const char *name, enum snd_tplg_type type);
|
||||||
|
|
||||||
static inline void elem_copy_text(char *dest, const char *src, int len)
|
|
||||||
{
|
|
||||||
if (!dest || !src || !len)
|
|
||||||
return;
|
|
||||||
|
|
||||||
strncpy(dest, src, len);
|
|
||||||
dest[len - 1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tplg_parse_channel(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
|
int tplg_parse_channel(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
|
||||||
snd_config_t *cfg, void *private);
|
snd_config_t *cfg, void *private);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue