Skip to contentSkip to conversation

staging: lustre: include: replace macros by functions

PATCH Superseded Aya Mahfouz 2 participants 9 messages Apr 1, 2015 – Apr 2, 2015 Staging

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover staging: lustre: include: replace macros by functions

Replace two macros with static inline functions that return values. Inline functions are preferred because compilers are aware of them and can optimize the calls. In addition, if macros are treated like functions they can introduce bugs into the code.

Some minor fixes were done in patches 1 and 2 of the series. That is why the patchset is resent.

Aya Mahfouz (3):
staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev
staging: lustre: include: replace OBD_CHECK_DEV_ACTIVE by
obd_check_dev_active
staging: lustre: include: remove unused macros

 drivers/staging/lustre/lustre/include/obd_class.h | 77 +++++++++++++++--------
 1 file changed, 50 insertions(+), 27 deletions(-)
Signature · 6 lines
2.1.0


-- 
Kind Regards,
Aya Saif El-yazal Mahfouz
#1 lore raw

PATCH v2 1/3 staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev

Static inline functions are preferred over macros. Hence, the function obd_check_dev was introduced. obd_check_dev replaces the macro OBD_CHECK_DEV. All functions that call obd_check_dev store the return values and return them if they represent an error code.

Some of the changes were carried out manually while others were done using coccinelle.

---
v2: removed unneeded parenthesis around the variable obd.

 drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +27 -6
index 5314f6f..ddc212a 100644
@@ -341,6 +341,15 @@ do {							    \
 	}						       \
 } while (0)
 
+static inline int obd_check_dev(struct obd_device *obd)
+{
+	if (!(obd)) {
+		CERROR("NULL device\n");
+		return -ENODEV;
+	}
+	return 0;
+}
+
 /* ensure obd_setup and !obd_stopping */
 #define OBD_CHECK_DEV_ACTIVE(obd)			       \
 do {							    \
@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
 	if (ldt != NULL && d != NULL) {
@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	obd->obd_process_conf = 1;
 	ldt = obd->obd_type->typ_lu;
@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd,
 {
 	int rc;
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	/* the check for async_recov is a complete hack - I'm hereby
 	   overloading the meaning to also mean "this was called from
@@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,
 static inline int obd_register_observer(struct obd_device *obd,
 					struct obd_device *observer)
 {
-	OBD_CHECK_DEV(obd);
+	int rc;
+
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	down_write(&obd->obd_observer_link_sem);
 	if (obd->obd_observer && observer) {
 		up_write(&obd->obd_observer_link_sem);
@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd,
 	}
 	obd->obd_observer = observer;
 	up_write(&obd->obd_observer_link_sem);
-	return 0;
+	return rc;
 }
 
 #if 0
Signature · 6 lines
2.1.0


-- 
Kind Regards,
Aya Saif El-yazal Mahfouz
#6 lore raw

PATCH v2 2/3 staging: lustre: include: replace OBD_CHECK_DEV_ACTIVE by obd_check_dev_active

In reply to Aya Mahfouz

Static inline functions are preferred over macros. The inline function obd_check_dev_active is introduced to replace OBD_CHECK_DEV_ACTIVE. All functions that call obd_check_dev_active store the return values and return them if they represent an error code.

Some of the changes were carried out manually while others were done using coccinelle.

---
v2: removed unneeded parenthesis around the variable obd.

 drivers/staging/lustre/lustre/include/obd_class.h | 28 +++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +24 -4
index ddc212a..3c444fa 100644
@@ -361,7 +361,19 @@ do {							    \
 	}						       \
 } while (0)
 
+static inline int obd_check_dev_active(struct obd_device *obd)
+{
+	int rc;
 
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
+	if (!(obd)->obd_set_up || (obd)->obd_stopping) {
+		CERROR("Device %d not setup\n", (obd)->obd_minor);
+		return -ENODEV;
+	}
+	return rc;
+}
 #if defined (CONFIG_PROC_FS)
 #define OBD_COUNTER_OFFSET(op)				  \
 	((offsetof(struct obd_ops, o_ ## op) -		  \
@@ -901,7 +913,9 @@ static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
 	struct obd_device *obd = imp->imp_obd;
 	int rc;
 
-	OBD_CHECK_DEV_ACTIVE(obd);
+	rc = obd_check_dev_active(obd);
+	if (rc)
+		return rc;
 	OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
 	OBD_COUNTER_INCREMENT(obd, add_conn);
 
@@ -914,7 +928,9 @@ static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
 	struct obd_device *obd = imp->imp_obd;
 	int rc;
 
-	OBD_CHECK_DEV_ACTIVE(obd);
+	rc = obd_check_dev_active(obd);
+	if (rc)
+		return rc;
 	OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
 	OBD_COUNTER_INCREMENT(obd, del_conn);
 
@@ -948,7 +964,9 @@ static inline int obd_connect(const struct lu_env *env,
 	__u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
 						   * check */
 
-	OBD_CHECK_DEV_ACTIVE(obd);
+	rc = obd_check_dev_active(obd);
+	if (rc)
+		return rc;
 	OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
 	OBD_COUNTER_INCREMENT(obd, connect);
 
@@ -970,7 +988,9 @@ static inline int obd_reconnect(const struct lu_env *env,
 	__u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
 						   * check */
 
-	OBD_CHECK_DEV_ACTIVE(obd);
+	rc = obd_check_dev_active(obd);
+	if (rc)
+		return rc;
 	OBD_CHECK_DT_OP(obd, reconnect, 0);
 	OBD_COUNTER_INCREMENT(obd, reconnect);
 
Signature · 6 lines
2.1.0


-- 
Kind Regards,
Aya Saif El-yazal Mahfouz
#8 lore raw

PATCH v2 3/3 staging: lustre: include: remove unused macros

In reply to Aya Mahfouz

OBD_CHECK_DEV and OBD_CHECK_DEV_ACTIVE have been replaced by static inline functions. They are removed since they are not used anymore.

---
v2: No changes. The patch is part of a patchset, so it was resent with them.

 drivers/staging/lustre/lustre/include/obd_class.h | 18 ------------------
 1 file changed, 18 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -18
index 3c444fa..9af2b43 100644
@@ -333,14 +333,6 @@ void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
 
 /* Ensure obd_setup: used for cleanup which must be called
    while obd is stopping */
-#define OBD_CHECK_DEV(obd)				      \
-do {							    \
-	if (!(obd)) {					   \
-		CERROR("NULL device\n");			\
-		return -ENODEV;				\
-	}						       \
-} while (0)
-
 static inline int obd_check_dev(struct obd_device *obd)
 {
 	if (!(obd)) {
@@ -351,16 +343,6 @@ static inline int obd_check_dev(struct obd_device *obd)
 }
 
 /* ensure obd_setup and !obd_stopping */
-#define OBD_CHECK_DEV_ACTIVE(obd)			       \
-do {							    \
-	OBD_CHECK_DEV(obd);				     \
-	if (!(obd)->obd_set_up || (obd)->obd_stopping) {	\
-		CERROR("Device %d not setup\n",		 \
-		       (obd)->obd_minor);		       \
-		return -ENODEV;				\
-	}						       \
-} while (0)
-
 static inline int obd_check_dev_active(struct obd_device *obd)
 {
 	int rc;
Signature · 6 lines
2.1.0


-- 
Kind Regards,
Aya Saif El-yazal Mahfouz
maintainer
#2 lore raw

Re: [Outreachy kernel] [PATCH v2 1/3] staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev

In reply to Aya Mahfouz
Quoted 20 lines · Aya Mahfouz

Static inline functions are preferred over macros. Hence, the function obd_check_dev was introduced. obd_check_dev replaces the macro OBD_CHECK_DEV. All functions that call obd_check_dev store the return values and return them if they represent an error code.

Some of the changes were carried out manually while others were done using coccinelle.

---
v2: removed unneeded parenthesis around the variable obd.

 drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -0
index 5314f6f..ddc212a 100644

drivers/staging/lustre/lustre/include/obd_class.h do { \ · line 346

Quoted 6 lines
drivers/staging/lustre/lustre/include/obd_class.h +3 -0
@@ -341,6 +341,15 @@ do {							    \
 	}						       \
 } while (0)
 
+static inline int obd_check_dev(struct obd_device *obd)
+{
+	if (!(obd)) {

Why the extra () here?

Quoted 67 lines
drivers/staging/lustre/lustre/include/obd_class.h +23 -5
+		CERROR("NULL device\n");
+		return -ENODEV;
+	}
+	return 0;
+}
+
 /* ensure obd_setup and !obd_stopping */
 #define OBD_CHECK_DEV_ACTIVE(obd)			       \
 do {							    \
@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
 	if (ldt != NULL && d != NULL) {
@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	obd->obd_process_conf = 1;
 	ldt = obd->obd_type->typ_lu;
@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd,
 {
 	int rc;
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	/* the check for async_recov is a complete hack - I'm hereby
 	   overloading the meaning to also mean "this was called from
@@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,
 static inline int obd_register_observer(struct obd_device *obd,
 					struct obd_device *observer)
 {
-	OBD_CHECK_DEV(obd);
+	int rc;
+
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	down_write(&obd->obd_observer_link_sem);
 	if (obd->obd_observer && observer) {
 		up_write(&obd->obd_observer_link_sem);

drivers/staging/lustre/lustre/include/obd_class.h static inline int obd_register_observer(struct obd_device *obd, · line 1413

Quoted 5 lines
drivers/staging/lustre/lustre/include/obd_class.h +1 -1
@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd,
 	}
 	obd->obd_observer = observer;
 	up_write(&obd->obd_observer_link_sem);
-	return 0;
+	return rc;

This change isn't needed in this patch.

thanks,

greg k-h

maintainer
#7 lore raw

Re: [Outreachy kernel] [PATCH v2 2/3] staging: lustre: include: replace OBD_CHECK_DEV_ACTIVE by obd_check_dev_active

In reply to Aya Mahfouz
Quoted 22 lines · Aya Mahfouz

Static inline functions are preferred over macros. The inline function obd_check_dev_active is introduced to replace OBD_CHECK_DEV_ACTIVE. All functions that call obd_check_dev_active store the return values and return them if they represent an error code.

Some of the changes were carried out manually while others were done using coccinelle.

---
v2: removed unneeded parenthesis around the variable obd.

 drivers/staging/lustre/lustre/include/obd_class.h | 28 +++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -0
index ddc212a..3c444fa 100644
@@ -361,7 +361,19 @@ do {							    \
 	}						       \
 } while (0)

drivers/staging/lustre/lustre/include/obd_class.h do { \ · line 372

Quoted 10 lines
drivers/staging/lustre/lustre/include/obd_class.h +8 -0
 
+static inline int obd_check_dev_active(struct obd_device *obd)
+{
+	int rc;
 
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
+	if (!(obd)->obd_set_up || (obd)->obd_stopping) {
+		CERROR("Device %d not setup\n", (obd)->obd_minor);

extra () are not needed on these two lines either.

thanks,

greg k-h

#3 lore raw

Re: [Outreachy kernel] [PATCH v2 1/3] staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev

In reply to Greg KH
Quoted 24 lines · Greg KH
Quoted 23 lines · Aya Mahfouz

Static inline functions are preferred over macros. Hence, the function obd_check_dev was introduced. obd_check_dev replaces the macro OBD_CHECK_DEV. All functions that call obd_check_dev store the return values and return them if they represent an error code.

Some of the changes were carried out manually while others were done using coccinelle.

---
v2: removed unneeded parenthesis around the variable obd.

 drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -0
index 5314f6f..ddc212a 100644
@@ -341,6 +341,15 @@ do {							    \
 	}						       \
 } while (0)
 
Quoted 6 lines

drivers/staging/lustre/lustre/include/obd_class.h do { \ · line 346

Quoted 3 lines
drivers/staging/lustre/lustre/include/obd_class.h +3 -0
+static inline int obd_check_dev(struct obd_device *obd)
+{
+	if (!(obd)) {

Why the extra () here?

This was supposed to be fixed. It seems I used the first patch numbers again. I will resend the patchset.

Quoted 67 lines
Quoted 67 lines
drivers/staging/lustre/lustre/include/obd_class.h +23 -5
+		CERROR("NULL device\n");
+		return -ENODEV;
+	}
+	return 0;
+}
+
 /* ensure obd_setup and !obd_stopping */
 #define OBD_CHECK_DEV_ACTIVE(obd)			       \
 do {							    \
@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
 	if (ldt != NULL && d != NULL) {
@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	obd->obd_process_conf = 1;
 	ldt = obd->obd_type->typ_lu;
@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd,
 {
 	int rc;
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	/* the check for async_recov is a complete hack - I'm hereby
 	   overloading the meaning to also mean "this was called from
@@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,
 static inline int obd_register_observer(struct obd_device *obd,
 					struct obd_device *observer)
 {
-	OBD_CHECK_DEV(obd);
+	int rc;
+
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	down_write(&obd->obd_observer_link_sem);
 	if (obd->obd_observer && observer) {
 		up_write(&obd->obd_observer_link_sem);
Quoted 9 lines

drivers/staging/lustre/lustre/include/obd_class.h static inline int obd_register_observer(struct obd_device *obd, · line 1413

Quoted 6 lines
drivers/staging/lustre/lustre/include/obd_class.h +1 -1
@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd,
 	}
 	obd->obd_observer = observer;
 	up_write(&obd->obd_observer_link_sem);
-	return 0;
+	return rc;

This change isn't needed in this patch.

You mean to keep it return 0 as is?

Quoted 3 lines

thanks,

greg k-h

Signature · 2 lines
Kind Regards,
Aya Saif El-yazal Mahfouz
#4 lore raw

Re: [Outreachy kernel] [PATCH v2 1/3] staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev

In reply to Greg KH
Quoted 97 lines · Greg KH
Quoted 20 lines · Aya Mahfouz

Static inline functions are preferred over macros. Hence, the function obd_check_dev was introduced. obd_check_dev replaces the macro OBD_CHECK_DEV. All functions that call obd_check_dev store the return values and return them if they represent an error code.

Some of the changes were carried out manually while others were done using coccinelle.

---
v2: removed unneeded parenthesis around the variable obd.

 drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -0
index 5314f6f..ddc212a 100644

drivers/staging/lustre/lustre/include/obd_class.h do { \ · line 346

Quoted 6 lines
drivers/staging/lustre/lustre/include/obd_class.h +3 -0
@@ -341,6 +341,15 @@ do {							    \
 	}						       \
 } while (0)
 
+static inline int obd_check_dev(struct obd_device *obd)
+{
+	if (!(obd)) {

Why the extra () here?

Quoted 66 lines
drivers/staging/lustre/lustre/include/obd_class.h +23 -5
+		CERROR("NULL device\n");
+		return -ENODEV;
+	}
+	return 0;
+}
+
 /* ensure obd_setup and !obd_stopping */
 #define OBD_CHECK_DEV_ACTIVE(obd)			       \
 do {							    \
@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
 	if (ldt != NULL && d != NULL) {
@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	obd->obd_process_conf = 1;
 	ldt = obd->obd_type->typ_lu;
@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd,
 {
 	int rc;
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	/* the check for async_recov is a complete hack - I'm hereby
 	   overloading the meaning to also mean "this was called from
@@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,
 static inline int obd_register_observer(struct obd_device *obd,
 					struct obd_device *observer)
 {
-	OBD_CHECK_DEV(obd);
+	int rc;
+
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	down_write(&obd->obd_observer_link_sem);
 	if (obd->obd_observer && observer) {
 		up_write(&obd->obd_observer_link_sem);
Quoted 9 lines

drivers/staging/lustre/lustre/include/obd_class.h static inline int obd_register_observer(struct obd_device *obd, · line 1413

Quoted 6 lines
drivers/staging/lustre/lustre/include/obd_class.h +1 -1
@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd,
 	}
 	obd->obd_observer = observer;
 	up_write(&obd->obd_observer_link_sem);
-	return 0;
+	return rc;

This change isn't needed in this patch.

obd_check_dev initializes rc to 0 upon success.

Quoted 3 lines

thanks,

greg k-h

Signature · 2 lines
Kind Regards,
Aya Saif El-yazal Mahfouz
maintainer
#5 lore raw

Re: [Outreachy kernel] [PATCH v2 1/3] staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev

Quoted 107 lines · Aya Mahfouz
Quoted 97 lines · Greg KH
Quoted 20 lines · Aya Mahfouz

Static inline functions are preferred over macros. Hence, the function obd_check_dev was introduced. obd_check_dev replaces the macro OBD_CHECK_DEV. All functions that call obd_check_dev store the return values and return them if they represent an error code.

Some of the changes were carried out manually while others were done using coccinelle.

---
v2: removed unneeded parenthesis around the variable obd.

 drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -0
index 5314f6f..ddc212a 100644

drivers/staging/lustre/lustre/include/obd_class.h do { \ · line 346

Quoted 6 lines
drivers/staging/lustre/lustre/include/obd_class.h +3 -0
@@ -341,6 +341,15 @@ do {							    \
 	}						       \
 } while (0)
 
+static inline int obd_check_dev(struct obd_device *obd)
+{
+	if (!(obd)) {

Why the extra () here?

Quoted 66 lines
drivers/staging/lustre/lustre/include/obd_class.h +23 -5
+		CERROR("NULL device\n");
+		return -ENODEV;
+	}
+	return 0;
+}
+
 /* ensure obd_setup and !obd_stopping */
 #define OBD_CHECK_DEV_ACTIVE(obd)			       \
 do {							    \
@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
 	if (ldt != NULL && d != NULL) {
@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	ldt = obd->obd_type->typ_lu;
 	d = obd->obd_lu_dev;
@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)
 	int rc;
 	DECLARE_LU_VARS(ldt, d);
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	obd->obd_process_conf = 1;
 	ldt = obd->obd_type->typ_lu;
@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd,
 {
 	int rc;
 
-	OBD_CHECK_DEV(obd);
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 
 	/* the check for async_recov is a complete hack - I'm hereby
 	   overloading the meaning to also mean "this was called from
@@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,
 static inline int obd_register_observer(struct obd_device *obd,
 					struct obd_device *observer)
 {
-	OBD_CHECK_DEV(obd);
+	int rc;
+
+	rc = obd_check_dev(obd);
+	if (rc)
+		return rc;
 	down_write(&obd->obd_observer_link_sem);
 	if (obd->obd_observer && observer) {
 		up_write(&obd->obd_observer_link_sem);
Quoted 9 lines

drivers/staging/lustre/lustre/include/obd_class.h static inline int obd_register_observer(struct obd_device *obd, · line 1413

Quoted 6 lines
drivers/staging/lustre/lustre/include/obd_class.h +1 -1
@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd,
 	}
 	obd->obd_observer = observer;
 	up_write(&obd->obd_observer_link_sem);
-	return 0;
+	return rc;

This change isn't needed in this patch.

Quoted 1 line

obd_check_dev initializes rc to 0 upon success.

Yes, but why is that change needed here? Just leave the line alone, it doesn't have anything to do with the horrid OBD_CHECK_DEV() macro.

thanks,

greg k-h