From fba51f48013be98d2d10324e57f3772a579fd2d2 Mon Sep 17 00:00:00 2001 From: hollisb Date: Sun, 1 Oct 2006 08:30:09 +0000 Subject: [PATCH] 2005-10-01 Hollis Blanchard * disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Cast `size' to long. * include/grub/ieee1275/ieee1275.h (grub_ieee1275_next_property): Remove `flags' argument. All callers changed. * kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_ROOT): Removed. (IEEE1275_IHANDLE_INVALID): New variable. (IEEE1275_CELL_INVALID): New variable. (grub_ieee1275_finddevice, grub_ieee1275_get_property, grub_ieee1275_get_property_length, grub_ieee1275_instance_to_package, grub_ieee1275_package_to_path, grub_ieee1275_instance_to_path, grub_ieee1275_peer, grub_ieee1275_child, grub_ieee1275_open, grub_ieee1275_claim, grub_ieee1275_set_property): Error-check return codes from Open Firmware. All callers updated. (grub_ieee1275_next_property): Directly return Open Firmware return code. * kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options): Standardize error checking from `grub_ieee1275_get_property'. * kern/powerpc/ieee1275/openfw.c (grub_devalias_iterate): Rename `devalias' to `aliases'. Correct comments. Consolidate error paths. --- ChangeLog | 22 ++++++++++ disk/ieee1275/ofdisk.c | 4 +- include/grub/ieee1275/ieee1275.h | 3 +- kern/ieee1275/ieee1275.c | 38 ++++++++++++------ kern/powerpc/ieee1275/cmain.c | 15 ++++--- kern/powerpc/ieee1275/openfw.c | 69 +++++++++++++------------------- 6 files changed, 84 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index f50acb263..1d280b407 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2005-10-01 Hollis Blanchard + + * disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Cast `size' to long. + + * include/grub/ieee1275/ieee1275.h (grub_ieee1275_next_property): + Remove `flags' argument. All callers changed. + * kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_ROOT): Removed. + (IEEE1275_IHANDLE_INVALID): New variable. + (IEEE1275_CELL_INVALID): New variable. + (grub_ieee1275_finddevice, grub_ieee1275_get_property, + grub_ieee1275_get_property_length, grub_ieee1275_instance_to_package, + grub_ieee1275_package_to_path, grub_ieee1275_instance_to_path, + grub_ieee1275_peer, grub_ieee1275_child, grub_ieee1275_open, + grub_ieee1275_claim, grub_ieee1275_set_property): Error-check return + codes from Open Firmware. All callers updated. + (grub_ieee1275_next_property): Directly return Open Firmware return + code. + * kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options): + Standardize error checking from `grub_ieee1275_get_property'. + * kern/powerpc/ieee1275/openfw.c (grub_devalias_iterate): Rename + `devalias' to `aliases'. Correct comments. Consolidate error paths. + 2005-10-01 Hollis Blanchard * kern/ieee1275/ieee1275.c (grub_ieee1275_instance_to_path): Rename diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c index 7a803d40c..c86a6a802 100644 --- a/disk/ieee1275/ofdisk.c +++ b/disk/ieee1275/ofdisk.c @@ -28,7 +28,7 @@ static int grub_ofdisk_iterate (int (*hook) (const char *name)) { auto int dev_iterate (struct grub_ieee1275_devalias *alias); - + int dev_iterate (struct grub_ieee1275_devalias *alias) { if (! grub_strcmp (alias->type, "block")) @@ -130,7 +130,7 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, grub_dprintf ("disk", "Reading handle %p: sector 0x%llx, size 0x%lx, buf %p.\n", - (void *) disk->data, sector, size, buf); + (void *) disk->data, sector, (long) size, buf); pos = sector * 512UL; diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 4c268f709..9da492923 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -96,8 +96,7 @@ int EXPORT_FUNC(grub_ieee1275_get_property) (grub_ieee1275_phandle_t phandle, grub_size_t size, grub_ssize_t *actual); int EXPORT_FUNC(grub_ieee1275_next_property) (grub_ieee1275_phandle_t phandle, - char *prev_prop, char *prop, - grub_ieee1275_cell_t *flags); + char *prev_prop, char *prop); int EXPORT_FUNC(grub_ieee1275_get_property_length) (grub_ieee1275_phandle_t phandle, const char *prop, grub_ssize_t *length); int EXPORT_FUNC(grub_ieee1275_instance_to_package) diff --git a/kern/ieee1275/ieee1275.c b/kern/ieee1275/ieee1275.c index 29329b007..03dd1bbaa 100644 --- a/kern/ieee1275/ieee1275.c +++ b/kern/ieee1275/ieee1275.c @@ -20,8 +20,9 @@ #include -#define IEEE1275_PHANDLE_ROOT ((grub_ieee1275_phandle_t) 0) -#define IEEE1275_PHANDLE_INVALID ((grub_ieee1275_phandle_t) -1) +#define IEEE1275_PHANDLE_INVALID ((grub_ieee1275_phandle_t) -1) +#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) -1) +#define IEEE1275_CELL_INVALID ((grub_ieee1275_cell_t) -1) @@ -52,6 +53,8 @@ grub_ieee1275_finddevice (char *name, grub_ieee1275_phandle_t *phandlep) if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; *phandlep = args.phandle; + if (args.phandle == IEEE1275_PHANDLE_INVALID) + return -1; return 0; } @@ -81,14 +84,14 @@ grub_ieee1275_get_property (grub_ieee1275_phandle_t phandle, return -1; if (actual) *actual = (grub_ssize_t) args.size; - if (args.size == (grub_ieee1275_cell_t) -1) + if (args.size == IEEE1275_CELL_INVALID) return -1; return 0; } int grub_ieee1275_next_property (grub_ieee1275_phandle_t phandle, char *prev_prop, - char *prop, grub_ieee1275_cell_t *flags) + char *prop) { struct get_property_args { @@ -108,9 +111,7 @@ grub_ieee1275_next_property (grub_ieee1275_phandle_t phandle, char *prev_prop, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; - if (flags) - *flags = args.flags; - return 0; + return (int) args.flags; } int @@ -134,6 +135,8 @@ grub_ieee1275_get_property_length (grub_ieee1275_phandle_t phandle, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; *length = args.length; + if (args.length == IEEE1275_CELL_INVALID) + return -1; return 0; } @@ -155,6 +158,8 @@ grub_ieee1275_instance_to_package (grub_ieee1275_ihandle_t ihandle, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; *phandlep = args.phandle; + if (args.phandle == IEEE1275_PHANDLE_INVALID) + return -1; return 0; } @@ -182,6 +187,8 @@ grub_ieee1275_package_to_path (grub_ieee1275_phandle_t phandle, return -1; if (actual) *actual = args.actual; + if (args.actual == IEEE1275_CELL_INVALID) + return -1; return 0; } @@ -209,6 +216,8 @@ grub_ieee1275_instance_to_path (grub_ieee1275_ihandle_t ihandle, return -1; if (actual) *actual = args.actual; + if (args.actual == IEEE1275_CELL_INVALID) + return -1; return 0; } @@ -309,6 +318,8 @@ grub_ieee1275_peer (grub_ieee1275_phandle_t node, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; *result = args.result; + if (args.result == 0) + return -1; return 0; } @@ -331,6 +342,8 @@ grub_ieee1275_child (grub_ieee1275_phandle_t node, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; *result = args.result; + if (args.result == 0) + return -1; return 0; } @@ -425,6 +438,8 @@ grub_ieee1275_open (const char *path, grub_ieee1275_ihandle_t *result) if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; *result = args.result; + if (args.result == IEEE1275_IHANDLE_INVALID) + return -1; return 0; } @@ -468,13 +483,10 @@ grub_ieee1275_claim (grub_addr_t addr, grub_size_t size, unsigned int align, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; - if (result) *result = args.base; - - if (args.base == (grub_ieee1275_cell_t)-1) + if (args.base == IEEE1275_CELL_INVALID) return -1; - return 0; } @@ -495,7 +507,6 @@ grub_ieee1275_release (grub_addr_t addr, grub_size_t size) if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; - return 0; } @@ -524,6 +535,8 @@ grub_ieee1275_set_property (grub_ieee1275_phandle_t phandle, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; *actual = args.actual; + if ((args.actual == IEEE1275_CELL_INVALID) || (args.actual != args.size)) + return -1; return 0; } @@ -553,7 +566,6 @@ grub_ieee1275_set_color (grub_ieee1275_ihandle_t ihandle, if (IEEE1275_CALL_ENTRY_FN (&args) == -1) return -1; - return 0; } diff --git a/kern/powerpc/ieee1275/cmain.c b/kern/powerpc/ieee1275/cmain.c index dcc0247db..378040906 100644 --- a/kern/powerpc/ieee1275/cmain.c +++ b/kern/powerpc/ieee1275/cmain.c @@ -51,19 +51,18 @@ grub_ieee1275_find_options (void) { grub_ieee1275_phandle_t options; grub_ieee1275_phandle_t openprom; - int realmode; - int smartfw; + int rc; + int realmode = 0; grub_ieee1275_finddevice ("/options", &options); - grub_ieee1275_get_property (options, "real-mode?", &realmode, - sizeof (realmode), 0); - if (realmode) + rc = grub_ieee1275_get_property (options, "real-mode?", &realmode, + sizeof realmode, 0); + if ((rc >= 0) && realmode) grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE); grub_ieee1275_finddevice ("/openprom", &openprom); - smartfw = grub_ieee1275_get_property (openprom, "SmartFirmware-version", - 0, 0, 0); - if (smartfw != -1) + rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version", 0, 0, 0); + if (rc >= 0) grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS); } diff --git a/kern/powerpc/ieee1275/openfw.c b/kern/powerpc/ieee1275/openfw.c index ad86f7b92..1b193b2db 100644 --- a/kern/powerpc/ieee1275/openfw.c +++ b/kern/powerpc/ieee1275/openfw.c @@ -38,12 +38,10 @@ grub_children_iterate (char *devpath, grub_ieee1275_phandle_t dev; grub_ieee1275_phandle_t child; - grub_ieee1275_finddevice (devpath, &dev); - if (dev == (grub_ieee1275_phandle_t) -1) + if (grub_ieee1275_finddevice (devpath, &dev)) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown device"); - grub_ieee1275_child (dev, &child); - if (child == (grub_ieee1275_phandle_t) -1) + if (grub_ieee1275_child (dev, &child)) return grub_error (GRUB_ERR_BAD_DEVICE, "Device has no children"); do @@ -56,19 +54,16 @@ grub_children_iterate (char *devpath, struct grub_ieee1275_devalias alias; int actual; - grub_ieee1275_get_property (child, "device_type", &childtype, - sizeof childtype, &actual); - if (actual == -1) + if (grub_ieee1275_get_property (child, "device_type", &childtype, + sizeof childtype, &actual)) continue; - grub_ieee1275_package_to_path (child, childpath, sizeof childpath, - &actual); - if (actual == -1) + if (grub_ieee1275_package_to_path (child, childpath, sizeof childpath, + &actual)) continue; - grub_ieee1275_get_property (child, "name", &childname, - sizeof childname, &actual); - if (actual == -1) + if (grub_ieee1275_get_property (child, "name", &childname, + sizeof childname, &actual)) continue; grub_sprintf (fullname, "%s/%s", devpath, childname); @@ -88,62 +83,52 @@ grub_children_iterate (char *devpath, grub_err_t grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) { - grub_ieee1275_phandle_t devalias; + grub_ieee1275_phandle_t aliases; char aliasname[32]; int actual; struct grub_ieee1275_devalias alias; - if (grub_ieee1275_finddevice ("/aliases", &devalias)) + if (grub_ieee1275_finddevice ("/aliases", &aliases)) return -1; - /* XXX: Is this the right way to find the first property? */ + /* Find the first property. */ aliasname[0] = '\0'; - /* XXX: Are the while conditions correct? */ - while (grub_ieee1275_next_property (devalias, aliasname, aliasname, 0)) + while (grub_ieee1275_next_property (aliases, aliasname, aliasname)) { grub_ieee1275_phandle_t dev; grub_ssize_t pathlen; char *devpath; /* XXX: This should be large enough for any possible case. */ char devtype[64]; - - grub_ieee1275_get_property_length (devalias, aliasname, &pathlen); + + grub_ieee1275_get_property_length (aliases, aliasname, &pathlen); /* The property `name' is a special case we should skip. */ if (!grub_strcmp (aliasname, "name")) - continue; - + continue; + devpath = grub_malloc (pathlen); if (! devpath) return grub_errno; - if (grub_ieee1275_get_property (devalias, aliasname, devpath, pathlen, + if (grub_ieee1275_get_property (aliases, aliasname, devpath, pathlen, &actual)) - { - grub_free (devpath); - continue; - } - - if (grub_ieee1275_finddevice (devpath, &dev) - || dev == (grub_ieee1275_phandle_t) -1) - { - grub_free (devpath); - continue; - } + goto nextprop; - if (grub_ieee1275_get_property (dev, "device_type", devtype, sizeof devtype, - &actual)) - { - grub_free (devpath); - continue; - } + if (grub_ieee1275_finddevice (devpath, &dev)) + goto nextprop; + + if (grub_ieee1275_get_property (dev, "device_type", devtype, + sizeof devtype, &actual)) + goto nextprop; alias.name = aliasname; - alias.path= devpath; + alias.path = devpath; alias.type = devtype; hook (&alias); - + +nextprop: grub_free (devpath); }