Skip to content

Commit ad24578

Browse files
zonqueDavid Woodhouse
authored andcommitted
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. Signed-off-by: Daniel Mack <zonque@gmail.com> Acked-by: Peter Korsgaard <jacmet@sunsite.dk> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 0cca9fb commit ad24578

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎drivers/mtd/devices/elm.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,21 @@ static u32 elm_read_reg(struct elm_info *info, int offset)
8181
* @dev: ELM device
8282
* @bch_type: Type of BCH ecc
8383
*/
84-
void elm_config(struct device *dev, enum bch_ecc bch_type)
84+
int elm_config(struct device *dev, enum bch_ecc bch_type)
8585
{
8686
u32 reg_val;
8787
struct elm_info *info = dev_get_drvdata(dev);
8888

89+
if (!info) {
90+
dev_err(dev, "Unable to configure elm - device not probed?\n");
91+
return -ENODEV;
92+
}
93+
8994
reg_val = (bch_type & ECC_BCH_LEVEL_MASK) | (ELM_ECC_SIZE << 16);
9095
elm_write_reg(info, ELM_LOCATION_CONFIG, reg_val);
9196
info->bch_type = bch_type;
97+
98+
return 0;
9299
}
93100
EXPORT_SYMBOL(elm_config);
94101

‎drivers/mtd/nand/omap2.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,9 @@ static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt)
17011701
elm_node = of_find_node_by_phandle(be32_to_cpup(parp));
17021702
pdev = of_find_device_by_node(elm_node);
17031703
info->elm_dev = &pdev->dev;
1704-
elm_config(info->elm_dev, bch_type);
1705-
info->is_elm_used = true;
1704+
1705+
if (elm_config(info->elm_dev, bch_type) == 0)
1706+
info->is_elm_used = true;
17061707
}
17071708

17081709
if (info->is_elm_used && (mtd->writesize <= 4096)) {

‎include/linux/platform_data/elm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ struct elm_errorvec {
5050

5151
void elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc,
5252
struct elm_errorvec *err_vec);
53-
void elm_config(struct device *dev, enum bch_ecc bch_type);
53+
int elm_config(struct device *dev, enum bch_ecc bch_type);
5454
#endif /* __ELM_H */

0 commit comments

Comments
 (0)