memory: stm32-fmc2-ebi: check regmap_read return value
[ Upstream commit 722463f73b
]
Check regmap_read return value to avoid to use uninitialized local
variables.
Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com>
Link: https://lore.kernel.org/r/20240226101428.37791-3-christophe.kerello@foss.st.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
1a45994fb2
commit
0f7acd8cef
|
@ -181,8 +181,11 @@ static int stm32_fmc2_ebi_check_mux(struct stm32_fmc2_ebi *ebi,
|
|||
int cs)
|
||||
{
|
||||
u32 bcr;
|
||||
int ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (bcr & FMC2_BCR_MTYP)
|
||||
return 0;
|
||||
|
@ -195,8 +198,11 @@ static int stm32_fmc2_ebi_check_waitcfg(struct stm32_fmc2_ebi *ebi,
|
|||
int cs)
|
||||
{
|
||||
u32 bcr, val = FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR);
|
||||
int ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if ((bcr & FMC2_BCR_MTYP) == val && bcr & FMC2_BCR_BURSTEN)
|
||||
return 0;
|
||||
|
@ -209,8 +215,11 @@ static int stm32_fmc2_ebi_check_sync_trans(struct stm32_fmc2_ebi *ebi,
|
|||
int cs)
|
||||
{
|
||||
u32 bcr;
|
||||
int ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (bcr & FMC2_BCR_BURSTEN)
|
||||
return 0;
|
||||
|
@ -223,8 +232,11 @@ static int stm32_fmc2_ebi_check_async_trans(struct stm32_fmc2_ebi *ebi,
|
|||
int cs)
|
||||
{
|
||||
u32 bcr;
|
||||
int ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!(bcr & FMC2_BCR_BURSTEN) || !(bcr & FMC2_BCR_CBURSTRW))
|
||||
return 0;
|
||||
|
@ -237,8 +249,11 @@ static int stm32_fmc2_ebi_check_cpsize(struct stm32_fmc2_ebi *ebi,
|
|||
int cs)
|
||||
{
|
||||
u32 bcr, val = FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_PSRAM);
|
||||
int ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if ((bcr & FMC2_BCR_MTYP) == val && bcr & FMC2_BCR_BURSTEN)
|
||||
return 0;
|
||||
|
@ -251,12 +266,18 @@ static int stm32_fmc2_ebi_check_address_hold(struct stm32_fmc2_ebi *ebi,
|
|||
int cs)
|
||||
{
|
||||
u32 bcr, bxtr, val = FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_D);
|
||||
int ret;
|
||||
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (prop->reg_type == FMC2_REG_BWTR)
|
||||
regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr);
|
||||
else
|
||||
regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if ((!(bcr & FMC2_BCR_BURSTEN) || !(bcr & FMC2_BCR_CBURSTRW)) &&
|
||||
((bxtr & FMC2_BXTR_ACCMOD) == val || bcr & FMC2_BCR_MUXEN))
|
||||
|
@ -270,12 +291,19 @@ static int stm32_fmc2_ebi_check_clk_period(struct stm32_fmc2_ebi *ebi,
|
|||
int cs)
|
||||
{
|
||||
u32 bcr, bcr1;
|
||||
int ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (cs)
|
||||
regmap_read(ebi->regmap, FMC2_BCR1, &bcr1);
|
||||
else
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (cs) {
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR1, &bcr1);
|
||||
if (ret)
|
||||
return ret;
|
||||
} else {
|
||||
bcr1 = bcr;
|
||||
}
|
||||
|
||||
if (bcr & FMC2_BCR_BURSTEN && (!cs || !(bcr1 & FMC2_BCR1_CCLKEN)))
|
||||
return 0;
|
||||
|
@ -307,12 +335,18 @@ static u32 stm32_fmc2_ebi_ns_to_clk_period(struct stm32_fmc2_ebi *ebi,
|
|||
{
|
||||
u32 nb_clk_cycles = stm32_fmc2_ebi_ns_to_clock_cycles(ebi, cs, setup);
|
||||
u32 bcr, btr, clk_period;
|
||||
int ret;
|
||||
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR1, &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR1, &bcr);
|
||||
if (bcr & FMC2_BCR1_CCLKEN || !cs)
|
||||
regmap_read(ebi->regmap, FMC2_BTR1, &btr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BTR1, &btr);
|
||||
else
|
||||
regmap_read(ebi->regmap, FMC2_BTR(cs), &btr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BTR(cs), &btr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
clk_period = FIELD_GET(FMC2_BTR_CLKDIV, btr) + 1;
|
||||
|
||||
|
@ -571,11 +605,16 @@ static int stm32_fmc2_ebi_set_address_setup(struct stm32_fmc2_ebi *ebi,
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (prop->reg_type == FMC2_REG_BWTR)
|
||||
regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr);
|
||||
else
|
||||
regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if ((bxtr & FMC2_BXTR_ACCMOD) == val || bcr & FMC2_BCR_MUXEN)
|
||||
val = clamp_val(setup, 1, FMC2_BXTR_ADDSET_MAX);
|
||||
|
@ -693,11 +732,14 @@ static int stm32_fmc2_ebi_set_max_low_pulse(struct stm32_fmc2_ebi *ebi,
|
|||
int cs, u32 setup)
|
||||
{
|
||||
u32 old_val, new_val, pcscntr;
|
||||
int ret;
|
||||
|
||||
if (setup < 1)
|
||||
return 0;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_PCSCNTR, &pcscntr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_PCSCNTR, &pcscntr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Enable counter for the bank */
|
||||
regmap_update_bits(ebi->regmap, FMC2_PCSCNTR,
|
||||
|
@ -944,17 +986,20 @@ static void stm32_fmc2_ebi_disable_bank(struct stm32_fmc2_ebi *ebi, int cs)
|
|||
regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_MBKEN, 0);
|
||||
}
|
||||
|
||||
static void stm32_fmc2_ebi_save_setup(struct stm32_fmc2_ebi *ebi)
|
||||
static int stm32_fmc2_ebi_save_setup(struct stm32_fmc2_ebi *ebi)
|
||||
{
|
||||
unsigned int cs;
|
||||
int ret;
|
||||
|
||||
for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) {
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &ebi->bcr[cs]);
|
||||
regmap_read(ebi->regmap, FMC2_BTR(cs), &ebi->btr[cs]);
|
||||
regmap_read(ebi->regmap, FMC2_BWTR(cs), &ebi->bwtr[cs]);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &ebi->bcr[cs]);
|
||||
ret |= regmap_read(ebi->regmap, FMC2_BTR(cs), &ebi->btr[cs]);
|
||||
ret |= regmap_read(ebi->regmap, FMC2_BWTR(cs), &ebi->bwtr[cs]);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_PCSCNTR, &ebi->pcscntr);
|
||||
return regmap_read(ebi->regmap, FMC2_PCSCNTR, &ebi->pcscntr);
|
||||
}
|
||||
|
||||
static void stm32_fmc2_ebi_set_setup(struct stm32_fmc2_ebi *ebi)
|
||||
|
@ -983,22 +1028,29 @@ static void stm32_fmc2_ebi_disable_banks(struct stm32_fmc2_ebi *ebi)
|
|||
}
|
||||
|
||||
/* NWAIT signal can not be connected to EBI controller and NAND controller */
|
||||
static bool stm32_fmc2_ebi_nwait_used_by_ctrls(struct stm32_fmc2_ebi *ebi)
|
||||
static int stm32_fmc2_ebi_nwait_used_by_ctrls(struct stm32_fmc2_ebi *ebi)
|
||||
{
|
||||
struct device *dev = ebi->dev;
|
||||
unsigned int cs;
|
||||
u32 bcr;
|
||||
int ret;
|
||||
|
||||
for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) {
|
||||
if (!(ebi->bank_assigned & BIT(cs)))
|
||||
continue;
|
||||
|
||||
regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if ((bcr & FMC2_BCR_WAITEN || bcr & FMC2_BCR_ASYNCWAIT) &&
|
||||
ebi->bank_assigned & BIT(FMC2_NAND))
|
||||
return true;
|
||||
ebi->bank_assigned & BIT(FMC2_NAND)) {
|
||||
dev_err(dev, "NWAIT signal connected to EBI and NAND controllers\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void stm32_fmc2_ebi_enable(struct stm32_fmc2_ebi *ebi)
|
||||
|
@ -1085,10 +1137,9 @@ static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi)
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (stm32_fmc2_ebi_nwait_used_by_ctrls(ebi)) {
|
||||
dev_err(dev, "NWAIT signal connected to EBI and NAND controllers\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = stm32_fmc2_ebi_nwait_used_by_ctrls(ebi);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
stm32_fmc2_ebi_enable(ebi);
|
||||
|
||||
|
@ -1133,7 +1184,10 @@ static int stm32_fmc2_ebi_probe(struct platform_device *pdev)
|
|||
if (ret)
|
||||
goto err_release;
|
||||
|
||||
stm32_fmc2_ebi_save_setup(ebi);
|
||||
ret = stm32_fmc2_ebi_save_setup(ebi);
|
||||
if (ret)
|
||||
goto err_release;
|
||||
|
||||
platform_set_drvdata(pdev, ebi);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue