board: toradex: common: fail gracefully on missing NAND chip
authorStefan Agner <stefan.agner@toradex.com>
Mon, 6 Aug 2018 07:19:18 +0000 (09:19 +0200)
committerStefano Babic <sbabic@denx.de>
Tue, 4 Sep 2018 06:47:23 +0000 (08:47 +0200)
If the NAND chip is missing get_nand_dev_by_index() returns NULL. Fail
gracefully in this case.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
board/toradex/common/tdx-cfg-block.c

index 57edb6c5c948cec607d4bcfb5a844b188c7cfc8f..d4f5b1803ad68fb376020a0df800f7bbc14936ea 100644 (file)
@@ -156,10 +156,13 @@ out:
 static int read_tdx_cfg_block_from_nand(unsigned char *config_block)
 {
        size_t size = TDX_CFG_BLOCK_MAX_SIZE;
+       struct mtd_info *mtd = get_nand_dev_by_index(0);
+
+       if (!mtd)
+               return -ENODEV;
 
        /* Read production parameter config block from NAND page */
-       return nand_read_skip_bad(get_nand_dev_by_index(0),
-                                 CONFIG_TDX_CFG_BLOCK_OFFSET,
+       return nand_read_skip_bad(mtd, CONFIG_TDX_CFG_BLOCK_OFFSET,
                                  &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
                                  config_block);
 }