diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index bfe798ffe4..ac4a0b23ad 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -1987,40 +1987,21 @@ static int max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max, int name_flags) { - char *name; - nvlist_t **child; - uint_t c, children; - int ret; - - name = zpool_vdev_name(g_zfs, zhp, nv, name_flags); - if (strlen(name) + depth > max) - max = strlen(name) + depth; + static const char *const subtypes[] = + {ZPOOL_CONFIG_SPARES, ZPOOL_CONFIG_L2CACHE, ZPOOL_CONFIG_CHILDREN}; + char *name = zpool_vdev_name(g_zfs, zhp, nv, name_flags); + max = MAX(strlen(name) + depth, max); free(name); - if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES, - &child, &children) == 0) { - for (c = 0; c < children; c++) - if ((ret = max_width(zhp, child[c], depth + 2, - max, name_flags)) > max) - max = ret; - } - - if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE, - &child, &children) == 0) { - for (c = 0; c < children; c++) - if ((ret = max_width(zhp, child[c], depth + 2, - max, name_flags)) > max) - max = ret; - } - - if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, - &child, &children) == 0) { - for (c = 0; c < children; c++) - if ((ret = max_width(zhp, child[c], depth + 2, - max, name_flags)) > max) - max = ret; - } + nvlist_t **child; + uint_t children; + for (size_t i = 0; i < ARRAY_SIZE(subtypes); ++i) + if (nvlist_lookup_nvlist_array(nv, subtypes[i], + &child, &children) == 0) + for (uint_t c = 0; c < children; ++c) + max = MAX(max_width(zhp, child[c], depth + 2, + max, name_flags), max); return (max); }