* disk/ieee1275/nand.c (grub_nand_iterate): Return

grub_devalias_iterate() result instead of unconditional 0.
	* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Likewise.
	Also, capture hook return value, either directly or via
	grub_children_iterate(), and propagate to caller.
	* include/grub/ieee1275/ieee1275.h (grub_devalias_iterate,
	grub_children_iterate): Return value is now 'int' instead of
	'grub_err_t'.
	* kern/ieee1275/openfw.c (grub_children_iterate): Fix to behave
	like a proper iterator, stopping when hooks return non-zero.
	(grub_devalias_iterate): Likewise.
This commit is contained in:
davem 2009-04-24 12:05:54 +00:00
parent ac20caff54
commit 0dcf7495d9
5 changed files with 44 additions and 26 deletions

View file

@ -9,6 +9,18 @@
* disk/fs_uuid.c (grub_fs_uuid_close): Call grub_disk_close() * disk/fs_uuid.c (grub_fs_uuid_close): Call grub_disk_close()
on disk->data. on disk->data.
* disk/ieee1275/nand.c (grub_nand_iterate): Return
grub_devalias_iterate() result instead of unconditional 0.
* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Likewise.
Also, capture hook return value, either directly or via
grub_children_iterate(), and propagate to caller.
* include/grub/ieee1275/ieee1275.h (grub_devalias_iterate,
grub_children_iterate): Return value is now 'int' instead of
'grub_err_t'.
* kern/ieee1275/openfw.c (grub_children_iterate): Fix to behave
like a proper iterator, stopping when hooks return non-zero.
(grub_devalias_iterate): Likewise.
2009-04-23 David S. Miller <davem@davemloft.net> 2009-04-23 David S. Miller <davem@davemloft.net>
* kern/sparc64/ieee1275/openfw.c: Unused, delete. * kern/sparc64/ieee1275/openfw.c: Unused, delete.

View file

@ -44,8 +44,7 @@ grub_nand_iterate (int (*hook) (const char *name))
return 0; return 0;
} }
grub_devalias_iterate (dev_iterate); return grub_devalias_iterate (dev_iterate);
return 0;
} }
static grub_err_t static grub_err_t

View file

@ -77,6 +77,8 @@ grub_ofdisk_iterate (int (*hook) (const char *name))
int dev_iterate (struct grub_ieee1275_devalias *alias) int dev_iterate (struct grub_ieee1275_devalias *alias)
{ {
int ret = 0;
grub_dprintf ("disk", "disk name = %s\n", alias->name); grub_dprintf ("disk", "disk name = %s\n", alias->name);
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY)) if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY))
@ -105,17 +107,16 @@ grub_ofdisk_iterate (int (*hook) (const char *name))
} }
if (! grub_strcmp (alias->type, "block")) if (! grub_strcmp (alias->type, "block"))
hook (alias->name); ret = hook (alias->name);
else if ((! grub_strcmp (alias->type, "scsi")) else if ((! grub_strcmp (alias->type, "scsi"))
|| (! grub_strcmp (alias->type, "ide")) || (! grub_strcmp (alias->type, "ide"))
|| (! grub_strcmp (alias->type, "ata"))) || (! grub_strcmp (alias->type, "ata")))
/* Search for block-type children of these bus controllers. */ /* Search for block-type children of these bus controllers. */
grub_children_iterate (alias->name, dev_iterate); ret = grub_children_iterate (alias->name, dev_iterate);
return 0; return ret;
} }
grub_devalias_iterate (dev_iterate); return grub_devalias_iterate (dev_iterate);
return 0;
} }
static grub_err_t static grub_err_t

View file

@ -166,9 +166,9 @@ int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs); int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs);
grub_err_t EXPORT_FUNC(grub_devalias_iterate) int EXPORT_FUNC(grub_devalias_iterate)
(int (*hook) (struct grub_ieee1275_devalias *alias)); (int (*hook) (struct grub_ieee1275_devalias *alias));
grub_err_t EXPORT_FUNC(grub_children_iterate) (char *devpath, int EXPORT_FUNC(grub_children_iterate) (char *devpath,
int (*hook) (struct grub_ieee1275_devalias *alias)); int (*hook) (struct grub_ieee1275_devalias *alias));
grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate)
(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));

View file

@ -32,36 +32,37 @@ enum grub_ieee1275_parse_type
}; };
/* Walk children of 'devpath', calling hook for each. */ /* Walk children of 'devpath', calling hook for each. */
grub_err_t int
grub_children_iterate (char *devpath, grub_children_iterate (char *devpath,
int (*hook) (struct grub_ieee1275_devalias *alias)) int (*hook) (struct grub_ieee1275_devalias *alias))
{ {
grub_ieee1275_phandle_t dev; grub_ieee1275_phandle_t dev;
grub_ieee1275_phandle_t child; grub_ieee1275_phandle_t child;
char *childtype, *childpath; char *childtype, *childpath;
char *childname, *fullname; char *childname, *fullname;
int ret = 0;
if (grub_ieee1275_finddevice (devpath, &dev)) if (grub_ieee1275_finddevice (devpath, &dev))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown device"); return 0;
if (grub_ieee1275_child (dev, &child)) if (grub_ieee1275_child (dev, &child))
return grub_error (GRUB_ERR_BAD_DEVICE, "Device has no children"); return 0;
childtype = grub_malloc (IEEE1275_MAX_PROP_LEN); childtype = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!childtype) if (!childtype)
return grub_errno; return 0;
childpath = grub_malloc (IEEE1275_MAX_PATH_LEN); childpath = grub_malloc (IEEE1275_MAX_PATH_LEN);
if (!childpath) if (!childpath)
{ {
grub_free (childtype); grub_free (childtype);
return grub_errno; return 0;
} }
childname = grub_malloc (IEEE1275_MAX_PROP_LEN); childname = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!childname) if (!childname)
{ {
grub_free (childpath); grub_free (childpath);
grub_free (childtype); grub_free (childtype);
return grub_errno; return 0;
} }
fullname = grub_malloc (IEEE1275_MAX_PATH_LEN); fullname = grub_malloc (IEEE1275_MAX_PATH_LEN);
if (!fullname) if (!fullname)
@ -69,7 +70,7 @@ grub_children_iterate (char *devpath,
grub_free (childname); grub_free (childname);
grub_free (childpath); grub_free (childpath);
grub_free (childtype); grub_free (childtype);
return grub_errno; return 0;
} }
do do
@ -94,7 +95,9 @@ grub_children_iterate (char *devpath,
alias.type = childtype; alias.type = childtype;
alias.path = childpath; alias.path = childpath;
alias.name = fullname; alias.name = fullname;
hook (&alias); ret = hook (&alias);
if (ret)
break;
} }
while (grub_ieee1275_peer (child, &child)); while (grub_ieee1275_peer (child, &child));
@ -103,30 +106,31 @@ grub_children_iterate (char *devpath,
grub_free (childpath); grub_free (childpath);
grub_free (childtype); grub_free (childtype);
return 0; return ret;
} }
/* Iterate through all device aliases. This function can be used to /* Iterate through all device aliases. This function can be used to
find a device of a specific type. */ find a device of a specific type. */
grub_err_t int
grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
{ {
grub_ieee1275_phandle_t aliases; grub_ieee1275_phandle_t aliases;
char *aliasname, *devtype; char *aliasname, *devtype;
grub_ssize_t actual; grub_ssize_t actual;
struct grub_ieee1275_devalias alias; struct grub_ieee1275_devalias alias;
int ret = 0;
if (grub_ieee1275_finddevice ("/aliases", &aliases)) if (grub_ieee1275_finddevice ("/aliases", &aliases))
return -1; return 0;
aliasname = grub_malloc (IEEE1275_MAX_PROP_LEN); aliasname = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!aliasname) if (!aliasname)
return grub_errno; return 0;
devtype = grub_malloc (IEEE1275_MAX_PROP_LEN); devtype = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!devtype) if (!devtype)
{ {
grub_free (aliasname); grub_free (aliasname);
return grub_errno; return 0;
} }
/* Find the first property. */ /* Find the first property. */
@ -155,7 +159,7 @@ grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
{ {
grub_free (devtype); grub_free (devtype);
grub_free (aliasname); grub_free (aliasname);
return grub_errno; return 0;
} }
if (grub_ieee1275_get_property (aliases, aliasname, devpath, pathlen, if (grub_ieee1275_get_property (aliases, aliasname, devpath, pathlen,
@ -182,15 +186,17 @@ grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
alias.name = aliasname; alias.name = aliasname;
alias.path = devpath; alias.path = devpath;
alias.type = devtype; alias.type = devtype;
hook (&alias); ret = hook (&alias);
nextprop: nextprop:
grub_free (devpath); grub_free (devpath);
if (ret)
break;
} }
grub_free (devtype); grub_free (devtype);
grub_free (aliasname); grub_free (aliasname);
return 0; return ret;
} }
/* Call the "map" method of /chosen/mmu. */ /* Call the "map" method of /chosen/mmu. */