Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Charles Keepax" <ckeepax@opensource.cirrus.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
	Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	David Rhodes <david.rhodes@cirrus.com>,
	Vlad Karpovich <vkarpovi@opensource.cirrus.com>,
	Paul Handrigan <Paul.Handrigan@cirrus.com>,
	patches@opensource.cirrus.com, linux-sound@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 0/3] ASoC: cs35l41/cs35l45/cs4265: sort the reg_defaults tables
Date: Wed, 5 Aug 2026 10:56:50 +0100	[thread overview]
Message-ID: <ffa045f4-dfb1-4ec8-b9f5-ce2205e83fb5@opensource.cirrus.com> (raw)
In-Reply-To: <4c407a93-7cb6-4a44-a7b6-4d972e714b4e@linux.intel.com>

On 05/08/2026 10:52 am, Péter Ujfalusi wrote:
> 
> 
> On 05/08/2026 12:38, Richard Fitzgerald wrote:
>> On 05/08/2026 10:25 am, Charles Keepax wrote:
>>> On Wed, Aug 05, 2026 at 12:10:10PM +0300, Péter Ujfalusi wrote:
>>>> On 05/08/2026 12:00, Richard Fitzgerald wrote:
>>>>>>> Found by an audit of all reg_defaults tables under sound/, the
>>>>>>> SoundWire
>>>>>>> codec drivers are fixed by a separate series.
>>>>>>
>>>>>> Wow. Would it make sense to have a regmap helper to double-check the
>>>>>> addresses are indeed in-order in those reg_default tables?
>>>>>> I am not sure how this requirement can be enforced by just
>>>>>> inspection, a
>>>>>> warning would help detect this sort of issues on more platforms.
>>>>>>
>>>>> It does seem probable that anything that relies on people just
>>>>> remembering to keep a large table sorted is prone to breaking,
>>>>> especially if the addresses are provided by named constant instead of
>>>>> a list of hardcoded numbers.
>>>>>
>>>>> Should regmap check the table when the regmap is first created?
>>>>> As it has to search the table during normal use anyway, one extra walk
>>>>> when the regmap is created probably isn't a serious overhead.
>>>>
>>>> But it will be done for _all_ devices which uses regmap on boot, small
>>>> things do add up, see my reply to Pierre-Louis.
>>>
>>> Indeed, if we were to add some sort of auto-checker it should
>>> be guarded behind something like perhaps a Kconfig option or the
>>> DEBUG define.
>>>
>>> Thanks,
>>> Charles
>>
>> regcache_init() already walks the defaults table checking the stride
>>
>>      for (i = 0; i < config->num_reg_defaults; i++)
>>          if (config->reg_defaults[i].reg % map->reg_stride)
>>              return -EINVAL;
>>
>> so checking that each entry is larger than previous is trivial extra
>> overhead. I think most regmaps are cached.
> 
> Right, I think this should work:
> 
> diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
> index aa8f2efed779..ce4b11d8a758 100644
> --- a/drivers/base/regmap/regcache.c
> +++ b/drivers/base/regmap/regcache.c
> @@ -123,6 +123,7 @@ static void regcache_hw_exit(struct regmap *map)
>   
>   int regcache_init(struct regmap *map, const struct regmap_config *config)
>   {
> +	bool sort_defaults = false;
>   	int count = 0;
>   	int ret;
>   	int i;
> @@ -149,10 +150,15 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
>   		return -EINVAL;
>   	}
>   
> -	for (i = 0; i < config->num_reg_defaults; i++)
> +	for (i = 0; i < config->num_reg_defaults; i++) {
>   		if (config->reg_defaults[i].reg % map->reg_stride)
>   			return -EINVAL;
>   
> +		if (i && config->reg_defaults[i - 1].reg >

You could test the stride of defaults[0] first before the loop, and
start the loop at i = 1. Then on each loop you can test [i] against
[i - 1] without the need to check i != 0 every time.

I don't think we need to sort them. Just fail, so that an unsorted table
must be fixed.


  reply	other threads:[~2026-08-05  9:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  8:24 [PATCH 0/3] ASoC: cs35l41/cs35l45/cs4265: sort the reg_defaults tables Peter Ujfalusi
2026-08-05  8:24 ` [PATCH 1/3] ASoC: cs35l41: sort the register default table Peter Ujfalusi
2026-08-05  9:58   ` Richard Fitzgerald
2026-08-05  8:24 ` [PATCH 2/3] ASoC: cs35l45: " Peter Ujfalusi
2026-08-05 11:35   ` Richard Fitzgerald
2026-08-05  8:24 ` [PATCH 3/3] ASoC: cs4265: " Peter Ujfalusi
2026-08-05 11:31   ` Richard Fitzgerald
2026-08-05  8:40 ` [PATCH 0/3] ASoC: cs35l41/cs35l45/cs4265: sort the reg_defaults tables Pierre-Louis Bossart
2026-08-05  8:52   ` Péter Ujfalusi
2026-08-05  8:59     ` Pierre-Louis Bossart
2026-08-05  9:00   ` Richard Fitzgerald
2026-08-05  9:10     ` Péter Ujfalusi
2026-08-05  9:25       ` Charles Keepax
2026-08-05  9:38         ` Richard Fitzgerald
2026-08-05  9:52           ` Charles Keepax
2026-08-05  9:52           ` Péter Ujfalusi
2026-08-05  9:56             ` Richard Fitzgerald [this message]
2026-08-05  9:59               ` Péter Ujfalusi
2026-08-05 10:10                 ` Charles Keepax
2026-08-05 10:17                   ` Péter Ujfalusi
2026-08-05 10:36                     ` Richard Fitzgerald
2026-08-05 11:25                       ` Péter Ujfalusi
2026-08-05 11:31                         ` Charles Keepax
2026-08-05 11:38                           ` Péter Ujfalusi
2026-08-05 11:38                           ` Richard Fitzgerald
2026-08-05  9:25     ` Péter Ujfalusi
2026-08-05 10:38   ` Mark Brown
2026-08-05  8:59 ` Charles Keepax
2026-08-05 12:37 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ffa045f4-dfb1-4ec8-b9f5-ce2205e83fb5@opensource.cirrus.com \
    --to=rf@opensource.cirrus.com \
    --cc=Paul.Handrigan@cirrus.com \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=david.rhodes@cirrus.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=vkarpovi@opensource.cirrus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox