summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
authorKever Yang <kever.yang@rock-chips.com>2018-02-10 17:55:38 +0800
committerTom Rini <trini@konsulko.com>2018-03-13 21:58:45 -0400
commit56670d6fb83f3c2f8d9285cc97506541471b43c9 (patch)
tree22bb6f116763f9aef3952deeaeb0e829d726134b /disk
parentd47292691977fd77f02af44359594e46411f4a63 (diff)
disk: part: use common api to lookup part driver
Do not need to scan disk every time when we get part info by name. Signed-off-by: Kever Yang <kever.yang@rock-chips.com> [trini: Fix build in !CONFIG_HAVE_BLOCK_DEVICE case] Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'disk')
-rw-r--r--disk/part.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/disk/part.c b/disk/part.c
index 16de7a2c31..44ef14dc54 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -26,7 +26,6 @@
DECLARE_GLOBAL_DATA_PTR;
-#ifdef CONFIG_HAVE_BLOCK_DEVICE
static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
{
struct part_driver *drv =
@@ -55,6 +54,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
return NULL;
}
+#ifdef CONFIG_HAVE_BLOCK_DEVICE
static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
{
struct blk_desc *dev_desc;
@@ -644,28 +644,25 @@ cleanup:
int part_get_info_by_name_type(struct blk_desc *dev_desc, const char *name,
disk_partition_t *info, int part_type)
{
- struct part_driver *first_drv =
- ll_entry_start(struct part_driver, part_driver);
- const int n_drvs = ll_entry_count(struct part_driver, part_driver);
struct part_driver *part_drv;
-
- for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) {
- int ret;
- int i;
- for (i = 1; i < part_drv->max_entries; i++) {
- if (part_type >= 0 && part_type != part_drv->part_type)
- break;
- ret = part_drv->get_info(dev_desc, i, info);
- if (ret != 0) {
- /* no more entries in table */
- break;
- }
- if (strcmp(name, (const char *)info->name) == 0) {
- /* matched */
- return i;
- }
+ int ret;
+ int i;
+
+ part_drv = part_driver_lookup_type(dev_desc);
+ if (!part_drv)
+ return -1;
+ for (i = 1; i < part_drv->max_entries; i++) {
+ ret = part_drv->get_info(dev_desc, i, info);
+ if (ret != 0) {
+ /* no more entries in table */
+ break;
+ }
+ if (strcmp(name, (const char *)info->name) == 0) {
+ /* matched */
+ return i;
}
}
+
return -1;
}