@@ -375,12 +375,19 @@ static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess,
375
375
init_waitqueue_head (& iu -> comp .wait );
376
376
iu -> comp .errno = INT_MAX ;
377
377
378
+ if (sg_alloc_table (& iu -> sgt , 1 , GFP_KERNEL )) {
379
+ rnbd_put_permit (sess , permit );
380
+ kfree (iu );
381
+ return NULL ;
382
+ }
383
+
378
384
return iu ;
379
385
}
380
386
381
387
static void rnbd_put_iu (struct rnbd_clt_session * sess , struct rnbd_iu * iu )
382
388
{
383
389
if (atomic_dec_and_test (& iu -> refcount )) {
390
+ sg_free_table (& iu -> sgt );
384
391
rnbd_put_permit (sess , iu -> permit );
385
392
kfree (iu );
386
393
}
@@ -487,8 +494,6 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, bool wait)
487
494
iu -> buf = NULL ;
488
495
iu -> dev = dev ;
489
496
490
- sg_alloc_table (& iu -> sgt , 1 , GFP_KERNEL );
491
-
492
497
msg .hdr .type = cpu_to_le16 (RNBD_MSG_CLOSE );
493
498
msg .device_id = cpu_to_le32 (device_id );
494
499
@@ -502,7 +507,6 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, bool wait)
502
507
err = errno ;
503
508
}
504
509
505
- sg_free_table (& iu -> sgt );
506
510
rnbd_put_iu (sess , iu );
507
511
return err ;
508
512
}
@@ -575,7 +579,6 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait)
575
579
iu -> buf = rsp ;
576
580
iu -> dev = dev ;
577
581
578
- sg_alloc_table (& iu -> sgt , 1 , GFP_KERNEL );
579
582
sg_init_one (iu -> sgt .sgl , rsp , sizeof (* rsp ));
580
583
581
584
msg .hdr .type = cpu_to_le16 (RNBD_MSG_OPEN );
@@ -594,7 +597,6 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait)
594
597
err = errno ;
595
598
}
596
599
597
- sg_free_table (& iu -> sgt );
598
600
rnbd_put_iu (sess , iu );
599
601
return err ;
600
602
}
@@ -622,8 +624,6 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait)
622
624
623
625
iu -> buf = rsp ;
624
626
iu -> sess = sess ;
625
-
626
- sg_alloc_table (& iu -> sgt , 1 , GFP_KERNEL );
627
627
sg_init_one (iu -> sgt .sgl , rsp , sizeof (* rsp ));
628
628
629
629
msg .hdr .type = cpu_to_le16 (RNBD_MSG_SESS_INFO );
@@ -650,7 +650,6 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait)
650
650
} else {
651
651
err = errno ;
652
652
}
653
- sg_free_table (& iu -> sgt );
654
653
rnbd_put_iu (sess , iu );
655
654
return err ;
656
655
}
0 commit comments