lkml.org 
[lkml]   [2014]   [Jul]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH 1/3] staging: lustre/lustre/lov: Remove unneeded 'if' statement in lov_request.c/lov_check_set()
From
Date
On Sat, 2014-07-19 at 21:34 +0200, Riccardo Lucchese wrote:
> It is silly to go through an if statement to set a single boolean
> value in function of a single boolean expression. In the function
> lov_check_set, assign the return value directly.
[]
> diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c
[]
> @@ -140,14 +140,13 @@ void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
>
> static int lov_check_set(struct lov_obd *lov, int idx)
> {
> - int rc = 0;
> + int rc;
> mutex_lock(&lov->lov_lock);
>
> - if (lov->lov_tgts[idx] == NULL ||
> - lov->lov_tgts[idx]->ltd_active ||
> - (lov->lov_tgts[idx]->ltd_exp != NULL &&
> - class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried))
> - rc = 1;
> + rc = lov->lov_tgts[idx] == NULL ||
> + lov->lov_tgts[idx]->ltd_active ||
> + (lov->lov_tgts[idx]->ltd_exp != NULL &&
> + class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried);
>
> mutex_unlock(&lov->lov_lock);
> return rc;

Maybe consider using a temporary for lov->lov_tgtx[idx] like:

---

drivers/staging/lustre/lustre/lov/lov_request.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c
b/drivers/staging/lustre/lustre/lov/lov_request.c
index ce830e4..53a4575 100644
--- a/drivers/staging/lustre/lustre/lov/lov_request.c
+++ b/drivers/staging/lustre/lustre/lov/lov_request.c
@@ -140,16 +140,18 @@ void lov_set_add_req(struct lov_request *req,
struct lov_request_set *set)

static int lov_check_set(struct lov_obd *lov, int idx)
{
- int rc = 0;
+ int rc;
+ struct lmv_tgt_desc *tgt;
+
mutex_lock(&lov->lov_lock);

- if (lov->lov_tgts[idx] == NULL ||
- lov->lov_tgts[idx]->ltd_active ||
- (lov->lov_tgts[idx]->ltd_exp != NULL &&
- class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried))
- rc = 1;
+ tgt = lov->lov_tgts[idx];
+ rc = (!tgt || tgt->ltd_active ||
+ (tgt->ltd_exp &&
+ class_exp2cliimp(tgt->ltd_exp)->imp_connect_tried));

mutex_unlock(&lov->lov_lock);
+
return rc;
}




\
 
 \ /
  Last update: 2014-07-19 22:41    [W:0.064 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site