ASoC: rcar: add rsnd_is_accessible_reg()
Current rcar driver is supporting Gen1, and Gen2 will be supported soon. Then, some registers are used from Gen1 only, or from Gen2 only. To avoid NULL pointer access, this patch adds register accessible check function. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@linaro.org>
This commit is contained in:
parent
c1e6cc5e57
commit
42ee5d22e3
|
@ -86,12 +86,28 @@ static struct regmap_bus rsnd_regmap_bus = {
|
||||||
.val_format_endian_default = REGMAP_ENDIAN_NATIVE,
|
.val_format_endian_default = REGMAP_ENDIAN_NATIVE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int rsnd_is_accessible_reg(struct rsnd_priv *priv,
|
||||||
|
struct rsnd_gen *gen, enum rsnd_reg reg)
|
||||||
|
{
|
||||||
|
if (!gen->regs[reg]) {
|
||||||
|
struct device *dev = rsnd_priv_to_dev(priv);
|
||||||
|
|
||||||
|
dev_err(dev, "unsupported register access %x\n", reg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
u32 rsnd_read(struct rsnd_priv *priv,
|
u32 rsnd_read(struct rsnd_priv *priv,
|
||||||
struct rsnd_mod *mod, enum rsnd_reg reg)
|
struct rsnd_mod *mod, enum rsnd_reg reg)
|
||||||
{
|
{
|
||||||
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
||||||
u32 val;
|
u32 val;
|
||||||
|
|
||||||
|
if (!rsnd_is_accessible_reg(priv, gen, reg))
|
||||||
|
return 0;
|
||||||
|
|
||||||
regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val);
|
regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
@ -103,6 +119,9 @@ void rsnd_write(struct rsnd_priv *priv,
|
||||||
{
|
{
|
||||||
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
||||||
|
|
||||||
|
if (!rsnd_is_accessible_reg(priv, gen, reg))
|
||||||
|
return;
|
||||||
|
|
||||||
regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data);
|
regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +130,9 @@ void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
|
||||||
{
|
{
|
||||||
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
||||||
|
|
||||||
|
if (!rsnd_is_accessible_reg(priv, gen, reg))
|
||||||
|
return;
|
||||||
|
|
||||||
regmap_fields_update_bits(gen->regs[reg], rsnd_mod_id(mod),
|
regmap_fields_update_bits(gen->regs[reg], rsnd_mod_id(mod),
|
||||||
mask, data);
|
mask, data);
|
||||||
}
|
}
|
||||||
|
@ -134,6 +156,10 @@ static int rsnd_gen_regmap_init(struct rsnd_priv *priv,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < RSND_REG_MAX; i++) {
|
for (i = 0; i < RSND_REG_MAX; i++) {
|
||||||
|
gen->regs[i] = NULL;
|
||||||
|
if (!regf[i].reg)
|
||||||
|
continue;
|
||||||
|
|
||||||
gen->regs[i] = devm_regmap_field_alloc(dev, gen->regmap, regf[i]);
|
gen->regs[i] = devm_regmap_field_alloc(dev, gen->regmap, regf[i]);
|
||||||
if (IS_ERR(gen->regs[i]))
|
if (IS_ERR(gen->regs[i]))
|
||||||
return PTR_ERR(gen->regs[i]);
|
return PTR_ERR(gen->regs[i]);
|
||||||
|
|
Loading…
Reference in New Issue