[PATCH 1/1] blk: simplify blk_get_devnum_by_typename()

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Sat Oct 23 16:06:47 CEST 2021


The block descriptor contains the if_type. There is no need to first look
up the uclass for the if_type and then to check the parent device's uclass
to know if the device has the correct if_type.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 drivers/block/blk-uclass.c | 35 +----------------------------------
 1 file changed, 1 insertion(+), 34 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 83682dcc18..b32067f957 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -33,22 +33,6 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
 	[IF_TYPE_PVBLOCK]	= "pvblock",
 };
 
-static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
-	[IF_TYPE_IDE]		= UCLASS_IDE,
-	[IF_TYPE_SCSI]		= UCLASS_SCSI,
-	[IF_TYPE_ATAPI]		= UCLASS_INVALID,
-	[IF_TYPE_USB]		= UCLASS_MASS_STORAGE,
-	[IF_TYPE_DOC]		= UCLASS_INVALID,
-	[IF_TYPE_MMC]		= UCLASS_MMC,
-	[IF_TYPE_SD]		= UCLASS_INVALID,
-	[IF_TYPE_SATA]		= UCLASS_AHCI,
-	[IF_TYPE_HOST]		= UCLASS_ROOT,
-	[IF_TYPE_NVME]		= UCLASS_NVME,
-	[IF_TYPE_EFI]		= UCLASS_EFI,
-	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
-	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
-};
-
 static enum if_type if_typename_to_iftype(const char *if_typename)
 {
 	int i;
@@ -62,11 +46,6 @@ static enum if_type if_typename_to_iftype(const char *if_typename)
 	return IF_TYPE_UNKNOWN;
 }
 
-static enum uclass_id if_type_to_uclass_id(enum if_type if_type)
-{
-	return if_type_uclass_id[if_type];
-}
-
 const char *blk_get_if_type_name(enum if_type if_type)
 {
 	return if_typename_str[if_type];
@@ -93,7 +72,6 @@ struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum)
  */
 struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
 {
-	enum uclass_id uclass_id;
 	enum if_type if_type;
 	struct udevice *dev;
 	struct uclass *uc;
@@ -105,12 +83,6 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
 		      if_typename);
 		return NULL;
 	}
-	uclass_id = if_type_to_uclass_id(if_type);
-	if (uclass_id == UCLASS_INVALID) {
-		debug("%s: Unknown uclass for interface type'\n",
-		      if_typename_str[if_type]);
-		return NULL;
-	}
 
 	ret = uclass_get(UCLASS_BLK, &uc);
 	if (ret)
@@ -122,13 +94,8 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
 		      if_type, devnum, dev->name, desc->if_type, desc->devnum);
 		if (desc->devnum != devnum)
 			continue;
-
-		/* Find out the parent device uclass */
-		if (device_get_uclass_id(dev->parent) != uclass_id) {
-			debug("%s: parent uclass %d, this dev %d\n", __func__,
-			      device_get_uclass_id(dev->parent), uclass_id);
+		if (desc->if_type != if_type)
 			continue;
-		}
 
 		if (device_probe(dev))
 			return NULL;
-- 
2.32.0



More information about the U-Boot mailing list