return bio_submit_split(bio, split_sectors);
 }
 
-struct bio *bio_split_write_zeroes(struct bio *bio,
-               const struct queue_limits *lim, unsigned *nsegs)
-{
-       *nsegs = 0;
-       if (!lim->max_write_zeroes_sectors)
-               return bio;
-       if (bio_sectors(bio) <= lim->max_write_zeroes_sectors)
-               return bio;
-       return bio_submit_split(bio, lim->max_write_zeroes_sectors);
-}
-
 static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim,
                                                bool is_atomic)
 {
         * We ignore lim->max_sectors for atomic writes because it may less
         * than the actual bio size, which we cannot tolerate.
         */
-       if (is_atomic)
+       if (bio_op(bio) == REQ_OP_WRITE_ZEROES)
+               max_sectors = lim->max_write_zeroes_sectors;
+       else if (is_atomic)
                max_sectors = lim->atomic_write_max_sectors;
        else
                max_sectors = lim->max_sectors;
        return bio_submit_split(bio, split_sectors);
 }
 
+struct bio *bio_split_write_zeroes(struct bio *bio,
+               const struct queue_limits *lim, unsigned *nsegs)
+{
+       unsigned int max_sectors = get_max_io_size(bio, lim);
+
+       *nsegs = 0;
+
+       /*
+        * An unset limit should normally not happen, as bio submission is keyed
+        * off having a non-zero limit.  But SCSI can clear the limit in the
+        * I/O completion handler, and we can race and see this.  Splitting to a
+        * zero limit obviously doesn't make sense, so band-aid it here.
+        */
+       if (!max_sectors)
+               return bio;
+       if (bio_sectors(bio) <= max_sectors)
+               return bio;
+       return bio_submit_split(bio, max_sectors);
+}
+
 /**
  * bio_split_to_limits - split a bio to fit the queue limits
  * @bio:     bio to be split