mtd: devices: elm: check for device's presence before configuration
Subsystems (2)
PATCH v2 1/1 mtd: devices: elm: check for device's presence before configuration
In case the driver is not probed - due to config mismatches or errors in the DTS files - dev_get_drvdata() returns NULL, leading to an Ooops during boot.
Make elm_config() return an error in such cases to propagate the error up to the user, so it can fall back to software mode.
--- drivers/mtd/devices/elm.c | 9 ++++++++- drivers/mtd/nand/omap2.c | 5 +++-- include/linux/platform_data/elm.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-)
drivers/mtd/devices/elm.c +8 -1
@@ -81,14 +81,21 @@ static u32 elm_read_reg(struct elm_info *info, int offset)* @dev: ELM device * @bch_type: Type of BCH ecc */ -void elm_config (struct device *dev,enum bch_ecc bch_type) +int elm_config (struct device *dev,enum bch_ecc bch_type) {u32 reg_val;struct elm_info *info =dev_get_drvdata (dev); +if (!info) { +dev_err (dev,"Unable to configure elm - device not probed?\n" ); +return -ENODEV ; + } + reg_val = (bch_type &ECC_BCH_LEVEL_MASK ) | (ELM_ECC_SIZE <<16 );elm_write_reg (info,ELM_LOCATION_CONFIG , reg_val); info->bch_type = bch_type; + +return 0 ; }EXPORT_SYMBOL (elm_config);
drivers/mtd/nand/omap2.c +3 -2
@@ -1701,8 +1701,9 @@ static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt) elm_node =of_find_node_by_phandle (be32_to_cpup (parp)); pdev =of_find_device_by_node (elm_node); info->elm_dev = &pdev->dev; -elm_config (info->elm_dev, bch_type); - info->is_elm_used = true; + +if (elm_config (info->elm_dev, bch_type) ==0 ) + info->is_elm_used = true; }if (info->is_elm_used && (mtd->writesize <=4096 )) {
include/linux/platform_data/elm.h +1 -1
@@ -50,5 +50,5 @@ struct elm_errorvec {void elm_decode_bch_error_page (struct device *dev,u8 *ecc_calc,struct elm_errorvec *err_vec); -void elm_config (struct device *dev,enum bch_ecc bch_type); +int elm_config (struct device *dev,enum bch_ecc bch_type);#endif /* __ELM_H */
Signature · 1 line
1.8.1.4
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Daniel" == Daniel Mack <[email protected]> writes:
Daniel> In case the driver is not probed - due to config mismatches or errors Daniel> in the DTS files - dev_get_drvdata() returns NULL, leading to an Ooops Daniel> during boot.
Daniel> Make elm_config() return an error in such cases to propagate the error Daniel> up to the user, so it can fall back to software mode.
Daniel> Signed-off-by: Daniel Mack <[email protected]> Daniel> Cc: Philip Avinash <[email protected]> Daniel> Cc: Artem Bityutskiy <[email protected]> Daniel> Cc: Peter Korsgaard <[email protected]>
Signature · 1 line
Bye, Peter Korsgaard
Quoted 9 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Daniel" == Daniel Mack <[email protected]> writes:
Daniel> In case the driver is not probed - due to config mismatches or errors Daniel> in the DTS files -
dev_get_drvdata()returns NULL, leading to an Ooops Daniel> during boot.Daniel> Make
elm_config()return an error in such cases to propagate the error Daniel> up to the user, so it can fall back to software mode.
Quoted 6 lines
Daniel> Signed-off-by: Daniel Mack <[email protected]> Daniel> Cc: Philip Avinash <[email protected]> Daniel> Cc: Artem Bityutskiy <[email protected]> Daniel> Cc: Peter Korsgaard <[email protected]>
Acked-by Peter Korsgaard <[email protected]>
Philip, are you also ok with this?
Thanks,
Daniel
Quoted 10 lines · Daniel Mack
Quoted 9 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Daniel" == Daniel Mack <[email protected]> writes:
Daniel> In case the driver is not probed - due to config mismatches or errors Daniel> in the DTS files -
dev_get_drvdata()returns NULL, leading to an Ooops Daniel> during boot.Daniel> Make
elm_config()return an error in such cases to propagate the error Daniel> up to the user, so it can fall back to software mode.
Quoted 8 lines
Quoted 6 lines
Daniel> Signed-off-by: Daniel Mack <[email protected]> Daniel> Cc: Philip Avinash <[email protected]> Daniel> Cc: Artem Bityutskiy <[email protected]> Daniel> Cc: Peter Korsgaard <[email protected]>
Acked-by Peter Korsgaard <[email protected]>Philip, are you also ok with this?
Yes.
Thanks
Avinash
Quoted 6 lines
Thanks,
Daniel
Quoted 16 lines · Avinash
Quoted 15 lines · Daniel Mack
Quoted 14 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Daniel" == Daniel Mack <[email protected]> writes:
Daniel> In case the driver is not probed - due to config mismatches or errors Daniel> in the DTS files -
dev_get_drvdata()returns NULL, leading to an Ooops Daniel> during boot.Daniel> Make
elm_config()return an error in such cases to propagate the error Daniel> up to the user, so it can fall back to software mode.Daniel> Signed-off-by: Daniel Mack <[email protected]> Daniel> Cc: Philip Avinash <[email protected]> Daniel> Cc: Artem Bityutskiy <[email protected]> Daniel> Cc: Peter Korsgaard <[email protected]>
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Acked-by Peter Korsgaard <[email protected]>Philip, are you also ok with this?
Yes.
Thanks
Avinash
Artem, can this go through your tree?
Thanks, everyone.
Daniel
Artem Bityutskiy
AppliedQuoted 8 lines · Daniel Mack
In case the driver is not probed - due to config mismatches or errors in the DTS files -
dev_get_drvdata()returns NULL, leading to an Ooops during boot.Make
elm_config()return an error in such cases to propagate the error up to the user, so it can fall back to software mode.Signed-off-by Daniel Mack <[email protected]>
Pushed to l2-mtd.git, thanks!
Signature · 2 lines
Best Regards, Artem Bityutskiy