[alsa-devel] [PATCH] ALSA: pcm: Mostly constify constraints
tiwai at suse.de
Thu Jul 5 11:55:36 CEST 2012
At Thu, 5 Jul 2012 10:28:42 +0100,
Mark Brown wrote:
> On Thu, Jul 05, 2012 at 09:06:30AM +0200, Takashi Iwai wrote:
> > Mark Brown wrote:
> > > There is no need for the constraints to be modified while being
> > > applied
> > Many drivers pass the local instance to rule->private, and it's not
> > always guaranteed to be const. For example, you can imagine some
> > state modified kept in the struct while it's modified via rules.
> > In short: you'd have seen many compile warnings for non-ASoC drivers
> > if you run make once with this patch ;)
> Well, that's trivial to fix.
> > As a safe side fix, how about just adding const to
> > snd_pcm_hw_constraint_list() & co, and expclitly cast to non-const
> > later?
> My inclination for something like this is to put the casts with the
> users since that way we get the type safety through most of the code and
> we can see that dropping the const is safe since we're just getting back
> our own data. If we can see the APIs immediately dropping the const I'd
> expect we'd get people spending time on code review trying to figure out
> if it's safe.
The rule->private pointer isn't designed to be always const. The data
purely depends on each rule function, thus whether it can be const or
not also depends on the rule, too. For simple rules like list take
indeed the constant list. But more complex rules may take a struct
containing variables changed on the fly (e.g. the max rate set by
user via control API).
More information about the Alsa-devel