scsi: sd_zbc: Cleanup sd_zbc_alloc_report_buffer()
[sfrench/cifs-2.6.git] / drivers / scsi / sd_zbc.c
index 7c4690f2669831eb416e1ccda296e4296f379688..663608d1003b142ceec83a76031f868353129a29 100644 (file)
@@ -104,11 +104,6 @@ static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
        return 0;
 }
 
-/*
- * Maximum number of zones to get with one report zones command.
- */
-#define SD_ZBC_REPORT_MAX_ZONES                8192U
-
 /**
  * Allocate a buffer for report zones reply.
  * @sdkp: The target disk
@@ -138,17 +133,24 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
         * sure that the allocated buffer can always be mapped by limiting the
         * number of pages allocated to the HBA max segments limit.
         */
-       nr_zones = min(nr_zones, SD_ZBC_REPORT_MAX_ZONES);
-       bufsize = roundup((nr_zones + 1) * 64, 512);
+       nr_zones = min(nr_zones, sdkp->nr_zones);
+       bufsize = roundup((nr_zones + 1) * 64, SECTOR_SIZE);
        bufsize = min_t(size_t, bufsize,
                        queue_max_hw_sectors(q) << SECTOR_SHIFT);
        bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT);
 
-       buf = vzalloc(bufsize);
-       if (buf)
-               *buflen = bufsize;
+       while (bufsize >= SECTOR_SIZE) {
+               buf = __vmalloc(bufsize,
+                               GFP_KERNEL | __GFP_ZERO | __GFP_NORETRY,
+                               PAGE_KERNEL);
+               if (buf) {
+                       *buflen = bufsize;
+                       return buf;
+               }
+               bufsize >>= 1;
+       }
 
-       return buf;
+       return NULL;
 }
 
 /**