mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-11 13:30:05 -05: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
|
|
@ -380,7 +380,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg,
|
|||
|
||||
be = elem->bytes_ext;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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->size = elem->size;
|
||||
tplg->channel_idx = 0;
|
||||
|
|
@ -606,7 +606,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg,
|
|||
|
||||
/* init new mixer */
|
||||
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->size = elem->size;
|
||||
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->type = t->type;
|
||||
|
||||
elem_copy_text(hdr->name, t->name,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
snd_strlcpy(hdr->name, t->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
|
||||
/* clean up access flag */
|
||||
if (t->access == 0)
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ static int tplg_parse_line(const char *text,
|
|||
unsigned int len, i;
|
||||
const char *source = NULL, *sink = NULL, *control = NULL;
|
||||
|
||||
elem_copy_text(buf, text, LINE_SIZE);
|
||||
snd_strlcpy(buf, text, LINE_SIZE);
|
||||
|
||||
len = strlen(buf);
|
||||
if (len <= 2) {
|
||||
|
|
@ -488,7 +488,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg,
|
|||
tplg_dbg(" Widget: %s\n", elem->id);
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
return -EINVAL;
|
||||
|
||||
elem_copy_text(widget->sname, val,
|
||||
snd_strlcpy(widget->sname, val,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
tplg_dbg("\t%s: %s\n", id, val);
|
||||
continue;
|
||||
|
|
@ -642,11 +642,11 @@ int tplg_add_route(snd_tplg_t *tplg, struct snd_tplg_graph_elem *t)
|
|||
return -ENOMEM;
|
||||
|
||||
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)
|
||||
elem_copy_text(line->control, t->ctl,
|
||||
snd_strlcpy(line->control, t->ctl,
|
||||
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;
|
||||
}
|
||||
|
|
@ -684,9 +684,9 @@ int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
|
|||
w->size = elem->size;
|
||||
|
||||
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)
|
||||
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->shift = wt->shift;
|
||||
w->mask = wt->mask;
|
||||
|
|
|
|||
|
|
@ -473,7 +473,7 @@ static int copy_tuples(struct tplg_elem *elem,
|
|||
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
|
||||
string = &array->string[j];
|
||||
string->token = token_val;
|
||||
elem_copy_text(string->string, tuple->string,
|
||||
snd_strlcpy(string->string, tuple->string,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
break;
|
||||
|
||||
|
|
@ -587,7 +587,7 @@ static int parse_tuple_set(snd_config_t *cfg,
|
|||
continue;
|
||||
|
||||
tuple = &set->tuple[set->num_tuples];
|
||||
elem_copy_text(tuple->token, id,
|
||||
snd_strlcpy(tuple->token, id,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
|
||||
switch (type) {
|
||||
|
|
@ -597,7 +597,7 @@ static int parse_tuple_set(snd_config_t *cfg,
|
|||
break;
|
||||
|
||||
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
|
||||
elem_copy_text(tuple->string, value,
|
||||
snd_strlcpy(tuple->string, value,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->string);
|
||||
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)
|
||||
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);
|
||||
tokens->token[tokens->num_tokens].value = atoi(value);
|
||||
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->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);
|
||||
return 0;
|
||||
|
|
@ -169,7 +169,7 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
|
|||
/* do we get name from cfg */
|
||||
if (cfg) {
|
||||
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;
|
||||
/* as we insert new elem based on the index value, move index
|
||||
parsing here */
|
||||
|
|
@ -186,7 +186,7 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
|
|||
}
|
||||
}
|
||||
} 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) {
|
||||
case SND_TPLG_TYPE_DATA:
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg,
|
|||
|
||||
sc = elem->stream_caps;
|
||||
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);
|
||||
|
||||
|
|
@ -562,7 +562,7 @@ static int tplg_parse_streams(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
|
|||
/* store stream caps name, to find and merge
|
||||
* the caps in building phase.
|
||||
*/
|
||||
elem_copy_text(caps[stream].name, value,
|
||||
snd_strlcpy(caps[stream].name, value,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
|
||||
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);
|
||||
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) {
|
||||
|
||||
|
|
@ -653,7 +653,7 @@ int tplg_parse_pcm(snd_tplg_t *tplg,
|
|||
|
||||
pcm = elem->pcm;
|
||||
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);
|
||||
|
||||
|
|
@ -754,7 +754,7 @@ int tplg_parse_dai(snd_tplg_t *tplg,
|
|||
|
||||
dai = elem->dai;
|
||||
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);
|
||||
|
||||
tplg_dbg(" DAI: %s\n", elem->id);
|
||||
|
|
@ -920,7 +920,7 @@ int tplg_parse_link(snd_tplg_t *tplg,
|
|||
|
||||
link = elem->link;
|
||||
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);
|
||||
|
||||
|
|
@ -949,7 +949,7 @@ int tplg_parse_link(snd_tplg_t *tplg,
|
|||
if (snd_config_get_string(n, &val) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
elem_copy_text(link->stream_name, val,
|
||||
snd_strlcpy(link->stream_name, val,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
tplg_dbg("\t%s: %s\n", id, val);
|
||||
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,
|
||||
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);
|
||||
strm->format = strm_tpl->format;
|
||||
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,
|
||||
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);
|
||||
|
||||
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->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);
|
||||
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);
|
||||
pcm->pcm_id = pcm_tpl->pcm_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 */
|
||||
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);
|
||||
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);
|
||||
|
||||
/* 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->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);
|
||||
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)
|
||||
continue;
|
||||
|
||||
elem_copy_text(&texts->items[j][0], value,
|
||||
snd_strlcpy(&texts->items[j][0], value,
|
||||
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
||||
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,
|
||||
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,
|
||||
snd_config_t *cfg, void *private);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue