Commit ad2457894c272279bf73ca46ae5ea5de4876d2a0

Authored by Daniel Mack
Committed by David Woodhouse
1 parent 0cca9fbf5d

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>

Showing 3 changed files with 12 additions and 4 deletions Side-by-side Diff

drivers/mtd/devices/elm.c
... ... @@ -81,14 +81,21 @@
81 81 * @dev: ELM device
82 82 * @bch_type: Type of BCH ecc
83 83 */
84   -void elm_config(struct device *dev, enum bch_ecc bch_type)
  84 +int elm_config(struct device *dev, enum bch_ecc bch_type)
85 85 {
86 86 u32 reg_val;
87 87 struct elm_info *info = dev_get_drvdata(dev);
88 88  
  89 + if (!info) {
  90 + dev_err(dev, "Unable to configure elm - device not probed?\n");
  91 + return -ENODEV;
  92 + }
  93 +
89 94 reg_val = (bch_type & ECC_BCH_LEVEL_MASK) | (ELM_ECC_SIZE << 16);
90 95 elm_write_reg(info, ELM_LOCATION_CONFIG, reg_val);
91 96 info->bch_type = bch_type;
  97 +
  98 + return 0;
92 99 }
93 100 EXPORT_SYMBOL(elm_config);
94 101  
drivers/mtd/nand/omap2.c
... ... @@ -1701,8 +1701,9 @@
1701 1701 elm_node = of_find_node_by_phandle(be32_to_cpup(parp));
1702 1702 pdev = of_find_device_by_node(elm_node);
1703 1703 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;
1706 1707 }
1707 1708  
1708 1709 if (info->is_elm_used && (mtd->writesize <= 4096)) {
include/linux/platform_data/elm.h
... ... @@ -50,6 +50,6 @@
50 50  
51 51 void elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc,
52 52 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);
54 54 #endif /* __ELM_H */