summaryrefslogtreecommitdiff
path: root/drivers/block
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-04-23 20:02:06 -0600
committerSimon Glass <sjg@chromium.org>2017-06-01 07:03:05 -0600
commite8abbb531f506dc0cac973b86fb5fa01f0bf88c4 (patch)
treef5f7afe02aa27b986da021ab252bf97e69ec2b74 /drivers/block
parent6139281a6473334351c8776643478c0b0e208342 (diff)
dm: blk: Add a function to find the next block device number
At present this code is inline. Move it into a function to allow it to be used elsewhere. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/blk-uclass.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 8b6b28d890..881c39f774 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -473,6 +473,19 @@ int blk_find_max_devnum(enum if_type if_type)
return max_devnum;
}
+static int blk_next_free_devnum(enum if_type if_type)
+{
+ int ret;
+
+ ret = blk_find_max_devnum(if_type);
+ if (ret == -ENODEV)
+ return 0;
+ if (ret < 0)
+ return ret;
+
+ return ret + 1;
+}
+
int blk_create_device(struct udevice *parent, const char *drv_name,
const char *name, int if_type, int devnum, int blksz,
lbaint_t size, struct udevice **devp)
@@ -482,13 +495,10 @@ int blk_create_device(struct udevice *parent, const char *drv_name,
int ret;
if (devnum == -1) {
- ret = blk_find_max_devnum(if_type);
- if (ret == -ENODEV)
- devnum = 0;
- else if (ret < 0)
+ ret = blk_next_free_devnum(if_type);
+ if (ret < 0)
return ret;
- else
- devnum = ret + 1;
+ devnum = ret;
}
ret = device_bind_driver(parent, drv_name, name, &dev);
if (ret)