Skip to content

Commit 0c02cac

Browse files
krzkbroonie
authored andcommitted
ASoC: codecs: lpass-rx-macro: Keep static regmap_config as const
The driver has static 'struct regmap_config', which is then customized depending on device version. This works fine, because there should not be two devices in a system simultaneously and even less likely that such two devices would have different versions, thus different regmap config. However code is cleaner and more obvious when static data in the driver is also const - it serves as a template. Mark the 'struct regmap_config' as const and duplicate it in the probe() with kmemdup to allow customizing per detected device variant. Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://patch.msgid.link/20240701-b4-qcom-audio-lpass-codec-cleanups-v3-3-6d98d4dd1ef5@linaro.org Signed-off-by: Mark Brown <[email protected]>
1 parent ee5e13b commit 0c02cac

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sound/soc/codecs/lpass-rx-macro.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ static bool rx_is_readable_register(struct device *dev, unsigned int reg)
16631663
return rx_is_rw_register(dev, reg);
16641664
}
16651665

1666-
static struct regmap_config rx_regmap_config = {
1666+
static const struct regmap_config rx_regmap_config = {
16671667
.name = "rx_macro",
16681668
.reg_bits = 16,
16691669
.val_bits = 32, /* 8 but with 32 bit read/write */
@@ -3847,10 +3847,16 @@ static int rx_macro_probe(struct platform_device *pdev)
38473847
return -EINVAL;
38483848
}
38493849

3850-
rx_regmap_config.reg_defaults = reg_defaults;
3851-
rx_regmap_config.num_reg_defaults = def_count;
3850+
struct regmap_config *reg_config __free(kfree) = kmemdup(&rx_regmap_config,
3851+
sizeof(*reg_config),
3852+
GFP_KERNEL);
3853+
if (!reg_config)
3854+
return -ENOMEM;
3855+
3856+
reg_config->reg_defaults = reg_defaults;
3857+
reg_config->num_reg_defaults = def_count;
38523858

3853-
rx->regmap = devm_regmap_init_mmio(dev, base, &rx_regmap_config);
3859+
rx->regmap = devm_regmap_init_mmio(dev, base, reg_config);
38543860
if (IS_ERR(rx->regmap))
38553861
return PTR_ERR(rx->regmap);
38563862

0 commit comments

Comments
 (0)