From: Takashi Iwai Subject: Re: [Pull request] Support for wm9705 codec and two machines that use it. Date: Fri, 16 Jan 2009 12:03:37 +0100 Message-ID: References: <496E8DD0.4090006@mnementh.co.uk> <496F0ABD.4080207@mnementh.co.uk> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 030C61038D8 for ; Fri, 16 Jan 2009 12:03:38 +0100 (CET) In-Reply-To: <496F0ABD.4080207@mnementh.co.uk> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Ian Molton Cc: ALSA development , Russell King - ARM Linux List-Id: alsa-devel@alsa-project.org At Thu, 15 Jan 2009 10:06:53 +0000, Ian Molton wrote: > > +static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int > reg) > +{ > + u16 *cache = codec->reg_cache; > + > + switch (reg) { > + case AC97_RESET: > + case AC97_VENDOR_ID1: > + case AC97_VENDOR_ID2: > + return soc_ac97_ops.read(codec->ac97, reg); > + default: > + reg = reg >> 1; > + > + if (reg > (ARRAY_SIZE(wm9705_reg))) > + return -EIO; Shouldn't be this "reg >= ARRAY_SIZE(wm9705_reg)" ? > +static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, > + unsigned int val) > +{ > + u16 *cache = codec->reg_cache; > + > + soc_ac97_ops.write(codec->ac97, reg, val); > + reg = reg >> 1; > + if (reg <= (ARRAY_SIZE(wm9705_reg))) > + cache[reg] = val; Ditto, should be "reg < ARRAY_SIZE(wm9705_reg)". > +static int wm9705_soc_probe(struct platform_device *pdev) > +{ > + struct snd_soc_device *socdev = platform_get_drvdata(pdev); > + struct snd_soc_codec *codec; > + int ret = 0; > + > + printk(KERN_INFO "WM9705 SoC Audio Codec\n"); > + > + socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); > + if (socdev->codec == NULL) > + return -ENOMEM; > + codec = socdev->codec; > + mutex_init(&codec->mutex); > + > + codec->reg_cache = > + kzalloc(sizeof(u16) * ARRAY_SIZE(wm9705_reg), GFP_KERNEL); > + if (codec->reg_cache == NULL) { > + ret = -ENOMEM; > + goto cache_err; > + } > + memcpy(codec->reg_cache, wm9705_reg, > + sizeof(u16) * ARRAY_SIZE(wm9705_reg)); You can use kmemdup() here. thanks, Takashi