164          */
 165         if (ufmh->ufmh_ops->ddi_ufm_op_nimages != NULL) {
 166                 ret = ufmh->ufmh_ops->ddi_ufm_op_nimages(ufmh, ufmh->ufmh_arg,
 167                     &nimgs);
 168                 if (ret == 0 && nimgs > 0)
 169                         ufmh->ufmh_nimages = nimgs;
 170                 else
 171                         goto cache_fail;
 172         } else {
 173                 ufmh->ufmh_nimages = 1;
 174         }
 175 
 176         /*
 177          * Now that we know how many images we're dealing with, allocate space
 178          * for an appropriately-sized array of ddi_ufm_image_t structs and then
 179          * iterate through them calling the ddi_ufm_op_fill_image entry point
 180          * so that the driver can fill them in.
 181          */
 182         ufmh->ufmh_images =
 183             kmem_zalloc((sizeof (ddi_ufm_image_t) * ufmh->ufmh_nimages),
 184             KM_NOSLEEP | KM_NORMALPRI);
 185         if (ufmh->ufmh_images == NULL)
 186                 return (ENOMEM);
 187 
 188         for (uint_t i = 0; i < ufmh->ufmh_nimages; i++) {
 189                 struct ddi_ufm_image *img = &ufmh->ufmh_images[i];
 190 
 191                 ret = ufmh->ufmh_ops->ddi_ufm_op_fill_image(ufmh,
 192                     ufmh->ufmh_arg, i, img);
 193 
 194                 if (ret != 0)
 195                         goto cache_fail;
 196 
 197                 if (img->ufmi_desc == NULL || img->ufmi_nslots == 0) {
 198                         ret = EIO;
 199                         goto cache_fail;
 200                 }
 201 
 202                 img->ufmi_slots =
 203                     kmem_zalloc((sizeof (ddi_ufm_slot_t) * img->ufmi_nslots),
 204                     KM_NOSLEEP | KM_NORMALPRI);
 205                 if (img->ufmi_slots == NULL) {
 206                         ret = ENOMEM;
 207                         goto cache_fail;
 208                 }
 209 
 210                 for (uint_t s = 0; s < img->ufmi_nslots; s++) {
 211                         struct ddi_ufm_slot *slot = &img->ufmi_slots[s];
 212 
 213                         ret = ufmh->ufmh_ops->ddi_ufm_op_fill_slot(ufmh,
 214                             ufmh->ufmh_arg, i, s, slot);
 215 
 216                         if (ret != 0)
 217                                 goto cache_fail;
 218 
 219                         ASSERT(slot->ufms_attrs & DDI_UFM_ATTR_EMPTY ||
 220                             slot->ufms_version != NULL);
 221                 }
 222         }
 223         images = kmem_zalloc(sizeof (nvlist_t *) * ufmh->ufmh_nimages,
 224             KM_SLEEP);
 
 | 
 
 
 164          */
 165         if (ufmh->ufmh_ops->ddi_ufm_op_nimages != NULL) {
 166                 ret = ufmh->ufmh_ops->ddi_ufm_op_nimages(ufmh, ufmh->ufmh_arg,
 167                     &nimgs);
 168                 if (ret == 0 && nimgs > 0)
 169                         ufmh->ufmh_nimages = nimgs;
 170                 else
 171                         goto cache_fail;
 172         } else {
 173                 ufmh->ufmh_nimages = 1;
 174         }
 175 
 176         /*
 177          * Now that we know how many images we're dealing with, allocate space
 178          * for an appropriately-sized array of ddi_ufm_image_t structs and then
 179          * iterate through them calling the ddi_ufm_op_fill_image entry point
 180          * so that the driver can fill them in.
 181          */
 182         ufmh->ufmh_images =
 183             kmem_zalloc((sizeof (ddi_ufm_image_t) * ufmh->ufmh_nimages),
 184             KM_NOSLEEP_LAZY);
 185         if (ufmh->ufmh_images == NULL)
 186                 return (ENOMEM);
 187 
 188         for (uint_t i = 0; i < ufmh->ufmh_nimages; i++) {
 189                 struct ddi_ufm_image *img = &ufmh->ufmh_images[i];
 190 
 191                 ret = ufmh->ufmh_ops->ddi_ufm_op_fill_image(ufmh,
 192                     ufmh->ufmh_arg, i, img);
 193 
 194                 if (ret != 0)
 195                         goto cache_fail;
 196 
 197                 if (img->ufmi_desc == NULL || img->ufmi_nslots == 0) {
 198                         ret = EIO;
 199                         goto cache_fail;
 200                 }
 201 
 202                 img->ufmi_slots =
 203                     kmem_zalloc((sizeof (ddi_ufm_slot_t) * img->ufmi_nslots),
 204                     KM_NOSLEEP_LAZY);
 205                 if (img->ufmi_slots == NULL) {
 206                         ret = ENOMEM;
 207                         goto cache_fail;
 208                 }
 209 
 210                 for (uint_t s = 0; s < img->ufmi_nslots; s++) {
 211                         struct ddi_ufm_slot *slot = &img->ufmi_slots[s];
 212 
 213                         ret = ufmh->ufmh_ops->ddi_ufm_op_fill_slot(ufmh,
 214                             ufmh->ufmh_arg, i, s, slot);
 215 
 216                         if (ret != 0)
 217                                 goto cache_fail;
 218 
 219                         ASSERT(slot->ufms_attrs & DDI_UFM_ATTR_EMPTY ||
 220                             slot->ufms_version != NULL);
 221                 }
 222         }
 223         images = kmem_zalloc(sizeof (nvlist_t *) * ufmh->ufmh_nimages,
 224             KM_SLEEP);
 
 |