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 v3] ucm: add cset-tlv
Date: Thu, 24 Mar 2016 14:19:41 +0100 [thread overview]
Message-ID: <s5h60wcau8i.wl-tiwai@suse.de> (raw)
In-Reply-To: <1458786501-8914-1-git-send-email-hychao@chromium.org>
On Thu, 24 Mar 2016 03:28:21 +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.
> The TLV file to set to kcontrol will be checked first by file size
> not larger than 16 MB, and then examine if the length field reports
> correct number of bytes in the TLV file.
>
> Signed-off-by: Hsin-Yu Chao <hychao@chromium.org>
> ---
> src/ucm/main.c | 91 +++++++++++++++++++++++++++++++++++++++++++++--------
> src/ucm/parser.c | 10 ++++++
> src/ucm/ucm_local.h | 1 +
> 3 files changed, 89 insertions(+), 13 deletions(-)
>
> diff --git a/src/ucm/main.c b/src/ucm/main.c
> index 7e44603..d0929a2 100644
> --- a/src/ucm/main.c
> +++ b/src/ucm/main.c
> @@ -161,6 +161,54 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr,
> return 0;
> }
>
> +static int read_tlv_file(char **res,
> + const char *filepath)
> +{
> + int err = 0;
> + int fd;
> + struct stat st;
> + size_t sz;
> + ssize_t sz_read;
> + unsigned int *tlv;
> +
> + fd = open(filepath, O_RDONLY);
> + if (fd < 0) {
> + err = -errno;
> + return err;
> + }
> + if (stat(filepath, &st) == -1) {
Better to use fstat() with the opened fd.
> + err = -errno;
> + goto __fail;
> + }
> + sz = st.st_size;
> + if (sz > 16 * 1024 * 1024 || sz < 8) {
> + uc_error("File size should be less than 16 MB");
> + goto __fail;
The error code is missing.
> + }
> + *res = malloc(sz);
> + if (res == NULL) {
> + err = -ENOMEM;
> + goto __fail;
> + }
> + sz_read = read(fd, *res, sz);
> + if (sz_read < 0 || (size_t)sz_read != sz) {
> + err = -errno;
The size shortage won't set the errno. You'd need to give the error
code explicitly, or repeat the read.
> + free(*res);
> + *res = NULL;
> + }
> + /* Check if the tlv file specifies valid size. */
> + tlv = (unsigned int *)(*res);
> + if (tlv[1] + 2 * sizeof(unsigned int) != sz) {
> + uc_error("Invalid tlv size");
> + free(*res);
> + *res = NULL;
The missing error code.
thanks,
Takashi
next prev parent reply other threads:[~2016-03-24 13:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-24 2:28 [PATCH v3] ucm: add cset-tlv Hsin-Yu Chao
2016-03-24 13:19 ` Takashi Iwai [this message]
2016-04-13 6:24 ` Hsin-yu Chao
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=s5h60wcau8i.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).