From: Takashi Iwai Subject: Re: [PATCH 4/4] ASoC: clean up cache accesser Date: Mon, 20 Dec 2010 17:47:13 +0100 Message-ID: References: <20101220152709.GJ26706@rakim.wolfsonmicro.main> <1292862469.29185.7.camel@dplaptop.localdomain> 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 mx1.suse.de (cantor.suse.de [195.135.220.2]) by alsa0.perex.cz (Postfix) with ESMTP id 4F401103868 for ; Mon, 20 Dec 2010 17:47:14 +0100 (CET) In-Reply-To: <1292862469.29185.7.camel@dplaptop.localdomain> 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: Dimitris Papastamos Cc: alsa-devel@alsa-project.org, Mark Brown , Liam Girdwood List-Id: alsa-devel@alsa-project.org At Mon, 20 Dec 2010 16:27:49 +0000, Dimitris Papastamos wrote: > > On Mon, 2010-12-20 at 17:05 +0100, Takashi Iwai wrote: > > +static inline bool set_cache_val(void *base, unsigned int idx, > > + unsigned int val, unsigned int word_size) > > +{ > > + if (word_size == 1) { > > + u8 *cache = base; > > + if (cache[idx] == val) > > + return true; > > + cache[idx] = val; > > + } else { > > + u16 *cache = base; > > + if (cache[idx] == val) > > + return true; > > + cache[idx] = val; > > + } > > + return false; > > +} > > If word_size is anything other than 1 byte, the above else will try to > handle it and assume it is 16 bits. I'd expect for an explicit check > for word_size == 2. A switch statement would perhaps be preferred for > legibility. It'd perhaps be wise to simply die via BUG() or similar if > an unsupported word size was passed in. Yes, this would be safer. I didn't put it since I wasn't sure whether BUG() content is also expanded at each caller. If yes, it would bloat. (Alternatively we may use snd_BUG_ON() -- it's built in only when CONFIG_SND_DEBUG is set.) Anyway, such a check should have been done rather at initialization. thanks, Takashi