All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Hsin-Yu Chao <hychao@chromium.org>
Cc: vinod.koul@intel.com, alsa-devel@alsa-project.org, dgreid@chromium.org
Subject: Re: [PATCH] ucm: add cset-tlv command
Date: Tue, 22 Mar 2016 12:48:36 +0100	[thread overview]
Message-ID: <s5hpoumzqaz.wl-tiwai@suse.de> (raw)
In-Reply-To: <1458637834-15947-1-git-send-email-hychao@chromium.org>

On Tue, 22 Mar 2016 10:10:34 +0100,
Hsin-Yu Chao wrote:
> 
> This patch enables UCM to set a file in TLV format to kcontrol by:
> cset-tlv "name='<kcontrol-name>' <path-to-file>"
> This new 'cset-tlv' command will be used to write audio DSP to
> specific alsa control, where the driver expectes a file in TLV
> format.
> 
> Signed-off-by: Hsin-Yu Chao <hychao@chromium.org>

One problem in this approach is that the provided TLV data file isn't
portable.  Since we deal TLV as int arrays, it's endian-sensitive.
At least, some endian check would be needed.

Some other nitpicks:

> ---
>  src/ucm/main.c      | 80 ++++++++++++++++++++++++++++++++++++++++++++---------
>  src/ucm/parser.c    | 10 +++++++
>  src/ucm/ucm_local.h |  1 +
>  3 files changed, 78 insertions(+), 13 deletions(-)
> 
> diff --git a/src/ucm/main.c b/src/ucm/main.c
> index 7e44603..a4ccb65 100644
> --- a/src/ucm/main.c
> +++ b/src/ucm/main.c
> @@ -161,6 +161,47 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr,
>  	return 0;
>  }
>  
> +static int tlv_parse(char **res,
> +		     snd_ctl_elem_info_t *info,
> +		     const char *filepath)

The function name is somehow confusing.  It appears as if it parses
TLV.  And what it actually does are two things:
- check snd_ctl_elem_info_is_tlv_writable(),
and
- allocate the whole TLV file.

IMO, snd_ctl_elem_info_is_tlv_writable() check can be in the caller
side, and this function (rename whatever better) can just do allocate
and read the TLV data into a buffer.


> +{
> +	int err = 0;
> +	int fd;
> +	struct stat st;
> +	size_t sz;
> +	ssize_t sz_read;
> +
> +	if (!snd_ctl_elem_info_is_tlv_writable(info)) {
> +		err = -EINVAL;
> +		return err;
> +	}
> +	fd = open(filepath, O_RDONLY);
> +	if (fd < 0) {
> +		err = -errno;
> +		return err;
> +	}
> +	if (stat(filepath, &st) == -1) {
> +		err = -errno;
> +		goto __fail;
> +	}
> +	sz = st.st_size;
> +	*res = malloc(sz);

What if a crazy large file was passed?  A sanity check of the file
size might be good.


thanks,

Takashi

  reply	other threads:[~2016-03-22 11:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22  9:10 [PATCH] ucm: add cset-tlv command Hsin-Yu Chao
2016-03-22 11:48 ` Takashi Iwai [this message]
2016-03-23  9:15   ` Hsin-yu Chao
2016-03-23  9:21     ` Takashi Iwai
2016-03-23  9:44       ` Hsin-yu Chao
2016-03-23 16:52         ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hpoumzqaz.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=dgreid@chromium.org \
    --cc=hychao@chromium.org \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.