All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Xiubo Li <Li.Xiubo@freescale.com>
Cc: broonie@kernel.org, lgirdwood@gmail.com, tiwai@suse.de,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: Re: [alsa-devel] [PATCH] ASoC: cache: Do the codec->reg_cache zero pionter check
Date: Fri, 28 Feb 2014 07:58:33 +0100	[thread overview]
Message-ID: <53103399.5070202@metafoo.de> (raw)
In-Reply-To: <1393555699-12752-1-git-send-email-Li.Xiubo@freescale.com>

On 02/28/2014 03:48 AM, Xiubo Li wrote:
> For the snd_soc_cache_init(), the reg_size maybe zero and then the value
> of codec->reg_cache, which is alloced via kzalloc, maybe equal to
> ZERO_SIZE_PTR. If the reg parameter of snd_soc_cache_write() is large enough,
> the cache[idx] = val maybe cause the kernel crash...
>

There are actually no users of snd_soc_cache_{read,write}() left. Since all 
drivers using snd_soc_set_cache_io() are now using native regmap the path in 
hw_{read,write} that does call snd_soc_cache_{read,write}() is never hit.

If you want to avoid this theoretical issue just remove the functions.

> So this patch fix this via doing the zero pionter check of it.
>
> Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
> ---
>   sound/soc/soc-cache.c | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
> index 375dc6d..bfed3e4 100644
> --- a/sound/soc/soc-cache.c
> +++ b/sound/soc/soc-cache.c
> @@ -96,8 +96,7 @@ int snd_soc_cache_exit(struct snd_soc_codec *codec)
>   {
>   	dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n",
>   			codec->name);
> -	if (!codec->reg_cache)
> -		return 0;
> +
>   	kfree(codec->reg_cache);
>   	codec->reg_cache = NULL;
>   	return 0;
> @@ -117,8 +116,9 @@ int snd_soc_cache_read(struct snd_soc_codec *codec,
>   		return -EINVAL;
>
>   	mutex_lock(&codec->cache_rw_mutex);
> -	*value = snd_soc_get_cache_val(codec->reg_cache, reg,
> -				       codec->driver->reg_word_size);
> +	if (!ZERO_OR_NULL_PTR(codec->reg_cache))
> +		*value = snd_soc_get_cache_val(codec->reg_cache, reg,
> +					       codec->driver->reg_word_size);
>   	mutex_unlock(&codec->cache_rw_mutex);
>
>   	return 0;
> @@ -136,8 +136,9 @@ int snd_soc_cache_write(struct snd_soc_codec *codec,
>   			unsigned int reg, unsigned int value)
>   {
>   	mutex_lock(&codec->cache_rw_mutex);
> -	snd_soc_set_cache_val(codec->reg_cache, reg, value,
> -			      codec->driver->reg_word_size);
> +	if (!ZERO_OR_NULL_PTR(codec->reg_cache))
> +		snd_soc_set_cache_val(codec->reg_cache, reg, value,
> +				      codec->driver->reg_word_size);
>   	mutex_unlock(&codec->cache_rw_mutex);
>
>   	return 0;
>

  reply	other threads:[~2014-02-28  6:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-28  2:48 [PATCH] ASoC: cache: Do the codec->reg_cache zero pionter check Xiubo Li
2014-02-28  2:48 ` Xiubo Li
2014-02-28  6:58 ` Lars-Peter Clausen [this message]
2014-03-04  4:32 ` Mark Brown

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=53103399.5070202@metafoo.de \
    --to=lars@metafoo.de \
    --cc=Li.Xiubo@freescale.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tiwai@suse.de \
    /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.