return count;
 }
 
+static void hpsa_turn_off_ioaccel_for_device(struct hpsa_scsi_dev_t *device)
+{
+       device->offload_enabled = 0;
+       device->offload_to_be_enabled = 0;
+}
+
 static ssize_t host_show_firmware_revision(struct device *dev,
             struct device_attribute *attr, char *buf)
 {
                                __func__,
                                h->scsi_host->host_no, logical_drive->bus,
                                logical_drive->target, logical_drive->lun);
-                       logical_drive->offload_enabled = 0;
-                       logical_drive->offload_to_be_enabled = 0;
+                       hpsa_turn_off_ioaccel_for_device(logical_drive);
                        logical_drive->queue_depth = 8;
                }
        }
                        IOACCEL2_SERV_RESPONSE_FAILURE) {
                if (c2->error_data.status ==
                        IOACCEL2_STATUS_SR_IOACCEL_DISABLED) {
-                       dev->offload_enabled = 0;
-                       dev->offload_to_be_enabled = 0;
+                       hpsa_turn_off_ioaccel_for_device(dev);
                }
 
                if (dev->in_reset) {
        this_device->offload_config =
                !!(ioaccel_status & OFFLOAD_CONFIGURED_BIT);
        if (this_device->offload_config) {
-               this_device->offload_to_be_enabled =
+               bool offload_enabled =
                        !!(ioaccel_status & OFFLOAD_ENABLED_BIT);
-               if (hpsa_get_raid_map(h, scsi3addr, this_device))
-                       this_device->offload_to_be_enabled = 0;
+               /*
+                * Check to see if offload can be enabled.
+                */
+               if (offload_enabled) {
+                       rc = hpsa_get_raid_map(h, scsi3addr, this_device);
+                       if (rc) /* could not load raid_map */
+                               goto out;
+                       this_device->offload_to_be_enabled = 1;
+               }
        }
 
 out:
        } else {
                this_device->raid_level = RAID_UNKNOWN;
                this_device->offload_config = 0;
-               this_device->offload_enabled = 0;
-               this_device->offload_to_be_enabled = 0;
+               hpsa_turn_off_ioaccel_for_device(this_device);
                this_device->hba_ioaccel_enabled = 0;
                this_device->volume_offline = 0;
                this_device->queue_depth = h->nr_cmds;
                /* Handles load balance across RAID 1 members.
                 * (2-drive R1 and R10 with even # of drives.)
                 * Appropriate for SSDs, not optimal for HDDs
+                * Ensure we have the correct raid_map.
                 */
-               BUG_ON(le16_to_cpu(map->layout_map_count) != 2);
+               if (le16_to_cpu(map->layout_map_count) != 2) {
+                       hpsa_turn_off_ioaccel_for_device(dev);
+                       return IO_ACCEL_INELIGIBLE;
+               }
                if (dev->offload_to_mirror)
                        map_index += le16_to_cpu(map->data_disks_per_row);
                dev->offload_to_mirror = !dev->offload_to_mirror;
        case HPSA_RAID_ADM:
                /* Handles N-way mirrors  (R1-ADM)
                 * and R10 with # of drives divisible by 3.)
+                * Ensure we have the correct raid_map.
                 */
-               BUG_ON(le16_to_cpu(map->layout_map_count) != 3);
+               if (le16_to_cpu(map->layout_map_count) != 3) {
+                       hpsa_turn_off_ioaccel_for_device(dev);
+                       return IO_ACCEL_INELIGIBLE;
+               }
 
                offload_to_mirror = dev->offload_to_mirror;
                raid_map_helper(map, offload_to_mirror,
                r5or6_blocks_per_row =
                        le16_to_cpu(map->strip_size) *
                        le16_to_cpu(map->data_disks_per_row);
-               BUG_ON(r5or6_blocks_per_row == 0);
+               if (r5or6_blocks_per_row == 0) {
+                       hpsa_turn_off_ioaccel_for_device(dev);
+                       return IO_ACCEL_INELIGIBLE;
+               }
                stripesize = r5or6_blocks_per_row *
                        le16_to_cpu(map->layout_map_count);
 #if BITS_PER_LONG == 32
  *
  * Called from monitor controller worker (hpsa_event_monitor_worker)
  *
- * A Volume (or Volumes that comprise an Array set may be undergoing a
+ * A Volume (or Volumes that comprise an Array set) may be undergoing a
  * transformation, so we will be turning off ioaccel for all volumes that
  * make up the Array.
  */
         * Run through current device list used during I/O requests.
         */
        for (i = 0; i < h->ndevices; i++) {
+               int offload_to_be_enabled = 0;
+               int offload_config = 0;
+
                device = h->dev[i];
 
                if (!device)
                        continue;
 
                ioaccel_status = buf[IOACCEL_STATUS_BYTE];
-               device->offload_config =
+
+               /*
+                * Check if offload is still configured on
+                */
+               offload_config =
                                !!(ioaccel_status & OFFLOAD_CONFIGURED_BIT);
-               if (device->offload_config)
-                       device->offload_to_be_enabled =
+               /*
+                * If offload is configured on, check to see if ioaccel
+                * needs to be enabled.
+                */
+               if (offload_config)
+                       offload_to_be_enabled =
                                !!(ioaccel_status & OFFLOAD_ENABLED_BIT);
 
+               /*
+                * If ioaccel is to be re-enabled, re-enable later during the
+                * scan operation so the driver can get a fresh raidmap
+                * before turning ioaccel back on.
+                */
+               if (offload_to_be_enabled)
+                       continue;
+
                /*
                 * Immediately turn off ioaccel for any volume the
                 * controller tells us to. Some of the reasons could be:
                 *    transformation - change to the LVs of an Array.
                 *    degraded volume - component failure
-                *
-                * If ioaccel is to be re-enabled, re-enable later during the
-                * scan operation so the driver can get a fresh raidmap
-                * before turning ioaccel back on.
-                *
                 */
-               if (!device->offload_to_be_enabled)
-                       device->offload_enabled = 0;
+               hpsa_turn_off_ioaccel_for_device(device);
        }
 
        kfree(buf);