dmraid_nvidia: Fix division by 0 and missing byte-swap.

This commit is contained in:
Vladimir Serbinenko 2015-02-26 22:06:19 +01:00
parent 94f701a826
commit f76c98b79e

View file

@ -99,6 +99,8 @@ grub_dmraid_nv_detect (grub_disk_t disk,
struct grub_nv_super sb; struct grub_nv_super sb;
int level; int level;
grub_uint64_t disk_size; grub_uint64_t disk_size;
grub_uint32_t capacity;
grub_uint8_t total_volumes;
char *uuid; char *uuid;
if (disk->partition) if (disk->partition)
@ -124,14 +126,17 @@ grub_dmraid_nv_detect (grub_disk_t disk,
return NULL; return NULL;
} }
capacity = grub_le_to_cpu32 (sb.capacity);
total_volumes = sb.array.total_volumes;
switch (sb.array.raid_level) switch (sb.array.raid_level)
{ {
case NV_LEVEL_0: case NV_LEVEL_0:
level = 0; level = 0;
disk_size = sb.capacity / sb.array.total_volumes; if (total_volumes == 0)
if (sb.array.total_volumes == 0)
/* Not RAID. */ /* Not RAID. */
return NULL; return NULL;
disk_size = capacity / total_volumes;
break; break;
case NV_LEVEL_1: case NV_LEVEL_1:
@ -141,10 +146,10 @@ grub_dmraid_nv_detect (grub_disk_t disk,
case NV_LEVEL_5: case NV_LEVEL_5:
level = 5; level = 5;
disk_size = sb.capacity / (sb.array.total_volumes - 1); if (total_volumes == 0 || total_volumes == 1)
if (sb.array.total_volumes == 0 || sb.array.total_volumes == 1)
/* Not RAID. */ /* Not RAID. */
return NULL; return NULL;
disk_size = capacity / (total_volumes - 1);
break; break;
default: default: