Staging: lustre: lnet: Simplify function kiblnd_find_rd_dma_mr
PATCH 1/1 Staging: lustre: lnet: Simplify function kiblnd_find_rd_dma_mr
The struct pointer prev_mr is made NULL in the for loop so if(!prev_mr) will be true and (pre_mr = mr) will always execute and so the second if statement will reduce to if(!mr). prev_mr is serving no purpose here and can be removed along with the if statement.
--- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +2 -6
@@ -1326,7 +1326,6 @@ struct ib_mr *kiblnd_find_dma_mr(kib_hca_dev_t *hdev, __u64 addr, __u64 size)struct ib_mr *kiblnd_find_rd_dma_mr (kib_hca_dev_t *hdev,kib_rdma_desc_t *rd) { -struct ib_mr *prev_mr;struct ib_mr *mr;int i;
@@ -1339,15 +1338,12 @@ struct ib_mr *kiblnd_find_rd_dma_mr(kib_hca_dev_t *hdev, kib_rdma_desc_t *rd)if (hdev->ibh_nmrs ==1 )return hdev->ibh_mrs[0 ]; -for (i =0 , mr = prev_mr =NULL ; +for (i =0 , mr =NULL ; i < rd->rd_nfrags; i++) { mr =kiblnd_find_dma_mr (hdev, rd->rd_frags[i].rf_addr, rd->rd_frags[i].rf_nob); -if (!prev_mr) - prev_mr = mr; - -if (!mr || prev_mr != mr) { +if (!mr) {/* Can't covered by one single MR */ mr =NULL ;break ;
Signature · 1 line
1.9.1
Quoted 24 lines · Bhumika Goyal
The struct pointer prev_mr is made NULL in the for loop so
if(!prev_mr)
will be true and (pre_mr= mr) will always execute and so the second if
statement will reduce to if(!mr).prev_mris serving no purpose here and
can be removed along with the if statement.drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +0
-0@@ -1339,15 +1338,12 @@ struct ib_mr *kiblnd_find_rd_dma_mr (kib_hca_dev_t *hdev, kib_rdma_desc_t *rd) if (hdev->ibh_nmrs == 1) return hdev->ibh_mrs[0];drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +1
-1- for (i = 0, mr = prev_mr = NULL; + for (i = 0, mr = NULL;i <
rd->rd_nfrags; i++) {
mr =kiblnd_find_dma_mr(hdev, rd->rd_frags[i].rf_addr, rd->rd_frags[i].rf_nob);drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +1
-4-if (!prev_mr) - prev_mr = mr; - -if (!mr || prev_mr != mr) { +if (!mr) {
Quoted 3 lines
/* Can't covered by one single MR */ mr = NULL;
break;
You certainly found some suspicious looking code, but remember that prev_mr = NULL is only set when we first enter the loop.
On the first iteration, prev_mr is set to the value of the found mr, and on the second iteration the code can hit prev_mr != mr.
At that point it will set mr = NULL, before breaking out of the function and returning NULL.
Your patch changes that, by only returning NULL if the last iterator in the loop finds a NULL value of mr, which is not guaranteed.
In other words, your patch changes the behaviour of the code.
Looking at the calling function, kiblnd_map_tx() I am not sure either the old or the new behaviour is right.
CC'ing some Lustre developers and maintainers, since it is not at all clear to me what that code is supposed to do.
--
All rights reversed
Quoted 52 lines · Rik van Riel
Quoted 26 lines · Bhumika Goyal
The struct pointer
prev_mris made NULL in the for loop soif(!prev_mr)
will be true and (pre_mr= mr) will always execute and so the second if
statement will reduce to if(!mr).prev_mris serving no purpose here and
can be removed along with the if statement.drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +2
-5@@ -1339,15 +1338,12 @@ struct ib_mr *kiblnd_find_rd_dma_mr(kib_hca_dev_t *hdev, kib_rdma_desc_t *rd)if (hdev->ibh_nmrs ==1 )return hdev->ibh_mrs[0 ]; -for (i =0 , mr = prev_mr =NULL ; +for (i =0 , mr =NULL ; i < rd->rd_nfrags; i++) { mr =kiblnd_find_dma_mr (hdev, rd->rd_frags[i].rf_addr, rd->rd_frags[i].rf_nob); -if (!prev_mr) - prev_mr = mr; - -if (!mr || prev_mr != mr) { +if (!mr) {/* Can't covered by one single MR */ mr =NULL ;Quoted 1 line
break;You certainly found some suspicious looking code, but remember that
prev_mr= NULL is only set when we first enter the loop.On the first iteration,
prev_mris set to the value of the found mr, and on the second iteration the code can hitprev_mr!= mr.At that point it will set mr = NULL, before breaking out of the function and returning NULL.
Your patch changes that, by only returning NULL if the last iterator in the loop finds a NULL value of mr, which is not guaranteed.
In other words, your patch changes the behaviour of the code.
Looking at the calling function,
kiblnd_map_tx()I am not sure either the old or the new behaviour is right.
Quoted 6 lines
CC'ing some Lustre developers and maintainers, since it is not at all clear to me what that code is supposed to do.
--
All rights reversed
Thank you for the input. I just realized that my change is not returning NULL when (prev_mr!=mr) condition is satisfied. I have deleted the condition but I think this condition is necessary for proper behavior of the code.
Thanks,
Bhumika