@@ -209,23 +209,22 @@ static inline unsigned get_max_io_size(struct bio *bio,
209
209
/**
210
210
* get_max_segment_size() - maximum number of bytes to add as a single segment
211
211
* @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
214
214
*
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.
216
217
*/
217
218
static 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 )
219
220
{
220
- unsigned long mask = lim -> seg_boundary_mask ;
221
-
222
- offset = mask & (page_to_phys (start_page ) + offset );
223
-
224
221
/*
225
222
* Prevent an overflow if mask = ULONG_MAX and offset = 0 by adding 1
226
223
* after having calculated the minimum.
227
224
*/
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 );
229
228
}
230
229
231
230
/**
@@ -258,9 +257,7 @@ static bool bvec_split_segs(const struct queue_limits *lim,
258
257
unsigned seg_size = 0 ;
259
258
260
259
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 );
264
261
265
262
(* nsegs )++ ;
266
263
total_len += seg_size ;
@@ -494,8 +491,8 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
494
491
495
492
while (nbytes > 0 ) {
496
493
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 );
499
496
struct page * page = bvec -> bv_page ;
500
497
501
498
/*
0 commit comments