summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBen Gardiner <bengardiner@nanometrics.ca>2010-08-31 17:48:00 -0400
committerScott Wood <scottwood@freescale.com>2010-10-11 15:11:00 -0500
commit0a026d3e86f3981f6fc4f6d634708442f65873e5 (patch)
tree4047d5db5c15a9dfc11794cd20566b2dce70a390 /common
parent5b8e6bb517ea4f6d8ba9fa11c84e0373bc7ead2c (diff)
downloadtalos-obmc-uboot-0a026d3e86f3981f6fc4f6d634708442f65873e5.tar.gz
talos-obmc-uboot-0a026d3e86f3981f6fc4f6d634708442f65873e5.zip
mtdparts: regroup calls to get_mtd_device_nm
The get_mtd_device_nm function is called in a couple places and the string that is passed to it is not really used after the calls. This patch regroups the calls to this function into a new function, get_mtd_info. Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca> Acked-by: Stefan Roese <sr@denx.de> CC: Wolfgang Denk <wd@denx.de>
Diffstat (limited to 'common')
-rw-r--r--common/cmd_mtdparts.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index ceec5a9751..772ad54519 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -286,6 +286,29 @@ static void current_save(void)
index_partitions();
}
+
+/**
+ * Produce a mtd_info given a type and num.
+ *
+ * @param type mtd type
+ * @param num mtd number
+ * @param mtd a pointer to an mtd_info instance (output)
+ * @return 0 if device is valid, 1 otherwise
+ */
+static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
+{
+ char mtd_dev[16];
+
+ sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
+ *mtd = get_mtd_device_nm(mtd_dev);
+ if (IS_ERR(*mtd)) {
+ printf("Device %s not found!\n", mtd_dev);
+ return 1;
+ }
+
+ return 0;
+}
+
/**
* Performs sanity check for supplied flash partition.
* Table of existing MTD flash devices is searched and partition device
@@ -297,17 +320,12 @@ static void current_save(void)
*/
static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
{
- struct mtd_info *mtd;
- char mtd_dev[16];
+ struct mtd_info *mtd = NULL;
int i, j;
ulong start;
- sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(id->type), id->num);
- mtd = get_mtd_device_nm(mtd_dev);
- if (IS_ERR(mtd)) {
- printf("Partition %s not found on device %s!\n", part->name, mtd_dev);
+ if (get_mtd_info(id->type, id->num, &mtd))
return 1;
- }
part->sector_size = mtd->erasesize;
@@ -684,20 +702,17 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
/**
* Check device number to be within valid range for given device type.
*
- * @param dev device to validate
+ * @param type mtd type
+ * @param num mtd number
+ * @param size a pointer to the size of the mtd device (output)
* @return 0 if device is valid, 1 otherwise
*/
int mtd_device_validate(u8 type, u8 num, u32 *size)
{
- struct mtd_info *mtd;
- char mtd_dev[16];
+ struct mtd_info *mtd = NULL;
- sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
- mtd = get_mtd_device_nm(mtd_dev);
- if (IS_ERR(mtd)) {
- printf("Device %s not found!\n", mtd_dev);
+ if (get_mtd_info(type, num, &mtd))
return 1;
- }
*size = mtd->size;
OpenPOWER on IntegriCloud