[alsa-devel] [PATCH v5] ASoC: Add Freescale SGTL5000 codec support

Mark Brown broonie at opensource.wolfsonmicro.com
Mon Feb 28 15:45:26 CET 2011

On Fri, Feb 25, 2011 at 11:56:52PM +0800, Zeng Zhaoming wrote:
> On Fri, Feb 25, 2011 at 8:09 PM, Mark Brown

> > This is going to fail on systems without voltage readback capabilities,
> > including systems which have the regulator API disabled and stubbed out.

> if the regulator driver not allow readback, I have no way to get the
> voltage of vdda and vddio,
> the voltage levels are critical  to codec initialization.

> Can you shed some light on howto around this?

If you can't read the data back you need to guess what the configuration
is somehow; I'd suggest just picking values and warning about what
you're doing.

> >> +     memcpy((void *)(&sgtl5000_regs[0] + (SGTL5000_DAP_REG_OFFSET >> 1)),
> >> +                     sgtl5000_dap_regs,
> >> +                     SGTL5000_MAX_REG_OFFSET - SGTL5000_DAP_REG_OFFSET);

> > As has been pointed out on previous revisions of the patch there is no
> > need to cast away from void in C and it can be actively harmful.

> I have not remove void* since my toolchain ( gcc 4.4.4) complains
> about the type mismatch, I will test
> it with other version toolchain to confirm.

As Timur indicated the reason this is complaining is that you're
memcpy() is writing to const data.  This is *clearly* buggy - the fact
that casting away removes the warning is an example of why you should
never have casts like this.

You should take a copy of the array and modify that, having the defaults
as const is correct.

More information about the Alsa-devel mailing list