Re: [RFC PATCH v2 3/3] ASoC: codecs: Initialise PCM hardware tables at boot for page size

From: Tzung-Bi Shih

Date: Tue Dec 01 2026 - 23:56:37 EST


On Wed, Dec 02, 2026 at 03:17:29AM +0000, Eric Curtin wrote:
> From: Ryan Roberts <ryan.roberts@xxxxxxx>
>
> The snd_pcm_hardware tables in cros_ec_codec.c and rt5514-spi.c use
> PAGE_SIZE in their initialisers. That is not a constant expression with
> arm64 boot-time page size selection, so the tables cannot be static
> initialisers.
>
> Define them with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(), which keeps a
> normal const initialiser for a fixed page size and otherwise fills the
> table in once the page size is known at boot. In cros_ec_codec.c the
> table was local to wov_pcm_open(), so it moves to file scope.

The cover letter [1] should be sent to the recipients of the patch as well,
so the context is easier to find.

[1] https://lore.kernel.org/all/20261202031733.1704898-1-ericcurtin17@xxxxxxxxx

> diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
> index b6f7016a324a..f6e0395d47a1 100644
> --- a/sound/soc/codecs/cros_ec_codec.c
> +++ b/sound/soc/codecs/cros_ec_codec.c
> @@ -874,24 +874,24 @@ static void wov_remove(struct snd_soc_component *component)
> &priv->ec_device->event_notifier, &priv->wov_notifier);
> }
>
> +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct snd_pcm_hardware, hw_param, {
> + .info = SNDRV_PCM_INFO_MMAP |
> + SNDRV_PCM_INFO_INTERLEAVED |
> + SNDRV_PCM_INFO_MMAP_VALID,
> + .formats = SNDRV_PCM_FMTBIT_S16_LE,
> + .rates = SNDRV_PCM_RATE_16000,
> + .channels_min = 1,
> + .channels_max = 1,
> + .period_bytes_min = PAGE_SIZE,
> + .period_bytes_max = 0x20000 / 8,
> + .periods_min = 8,
> + .periods_max = 8,
> + .buffer_bytes_max = 0x20000,
> +});

If keeping it this way, hw_param is moved from function scope to file scope
and needs a prefix, e.g., wov_hw_param.

> +
> static int wov_pcm_open(struct snd_soc_component *component,
> struct snd_pcm_substream *substream)
> {
> - static const struct snd_pcm_hardware hw_param = {
> - .info = SNDRV_PCM_INFO_MMAP |
> - SNDRV_PCM_INFO_INTERLEAVED |
> - SNDRV_PCM_INFO_MMAP_VALID,
> - .formats = SNDRV_PCM_FMTBIT_S16_LE,
> - .rates = SNDRV_PCM_RATE_16000,
> - .channels_min = 1,
> - .channels_max = 1,
> - .period_bytes_min = PAGE_SIZE,
> - .period_bytes_max = 0x20000 / 8,
> - .periods_min = 8,
> - .periods_max = 8,
> - .buffer_bytes_max = 0x20000,
> - };
> -

Overall, I think this is overkill. Replacing PAGE_SIZE here with SZ_4K
would be the simplest fix. At least cros_ec_codec was written and tested
assuming PAGE_SIZE is 4K.