mtd: devices: elm: check for device's presence before configuration
authorDaniel Mack <zonque@gmail.com>
Sun, 3 Mar 2013 23:57:20 +0000 (00:57 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 5 Apr 2013 11:57:18 +0000 (12:57 +0100)
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>
drivers/mtd/devices/elm.c
drivers/mtd/nand/omap2.c
include/linux/platform_data/elm.h

index 2ec5da9ee24826a0790399e24cb6271891889cf8..dccef9fdc1f276269566bcc4ba03ae6e7a87111d 100644 (file)
@@ -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);
 
index 8e820ddf4e085ba0091c7238085395b40c4b0c39..b97ef3b68ec69f14a85180bcebc0897afcda6be8 100644 (file)
@@ -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)) {
index 1bd5244d1dcd0720d878de32059867f125ab803e..bf0a83b7ed9d3e0538cc09c57f7d498065931501 100644 (file)
@@ -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 */