@@ -209,23 +209,22 @@ static inline unsigned get_max_io_size(struct bio *bio,
209209/**
210210 * get_max_segment_size() - maximum number of bytes to add as a single segment
211211 * @lim: Request queue limits.
212- * @start_page: See below.
213- * @offset: Offset from @start_page where to add a segment.
212+ * @paddr: address of the range to add
213+ * @max_len: maximum length available to add at @paddr
214214 *
215- * Returns the maximum number of bytes that can be added as a single segment.
215+ * Returns the maximum number of bytes of the range starting at @paddr that can
216+ * be added to a single segment.
216217 */
217218static inline unsigned get_max_segment_size (const struct queue_limits * lim ,
218- struct page * start_page , unsigned long offset )
219+ phys_addr_t paddr , unsigned int len )
219220{
220- unsigned long mask = lim -> seg_boundary_mask ;
221-
222- offset = mask & (page_to_phys (start_page ) + offset );
223-
224221 /*
225222 * Prevent an overflow if mask = ULONG_MAX and offset = 0 by adding 1
226223 * after having calculated the minimum.
227224 */
228- return min (mask - offset , (unsigned long )lim -> max_segment_size - 1 ) + 1 ;
225+ return min_t (unsigned long , len ,
226+ min (lim -> seg_boundary_mask - (lim -> seg_boundary_mask & paddr ),
227+ (unsigned long )lim -> max_segment_size - 1 ) + 1 );
229228}
230229
231230/**
@@ -258,9 +257,7 @@ static bool bvec_split_segs(const struct queue_limits *lim,
258257 unsigned seg_size = 0 ;
259258
260259 while (len && * nsegs < max_segs ) {
261- seg_size = get_max_segment_size (lim , bv -> bv_page ,
262- bv -> bv_offset + total_len );
263- seg_size = min (seg_size , len );
260+ seg_size = get_max_segment_size (lim , bvec_phys (bv ) + total_len , len );
264261
265262 (* nsegs )++ ;
266263 total_len += seg_size ;
@@ -494,8 +491,8 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
494491
495492 while (nbytes > 0 ) {
496493 unsigned offset = bvec -> bv_offset + total ;
497- unsigned len = min ( get_max_segment_size (& q -> limits ,
498- bvec -> bv_page , offset ), nbytes );
494+ unsigned len = get_max_segment_size (& q -> limits , bvec_phys ( bvec ) ,
495+ nbytes );
499496 struct page * page = bvec -> bv_page ;
500497
501498 /*
0 commit comments