Skip to contentSkip to conversation

checkpatch fixes and style cleanups for libcfs headers

PATCH In review James Simmons 3 participants 13 messages Nov 18, 2016 – Nov 25, 2016 Staging

lore
Share & tools
lore
#0 lore raw

cover checkpatch fixes and style cleanups for libcfs headers

This patch set contains various cleanups that were reported with checkpatch. Also remove the NULL and 0 comparisons which is not kernel style. Lastly the uXX types are sorted out in the libcfs headers. Only the macro mess is left that needs cleaning up.

James Simmons (10):
staging: lustre: libcfs: fixup all header block comments
staging: lustre: libcfs: remove header's bare unsigned use
staging: lustre: libcfs: name parameters for function prototypes
staging: lustre: libcfs: remove blank line in header
staging: lustre: libcfs: correct spelling in libcfs_cpu.h
staging: lustre: libcfs: use bit macro in libcfs headers
staging: lustre: libcfs: remove whitespace in libcfs_fail.h
staging: lustre: libcfs: remove NULL comparisons in headers
staging: lustre: libcfs: remove zero comparisons in headers
staging: lustre: libcfs: use uXX instead of __uXX types in headers

 .../staging/lustre/include/linux/libcfs/curproc.h  |   20 +-
 .../staging/lustre/include/linux/libcfs/libcfs.h   |    4 +-
 .../lustre/include/linux/libcfs/libcfs_cpu.h       |    4 +-
 .../lustre/include/linux/libcfs/libcfs_crypto.h    |   12 +-
 .../lustre/include/linux/libcfs/libcfs_fail.h      |   53 ++++---
 .../lustre/include/linux/libcfs/libcfs_hash.h      |  183 ++++++++++---------
 .../lustre/include/linux/libcfs/libcfs_private.h   |   13 +-
 .../lustre/include/linux/libcfs/libcfs_string.h    |   24 ++--
 .../lustre/include/linux/libcfs/libcfs_workitem.h  |    4 +-
 .../lustre/include/linux/libcfs/linux/linux-cpu.h  |    8 +-
 .../lustre/include/linux/libcfs/linux/linux-time.h |    8 +-
 drivers/staging/lustre/lustre/obdclass/lu_object.c |    2 +-
 12 files changed, 179 insertions(+), 156 deletions(-)
#1 lore raw

PATCH 1/10 staging: lustre: libcfs: fixup all header block comments

Properly format the incorrect comments sections
that were reported by checkpatch.

---
 .../lustre/include/linux/libcfs/libcfs_crypto.h    |   10 ++++--
 .../lustre/include/linux/libcfs/libcfs_fail.h      |   30 +++++++++++++------
 .../lustre/include/linux/libcfs/libcfs_hash.h      |   24 ++++++++++-----
 .../lustre/include/linux/libcfs/libcfs_private.h   |    5 ++-
 .../lustre/include/linux/libcfs/libcfs_string.h    |    6 ++-
 5 files changed, 49 insertions(+), 26 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h +6 -4
index 02be7d7..a0865e5 100644
@@ -29,10 +29,12 @@
 #define _LIBCFS_CRYPTO_H
 
 struct cfs_crypto_hash_type {
-	char		*cht_name;      /**< hash algorithm name, equal to
-					 * format name for crypto api */
-	unsigned int    cht_key;	/**< init key by default (valid for
-					 * 4 bytes context like crc32, adler */
+	char		*cht_name;      /*< hash algorithm name, equal to
+					 * format name for crypto api
+					 */
+	unsigned int    cht_key;	/*< init key by default (valid for
+					 * 4 bytes context like crc32, adler
+					 */
 	unsigned int    cht_size;       /**< hash digest size */
 };
 
drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h +20 -10
index bdbbe93..b1658c8 100644
@@ -103,22 +103,28 @@ static inline int cfs_fail_check_set(__u32 id, __u32 value,
 #define CFS_FAIL_CHECK_QUIET(id) \
 	cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET, 1)
 
-/* If id hit cfs_fail_loc and cfs_fail_val == (-1 or value) return 1,
- * otherwise return 0 */
+/*
+ * If id hit cfs_fail_loc and cfs_fail_val == (-1 or value) return 1,
+ * otherwise return 0
+ */
 #define CFS_FAIL_CHECK_VALUE(id, value) \
 	cfs_fail_check_set(id, value, CFS_FAIL_LOC_VALUE, 0)
 #define CFS_FAIL_CHECK_VALUE_QUIET(id, value) \
 	cfs_fail_check_set(id, value, CFS_FAIL_LOC_VALUE, 1)
 
-/* If id hit cfs_fail_loc, cfs_fail_loc |= value and return 1,
- * otherwise return 0 */
+/*
+ * If id hit cfs_fail_loc, cfs_fail_loc |= value and return 1,
+ * otherwise return 0
+ */
 #define CFS_FAIL_CHECK_ORSET(id, value) \
 	cfs_fail_check_set(id, value, CFS_FAIL_LOC_ORSET, 0)
 #define CFS_FAIL_CHECK_ORSET_QUIET(id, value) \
 	cfs_fail_check_set(id, value, CFS_FAIL_LOC_ORSET, 1)
 
-/* If id hit cfs_fail_loc, cfs_fail_loc = value and return 1,
- * otherwise return 0 */
+/*
+ * If id hit cfs_fail_loc, cfs_fail_loc = value and return 1,
+ * otherwise return 0
+ */
 #define CFS_FAIL_CHECK_RESET(id, value) \
 	cfs_fail_check_set(id, value, CFS_FAIL_LOC_RESET, 0)
 #define CFS_FAIL_CHECK_RESET_QUIET(id, value) \
@@ -138,8 +144,10 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
 #define CFS_FAIL_TIMEOUT_MS(id, ms) \
 	cfs_fail_timeout_set(id, 0, ms, CFS_FAIL_LOC_NOSET)
 
-/* If id hit cfs_fail_loc, cfs_fail_loc |= value and
- * sleep seconds or milliseconds */
+/*
+ * If id hit cfs_fail_loc, cfs_fail_loc |= value and
+ * sleep seconds or milliseconds
+ */
 #define CFS_FAIL_TIMEOUT_ORSET(id, value, secs) \
 	cfs_fail_timeout_set(id, value, secs * 1000, CFS_FAIL_LOC_ORSET)
 
@@ -152,10 +160,12 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
 #define CFS_FAULT_CHECK(id)			\
 	CFS_FAIL_CHECK(CFS_FAULT | (id))
 
-/* The idea here is to synchronise two threads to force a race. The
+/*
+ * The idea here is to synchronise two threads to force a race. The
  * first thread that calls this with a matching fail_loc is put to
  * sleep. The next thread that calls with the same fail_loc wakes up
- * the first and continues. */
+ * the first and continues.
+ */
 static inline void cfs_race(__u32 id)
 {
 
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +16 -8
index f2b4399..a4ca488 100644
@@ -57,8 +57,10 @@
 
 /** disable debug */
 #define CFS_HASH_DEBUG_NONE	0
-/** record hash depth and output to console when it's too deep,
- *  computing overhead is low but consume more memory */
+/*
+ * record hash depth and output to console when it's too deep,
+ * computing overhead is low but consume more memory
+ */
 #define CFS_HASH_DEBUG_1	1
 /** expensive, check key validation */
 #define CFS_HASH_DEBUG_2	2
@@ -153,8 +155,10 @@ enum cfs_hash_tag {
 	 * change on hash table is non-blocking
 	 */
 	CFS_HASH_NBLK_CHANGE	= 1 << 13,
-	/** NB, we typed hs_flags as  __u16, please change it
-	 * if you need to extend >=16 flags */
+	/**
+	 * NB, we typed hs_flags as  __u16, please change it
+	 * if you need to extend >=16 flags
+	 */
 };
 
 /** most used attributes */
@@ -201,8 +205,10 @@ enum cfs_hash_tag {
  */
 
 struct cfs_hash {
-	/** serialize with rehash, or serialize all operations if
-	 * the hash-table has CFS_HASH_NO_BKTLOCK */
+	/**
+	 * serialize with rehash, or serialize all operations if
+	 * the hash-table has CFS_HASH_NO_BKTLOCK
+	 */
 	union cfs_hash_lock		hs_lock;
 	/** hash operations */
 	struct cfs_hash_ops		*hs_ops;
@@ -369,9 +375,11 @@ struct cfs_hash_ops {
 static inline int
 cfs_hash_with_no_itemref(struct cfs_hash *hs)
 {
-	/* hash-table doesn't keep refcount on item,
+	/*
+	 * hash-table doesn't keep refcount on item,
 	 * item can't be removed from hash unless it's
-	 * ZERO refcount */
+	 * ZERO refcount
+	 */
 	return (hs->hs_flags & CFS_HASH_NO_ITEMREF) != 0;
 }
 
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +3 -2
index e0e1a5d..523e8f4 100644
@@ -280,7 +280,7 @@
 #define CFS_FREE_PTR(ptr)       LIBCFS_FREE(ptr, sizeof(*(ptr)))
 
 /** Compile-time assertion.
-
+ *
  * Check an invariant described by a constant expression at compile time by
  * forcing a compiler error if it does not hold.  \a cond must be a constant
  * expression as defined by the ISO C Standard:
@@ -306,7 +306,8 @@
 /* --------------------------------------------------------------------
  * Light-weight trace
  * Support for temporary event tracing with minimal Heisenberg effect.
- * -------------------------------------------------------------------- */
+ * --------------------------------------------------------------------
+ */
 
 #define MKSTR(ptr) ((ptr)) ? (ptr) : ""
 
drivers/staging/lustre/include/linux/libcfs/libcfs_string.h +4 -2
index 0ee60ff..56341d9 100644
@@ -84,9 +84,11 @@ int cfs_expr_list_values(struct cfs_expr_list *expr_list,
 static inline void
 cfs_expr_list_values_free(__u32 *values, int num)
 {
-	/* This array is allocated by LIBCFS_ALLOC(), so it shouldn't be freed
+	/*
+	 * This array is allocated by LIBCFS_ALLOC(), so it shouldn't be freed
 	 * by OBD_FREE() if it's called by module other than libcfs & LNet,
-	 * otherwise we will see fake memory leak */
+	 * otherwise we will see fake memory leak
+	 */
 	LIBCFS_FREE(values, num * sizeof(values[0]));
 }
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/10 staging: lustre: libcfs: remove header's bare unsigned use

In reply to James Simmons

Fixup the libcfs headers to use the proper unsigned int instead of raw unsigned.

---
 .../lustre/include/linux/libcfs/libcfs_hash.h      |   28 ++++++++++----------
 .../lustre/include/linux/libcfs/libcfs_string.h    |    6 ++--
 .../lustre/include/linux/libcfs/linux/linux-cpu.h  |    8 +++---
 3 files changed, 21 insertions(+), 21 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +14 -14
index a4ca488..28937d5 100644
@@ -297,8 +297,8 @@ struct cfs_hash_hlist_ops {
 
 struct cfs_hash_ops {
 	/** return hashed value from @key */
-	unsigned (*hs_hash)(struct cfs_hash *hs, const void *key,
-			    unsigned mask);
+	unsigned int (*hs_hash)(struct cfs_hash *hs, const void *key,
+				unsigned int mask);
 	/** return key address of @hnode */
 	void *   (*hs_key)(struct hlist_node *hnode);
 	/** copy key from @hnode to @key */
@@ -461,7 +461,7 @@ struct cfs_hash_ops {
 }
 
 static inline unsigned
-cfs_hash_id(struct cfs_hash *hs, const void *key, unsigned mask)
+cfs_hash_id(struct cfs_hash *hs, const void *key, unsigned int mask)
 {
 	return hs->hs_ops->hs_hash(hs, key, mask);
 }
@@ -570,7 +570,7 @@ void cfs_hash_bd_get(struct cfs_hash *hs, const void *key,
 }
 
 static inline void
-cfs_hash_bd_index_set(struct cfs_hash *hs, unsigned index,
+cfs_hash_bd_index_set(struct cfs_hash *hs, unsigned int index,
 		      struct cfs_hash_bd *bd)
 {
 	bd->bd_bucket = hs->hs_buckets[index >> hs->hs_bkt_bits];
@@ -677,10 +677,10 @@ struct hlist_node *
 
 /* Hash init/cleanup functions */
 struct cfs_hash *
-cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits,
-		unsigned bkt_bits, unsigned extra_bytes,
-		unsigned min_theta, unsigned max_theta,
-		struct cfs_hash_ops *ops, unsigned flags);
+cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits,
+		unsigned int bkt_bits, unsigned int extra_bytes,
+		unsigned int min_theta, unsigned int max_theta,
+		struct cfs_hash_ops *ops, unsigned int flags);
 
 struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs);
 void cfs_hash_putref(struct cfs_hash *hs);
@@ -725,7 +725,7 @@ typedef int (*cfs_hash_for_each_cb_t)(struct cfs_hash *hs,
 cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t, void *data);
 
 void
-cfs_hash_hlist_for_each(struct cfs_hash *hs, unsigned hindex,
+cfs_hash_hlist_for_each(struct cfs_hash *hs, unsigned int hindex,
 			cfs_hash_for_each_cb_t, void *data);
 int  cfs_hash_is_empty(struct cfs_hash *hs);
 __u64 cfs_hash_size_get(struct cfs_hash *hs);
@@ -813,9 +813,9 @@ static inline int __cfs_hash_theta(struct cfs_hash *hs)
  * Generic djb2 hash algorithm for character arrays.
  */
 static inline unsigned
-cfs_hash_djb2_hash(const void *key, size_t size, unsigned mask)
+cfs_hash_djb2_hash(const void *key, size_t size, unsigned int mask)
 {
-	unsigned i, hash = 5381;
+	unsigned int i, hash = 5381;
 
 	LASSERT(key != NULL);
 
@@ -829,7 +829,7 @@ static inline int __cfs_hash_theta(struct cfs_hash *hs)
  * Generic u32 hash algorithm.
  */
 static inline unsigned
-cfs_hash_u32_hash(const __u32 key, unsigned mask)
+cfs_hash_u32_hash(const __u32 key, unsigned int mask)
 {
 	return ((key * CFS_GOLDEN_RATIO_PRIME_32) & mask);
 }
@@ -838,9 +838,9 @@ static inline int __cfs_hash_theta(struct cfs_hash *hs)
  * Generic u64 hash algorithm.
  */
 static inline unsigned
-cfs_hash_u64_hash(const __u64 key, unsigned mask)
+cfs_hash_u64_hash(const __u64 key, unsigned int mask)
 {
-	return ((unsigned)(key * CFS_GOLDEN_RATIO_PRIME_64) & mask);
+	return ((unsigned int)(key * CFS_GOLDEN_RATIO_PRIME_64) & mask);
 }
 
 /** iterate over all buckets in @bds (array of struct cfs_hash_bd) */
drivers/staging/lustre/include/linux/libcfs/libcfs_string.h +3 -3
index 56341d9..f5a434d 100644
@@ -74,8 +74,8 @@ struct cfs_expr_list {
 
 char *cfs_trimwhite(char *str);
 int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
-int cfs_str2num_check(char *str, int nob, unsigned *num,
-		      unsigned min, unsigned max);
+int cfs_str2num_check(char *str, int nob, unsigned int *num,
+		      unsigned int min, unsigned int max);
 int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
 int cfs_expr_list_print(char *buffer, int count,
 			struct cfs_expr_list *expr_list);
@@ -93,7 +93,7 @@ int cfs_expr_list_values(struct cfs_expr_list *expr_list,
 }
 
 void cfs_expr_list_free(struct cfs_expr_list *expr_list);
-int cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
+int cfs_expr_list_parse(char *str, int len, unsigned int min, unsigned int max,
 			struct cfs_expr_list **elpp);
 void cfs_expr_list_free_list(struct list_head *list);
 
drivers/staging/lustre/include/linux/libcfs/linux/linux-cpu.h +4 -4
index f63cb47..dd0cd04 100644
@@ -52,17 +52,17 @@ struct cfs_cpu_partition {
 	/* nodes mask for this partition */
 	nodemask_t			*cpt_nodemask;
 	/* spread rotor for NUMA allocator */
-	unsigned			cpt_spread_rotor;
+	unsigned int			cpt_spread_rotor;
 };
 
 /** descriptor for CPU partitions */
 struct cfs_cpt_table {
 	/* version, reserved for hotplug */
-	unsigned			ctb_version;
+	unsigned int			ctb_version;
 	/* spread rotor for NUMA allocator */
-	unsigned			ctb_spread_rotor;
+	unsigned int			ctb_spread_rotor;
 	/* # of CPU partitions */
-	unsigned			ctb_nparts;
+	unsigned int			ctb_nparts;
 	/* partitions tables */
 	struct cfs_cpu_partition	*ctb_parts;
 	/* shadow HW CPU to CPU partition ID */
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/10 staging: lustre: libcfs: name parameters for function prototypes

In reply to James Simmons

Give the parameters names for the function
prototypes in the libcfs headers.

---
 .../staging/lustre/include/linux/libcfs/libcfs.h   |    4 ++--
 .../lustre/include/linux/libcfs/libcfs_hash.h      |   15 ++++++++-------
 .../lustre/include/linux/libcfs/libcfs_private.h   |    4 ++--
 .../lustre/include/linux/libcfs/libcfs_workitem.h  |    4 ++--
 4 files changed, 14 insertions(+), 13 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs.h +2 -2
index 3b92d38..70eb08e 100644
@@ -61,7 +61,7 @@
 sigset_t cfs_block_allsigs(void);
 sigset_t cfs_block_sigs(unsigned long sigs);
 sigset_t cfs_block_sigsinv(unsigned long sigs);
-void cfs_restore_sigs(sigset_t);
+void cfs_restore_sigs(sigset_t sigset);
 void cfs_clear_sigpending(void);
 
 /*
@@ -71,7 +71,7 @@
 /* returns a random 32-bit integer */
 unsigned int cfs_rand(void);
 /* seed the generator */
-void cfs_srand(unsigned int, unsigned int);
+void cfs_srand(unsigned int seed1, unsigned int seed2);
 void cfs_get_random_bytes(void *buf, int size);
 
 #include "libcfs_debug.h"
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +8 -7
index 28937d5..2f56707 100644
@@ -708,25 +708,26 @@ typedef int (*cfs_hash_for_each_cb_t)(struct cfs_hash *hs,
 void *
 cfs_hash_lookup(struct cfs_hash *hs, const void *key);
 void
-cfs_hash_for_each(struct cfs_hash *hs, cfs_hash_for_each_cb_t, void *data);
+cfs_hash_for_each(struct cfs_hash *hs, cfs_hash_for_each_cb_t cb, void *data);
 void
-cfs_hash_for_each_safe(struct cfs_hash *hs, cfs_hash_for_each_cb_t, void *data);
+cfs_hash_for_each_safe(struct cfs_hash *hs, cfs_hash_for_each_cb_t cb,
+		       void *data);
 int
-cfs_hash_for_each_nolock(struct cfs_hash *hs, cfs_hash_for_each_cb_t,
+cfs_hash_for_each_nolock(struct cfs_hash *hs, cfs_hash_for_each_cb_t cb,
 			 void *data, int start);
 int
-cfs_hash_for_each_empty(struct cfs_hash *hs, cfs_hash_for_each_cb_t,
+cfs_hash_for_each_empty(struct cfs_hash *hs, cfs_hash_for_each_cb_t cb,
 			void *data);
 void
 cfs_hash_for_each_key(struct cfs_hash *hs, const void *key,
-		      cfs_hash_for_each_cb_t, void *data);
+		      cfs_hash_for_each_cb_t cb, void *data);
 typedef int (*cfs_hash_cond_opt_cb_t)(void *obj, void *data);
 void
-cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t, void *data);
+cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t cb, void *data);
 
 void
 cfs_hash_hlist_for_each(struct cfs_hash *hs, unsigned int hindex,
-			cfs_hash_for_each_cb_t, void *data);
+			cfs_hash_for_each_cb_t cb, void *data);
 int  cfs_hash_is_empty(struct cfs_hash *hs);
 __u64 cfs_hash_size_get(struct cfs_hash *hs);
 
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +2 -2
index 523e8f4..93bff1b 100644
@@ -75,7 +75,7 @@
 
 #define KLASSERT(e) LASSERT(e)
 
-void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *);
+void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msg);
 
 #define LBUG()							  \
 do {								    \
@@ -170,7 +170,7 @@
 #endif
 
 void libcfs_run_upcall(char **argv);
-void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data *);
+void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data *msg);
 void libcfs_debug_dumplog(void);
 int libcfs_debug_init(unsigned long bufsize);
 int libcfs_debug_cleanup(void);
drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h +2 -2
index a7e1340..2accd9a 100644
@@ -62,9 +62,9 @@
 
 struct cfs_wi_sched;
 
-void cfs_wi_sched_destroy(struct cfs_wi_sched *);
+void cfs_wi_sched_destroy(struct cfs_wi_sched *sched);
 int cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, int cpt,
-			int nthrs, struct cfs_wi_sched **);
+			int nthrs, struct cfs_wi_sched **sched_pp);
 
 struct cfs_workitem;
 
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/10 staging: lustre: libcfs: remove blank line in header

In reply to James Simmons

The header libcfs_fail.h has a extra blank line that is not needed.

---
 .../lustre/include/linux/libcfs/libcfs_fail.h      |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h +0 -1
index b1658c8..f06b4aa 100644
@@ -168,7 +168,6 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
  */
 static inline void cfs_race(__u32 id)
 {
-
 	if (CFS_FAIL_PRECHECK(id)) {
 		if (unlikely(__cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET))) {
 			int rc;
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/10 staging: lustre: libcfs: correct spelling in libcfs_cpu.h

In reply to James Simmons

Spell the word destroy correctly.

---
 .../lustre/include/linux/libcfs/libcfs_cpu.h       |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h +1 -1
index 81d8079..61bd951 100644
@@ -211,7 +211,7 @@ void cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab,
  */
 void *cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size);
 /*
- * destory per-cpu-partition variable
+ * destroy per-cpu-partition variable
  */
 void cfs_percpt_free(void *vars);
 int cfs_percpt_number(void *vars);
Signature · 1 line
1.7.1
#6 lore raw

PATCH 6/10 staging: lustre: libcfs: use bit macro in libcfs headers

In reply to James Simmons

Use the BIT macros instead of (1 << ***) in libcfs headers.

---
 .../staging/lustre/include/linux/libcfs/curproc.h  |   18 ++++----
 .../lustre/include/linux/libcfs/libcfs_fail.h      |    4 +-
 .../lustre/include/linux/libcfs/libcfs_hash.h      |   42 ++++++++++----------
 drivers/staging/lustre/lustre/obdclass/lu_object.c |    2 +-
 4 files changed, 33 insertions(+), 33 deletions(-)
drivers/staging/lustre/include/linux/libcfs/curproc.h +9 -9
index be0675d..6469a67 100644
@@ -65,15 +65,15 @@
 #define CFS_CAP_SYS_BOOT	       23
 #define CFS_CAP_SYS_RESOURCE	   24
 
-#define CFS_CAP_FS_MASK ((1 << CFS_CAP_CHOWN) |		 \
-			 (1 << CFS_CAP_DAC_OVERRIDE) |	  \
-			 (1 << CFS_CAP_DAC_READ_SEARCH) |       \
-			 (1 << CFS_CAP_FOWNER) |		\
-			 (1 << CFS_CAP_FSETID) |	       \
-			 (1 << CFS_CAP_LINUX_IMMUTABLE) |       \
-			 (1 << CFS_CAP_SYS_ADMIN) |	     \
-			 (1 << CFS_CAP_SYS_BOOT) |	      \
-			 (1 << CFS_CAP_SYS_RESOURCE))
+#define CFS_CAP_FS_MASK (BIT(CFS_CAP_CHOWN) |		\
+			 BIT(CFS_CAP_DAC_OVERRIDE) |	\
+			 BIT(CFS_CAP_DAC_READ_SEARCH) |	\
+			 BIT(CFS_CAP_FOWNER) |		\
+			 BIT(CFS_CAP_FSETID) |		\
+			 BIT(CFS_CAP_LINUX_IMMUTABLE) | \
+			 BIT(CFS_CAP_SYS_ADMIN) |	\
+			 BIT(CFS_CAP_SYS_BOOT) |	\
+			 BIT(CFS_CAP_SYS_RESOURCE))
 
 void cfs_cap_raise(cfs_cap_t cap);
 void cfs_cap_lower(cfs_cap_t cap);
drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h +2 -2
index f06b4aa..6f019a4 100644
@@ -55,11 +55,11 @@ enum {
 
 #define CFS_FAILED_BIT       30
 /* CFS_FAILED is 0x40000000 */
-#define CFS_FAILED	  (1 << CFS_FAILED_BIT)
+#define CFS_FAILED		BIT(CFS_FAILED_BIT)
 
 #define CFS_FAIL_ONCE_BIT    31
 /* CFS_FAIL_ONCE is 0x80000000 */
-#define CFS_FAIL_ONCE       (1 << CFS_FAIL_ONCE_BIT)
+#define CFS_FAIL_ONCE		BIT(CFS_FAIL_ONCE_BIT)
 
 /* The following flags aren't made to be combined */
 #define CFS_FAIL_SKIP	0x20000000 /* skip N times then fail */
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +21 -21

85 lines not on this page · raw message

drivers/staging/lustre/lustre/obdclass/lu_object.c +1 -1
index 14ca82d..43868ed 100644
@@ -1981,7 +1981,7 @@ int lu_site_stats_print(const struct lu_site *s, struct seq_file *m)
 	memset(&stats, 0, sizeof(stats));
 	lu_site_stats_get(s->ls_obj_hash, &stats, 1);
 
-	seq_printf(m, "%d/%d %d/%d %d %d %d %d %d %d %d %d\n",
+	seq_printf(m, "%d/%d %d/%ld %d %d %d %d %d %d %d %d\n",
 		   stats.lss_busy,
 		   stats.lss_total,
 		   stats.lss_populated,
Signature · 1 line
1.7.1
#7 lore raw

PATCH 7/10 staging: lustre: libcfs: remove whitespace in libcfs_fail.h

In reply to James Simmons

One last white space is still left in libcfs_fail.h. Lets remove it.

---
 .../lustre/include/linux/libcfs/libcfs_fail.h      |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h +1 -1
index 6f019a4..73cbb47 100644
@@ -73,7 +73,7 @@ static inline bool CFS_FAIL_PRECHECK(__u32 id)
 {
 	return cfs_fail_loc != 0 &&
 	       ((cfs_fail_loc & CFS_FAIL_MASK_LOC) == (id & CFS_FAIL_MASK_LOC) ||
-	        (cfs_fail_loc & id & CFS_FAULT));
+		(cfs_fail_loc & id & CFS_FAULT));
 }
 
 static inline int cfs_fail_check_set(__u32 id, __u32 value,
Signature · 1 line
1.7.1
#8 lore raw

PATCH 8/10 staging: lustre: libcfs: remove NULL comparisons in headers

In reply to James Simmons

Remove the NULL comparisions in the libcfs headers.

---
 .../lustre/include/linux/libcfs/libcfs_hash.h      |    2 +-
 .../lustre/include/linux/libcfs/libcfs_private.h   |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +1 -1
index 85661b3..d0ba3e0 100644
@@ -818,7 +818,7 @@ static inline int __cfs_hash_theta(struct cfs_hash *hs)
 {
 	unsigned int i, hash = 5381;
 
-	LASSERT(key != NULL);
+	LASSERT(key);
 
 	for (i = 0; i < size; i++)
 		hash = hash * 33 + ((char *)key)[i];
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +2 -2
index 93bff1b..fc180b8 100644
@@ -96,7 +96,7 @@
 
 #define LIBCFS_ALLOC_POST(ptr, size)					    \
 do {									    \
-	if (unlikely((ptr) == NULL)) {					    \
+	if (!unlikely((ptr))) {						    \
 		CERROR("LNET: out of memory at %s:%d (tried to alloc '"	    \
 		       #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));  \
 	} else {							    \
@@ -147,7 +147,7 @@
 
 #define LIBCFS_FREE(ptr, size)					  \
 do {								    \
-	if (unlikely((ptr) == NULL)) {				  \
+	if (!unlikely((ptr))) {						\
 		CERROR("LIBCFS: free NULL '" #ptr "' (%d bytes)@"    \
 		       "%s:%d\n", (int)(size), __FILE__, __LINE__);	\
 		break;						  \
Signature · 1 line
1.7.1
#10 lore raw

PATCH 9/10 staging: lustre: libcfs: remove zero comparisons in headers

In reply to James Simmons

Remove the zero comparisions in the libcfs headers.

---
 .../lustre/include/linux/libcfs/libcfs_crypto.h    |    2 +-
 .../lustre/include/linux/libcfs/libcfs_fail.h      |    4 +-
 .../lustre/include/linux/libcfs/libcfs_hash.h      |   32 ++++++++++----------
 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h +1 -1
index a0865e5..8f34c5d 100644
@@ -137,7 +137,7 @@ static inline unsigned char cfs_crypto_hash_alg(const char *algname)
 	enum cfs_crypto_hash_alg hash_alg;
 
 	for (hash_alg = 0; hash_alg < CFS_HASH_ALG_MAX; hash_alg++)
-		if (strcmp(hash_types[hash_alg].cht_name, algname) == 0)
+		if (!strcmp(hash_types[hash_alg].cht_name, algname))
 			return hash_alg;
 
 	return CFS_HASH_ALG_UNKNOWN;
drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h +2 -2
index 73cbb47..129047e 100644
@@ -71,7 +71,7 @@ enum {
 
 static inline bool CFS_FAIL_PRECHECK(__u32 id)
 {
-	return cfs_fail_loc != 0 &&
+	return cfs_fail_loc &&
 	       ((cfs_fail_loc & CFS_FAIL_MASK_LOC) == (id & CFS_FAIL_MASK_LOC) ||
 		(cfs_fail_loc & id & CFS_FAULT));
 }
@@ -175,7 +175,7 @@ static inline void cfs_race(__u32 id)
 			cfs_race_state = 0;
 			CERROR("cfs_race id %x sleeping\n", id);
 			rc = wait_event_interruptible(cfs_race_waitq,
-						      cfs_race_state != 0);
+						      !!cfs_race_state);
 			CERROR("cfs_fail_race id %x awake, rc=%d\n", id, rc);
 		} else {
 			CERROR("cfs_fail_race id %x waking\n", id);
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +16 -16
index d0ba3e0..6231f47 100644
@@ -342,34 +342,34 @@ struct cfs_hash_ops {
 cfs_hash_with_no_lock(struct cfs_hash *hs)
 {
 	/* caller will serialize all operations for this hash-table */
-	return (hs->hs_flags & CFS_HASH_NO_LOCK) != 0;
+	return hs->hs_flags & CFS_HASH_NO_LOCK;
 }
 
 static inline int
 cfs_hash_with_no_bktlock(struct cfs_hash *hs)
 {
 	/* no bucket lock, one single lock to protect the hash-table */
-	return (hs->hs_flags & CFS_HASH_NO_BKTLOCK) != 0;
+	return hs->hs_flags & CFS_HASH_NO_BKTLOCK;
 }
 
 static inline int
 cfs_hash_with_rw_bktlock(struct cfs_hash *hs)
 {
 	/* rwlock to protect hash bucket */
-	return (hs->hs_flags & CFS_HASH_RW_BKTLOCK) != 0;
+	return hs->hs_flags & CFS_HASH_RW_BKTLOCK;
 }
 
 static inline int
 cfs_hash_with_spin_bktlock(struct cfs_hash *hs)
 {
 	/* spinlock to protect hash bucket */
-	return (hs->hs_flags & CFS_HASH_SPIN_BKTLOCK) != 0;
+	return hs->hs_flags & CFS_HASH_SPIN_BKTLOCK;
 }
 
 static inline int
 cfs_hash_with_add_tail(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_ADD_TAIL) != 0;
+	return hs->hs_flags & CFS_HASH_ADD_TAIL;
 }
 
 static inline int
@@ -380,55 +380,55 @@ struct cfs_hash_ops {
 	 * item can't be removed from hash unless it's
 	 * ZERO refcount
 	 */
-	return (hs->hs_flags & CFS_HASH_NO_ITEMREF) != 0;
+	return hs->hs_flags & CFS_HASH_NO_ITEMREF;
 }
 
 static inline int
 cfs_hash_with_bigname(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_BIGNAME) != 0;
+	return hs->hs_flags & CFS_HASH_BIGNAME;
 }
 
 static inline int
 cfs_hash_with_counter(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_COUNTER) != 0;
+	return hs->hs_flags & CFS_HASH_COUNTER;
 }
 
 static inline int
 cfs_hash_with_rehash(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_REHASH) != 0;
+	return hs->hs_flags & CFS_HASH_REHASH;
 }
 
 static inline int
 cfs_hash_with_rehash_key(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_REHASH_KEY) != 0;
+	return hs->hs_flags & CFS_HASH_REHASH_KEY;
 }
 
 static inline int
 cfs_hash_with_shrink(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_SHRINK) != 0;
+	return hs->hs_flags & CFS_HASH_SHRINK;
 }
 
 static inline int
 cfs_hash_with_assert_empty(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_ASSERT_EMPTY) != 0;
+	return hs->hs_flags & CFS_HASH_ASSERT_EMPTY;
 }
 
 static inline int
 cfs_hash_with_depth(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_DEPTH) != 0;
+	return hs->hs_flags & CFS_HASH_DEPTH;
 }
 
 static inline int
 cfs_hash_with_nblk_change(struct cfs_hash *hs)
 {
-	return (hs->hs_flags & CFS_HASH_NBLK_CHANGE) != 0;
+	return hs->hs_flags & CFS_HASH_NBLK_CHANGE;
 }
 
 static inline int
@@ -442,14 +442,14 @@ struct cfs_hash_ops {
 cfs_hash_is_rehashing(struct cfs_hash *hs)
 {
 	/* rehash is launched */
-	return hs->hs_rehash_bits != 0;
+	return !!hs->hs_rehash_bits;
 }
 
 static inline int
 cfs_hash_is_iterating(struct cfs_hash *hs)
 {
 	/* someone is calling cfs_hash_for_each_* */
-	return hs->hs_iterating || hs->hs_iterators != 0;
+	return hs->hs_iterating || hs->hs_iterators;
 }
 
 static inline int
Signature · 1 line
1.7.1
#12 lore raw

PATCH 10/10 staging: lustre: libcfs: use uXX instead of __uXX types in headers

In reply to James Simmons

The types __[u|s]XX is only used for UAPI headers and userspace. Only keep these types for the libcfs headers that are UAPI headers. The rest convert to the standard uXX types.

---
 .../staging/lustre/include/linux/libcfs/curproc.h  |    2 +-
 .../lustre/include/linux/libcfs/libcfs_cpu.h       |    2 +-
 .../lustre/include/linux/libcfs/libcfs_fail.h      |   12 +++---
 .../lustre/include/linux/libcfs/libcfs_hash.h      |   46 ++++++++++----------
 .../lustre/include/linux/libcfs/libcfs_string.h    |   12 +++---
 .../lustre/include/linux/libcfs/linux/linux-time.h |    8 ++--
 6 files changed, 41 insertions(+), 41 deletions(-)
drivers/staging/lustre/include/linux/libcfs/curproc.h +1 -1
index 6469a67..1ea27c9 100644
@@ -53,7 +53,7 @@
 #define current_pid()		(current->pid)
 #define current_comm()		(current->comm)
 
-typedef __u32 cfs_cap_t;
+typedef u32 cfs_cap_t;
 
 #define CFS_CAP_CHOWN		   0
 #define CFS_CAP_DAC_OVERRIDE	    1
drivers/staging/lustre/include/linux/libcfs/libcfs_cpu.h +1 -1
index 61bd951..6d8752a 100644
@@ -92,7 +92,7 @@ struct cfs_cpt_table {
 	/* node mask */
 	nodemask_t		ctb_nodemask;
 	/* version */
-	__u64			ctb_version;
+	u64			ctb_version;
 };
 
 static inline cpumask_t *
drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h +6 -6
index 129047e..fedb46d 100644
@@ -39,8 +39,8 @@
 extern wait_queue_head_t cfs_race_waitq;
 extern int cfs_race_state;
 
-int __cfs_fail_check_set(__u32 id, __u32 value, int set);
-int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set);
+int __cfs_fail_check_set(u32 id, u32 value, int set);
+int __cfs_fail_timeout_set(u32 id, u32 value, int ms, int set);
 
 enum {
 	CFS_FAIL_LOC_NOSET      = 0,
@@ -69,14 +69,14 @@ enum {
 
 #define CFS_FAULT	0x02000000 /* match any CFS_FAULT_CHECK */
 
-static inline bool CFS_FAIL_PRECHECK(__u32 id)
+static inline bool CFS_FAIL_PRECHECK(u32 id)
 {
 	return cfs_fail_loc &&
 	       ((cfs_fail_loc & CFS_FAIL_MASK_LOC) == (id & CFS_FAIL_MASK_LOC) ||
 		(cfs_fail_loc & id & CFS_FAULT));
 }
 
-static inline int cfs_fail_check_set(__u32 id, __u32 value,
+static inline int cfs_fail_check_set(u32 id, u32 value,
 				     int set, int quiet)
 {
 	int ret = 0;
@@ -130,7 +130,7 @@ static inline int cfs_fail_check_set(__u32 id, __u32 value,
 #define CFS_FAIL_CHECK_RESET_QUIET(id, value) \
 	cfs_fail_check_set(id, value, CFS_FAIL_LOC_RESET, 1)
 
-static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
+static inline int cfs_fail_timeout_set(u32 id, u32 value, int ms, int set)
 {
 	if (unlikely(CFS_FAIL_PRECHECK(id)))
 		return __cfs_fail_timeout_set(id, value, ms, set);
@@ -166,7 +166,7 @@ static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
  * sleep. The next thread that calls with the same fail_loc wakes up
  * the first and continues.
  */
-static inline void cfs_race(__u32 id)
+static inline void cfs_race(u32 id)
 {
 	if (CFS_FAIL_PRECHECK(id)) {
 		if (unlikely(__cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET))) {
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +23 -23

112 lines not on this page · raw message

drivers/staging/lustre/include/linux/libcfs/libcfs_string.h +6 -6
index f5a434d..41795d9 100644
@@ -62,9 +62,9 @@ struct cfs_range_expr {
 	 * Link to cfs_expr_list::el_exprs.
 	 */
 	struct list_head	re_link;
-	__u32		re_lo;
-	__u32		re_hi;
-	__u32		re_stride;
+	u32		re_lo;
+	u32		re_hi;
+	u32		re_stride;
 };
 
 struct cfs_expr_list {
@@ -76,13 +76,13 @@ struct cfs_expr_list {
 int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
 int cfs_str2num_check(char *str, int nob, unsigned int *num,
 		      unsigned int min, unsigned int max);
-int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
+int cfs_expr_list_match(u32 value, struct cfs_expr_list *expr_list);
 int cfs_expr_list_print(char *buffer, int count,
 			struct cfs_expr_list *expr_list);
 int cfs_expr_list_values(struct cfs_expr_list *expr_list,
-			 int max, __u32 **values);
+			 int max, u32 **values);
 static inline void
-cfs_expr_list_values_free(__u32 *values, int num)
+cfs_expr_list_values_free(u32 *values, int num)
 {
 	/*
 	 * This array is allocated by LIBCFS_ALLOC(), so it shouldn't be freed
drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h +4 -4
index b646acd..709e1ce 100644
@@ -76,23 +76,23 @@ static inline long cfs_duration_sec(long d)
 
 #define cfs_time_current_64 get_jiffies_64
 
-static inline __u64 cfs_time_add_64(__u64 t, __u64 d)
+static inline u64 cfs_time_add_64(u64 t, u64 d)
 {
 	return t + d;
 }
 
-static inline __u64 cfs_time_shift_64(int seconds)
+static inline u64 cfs_time_shift_64(int seconds)
 {
 	return cfs_time_add_64(cfs_time_current_64(),
 			       cfs_time_seconds(seconds));
 }
 
-static inline int cfs_time_before_64(__u64 t1, __u64 t2)
+static inline int cfs_time_before_64(u64 t1, u64 t2)
 {
 	return (__s64)t2 - (__s64)t1 > 0;
 }
 
-static inline int cfs_time_beforeq_64(__u64 t1, __u64 t2)
+static inline int cfs_time_beforeq_64(u64 t1, u64 t2)
 {
 	return (__s64)t2 - (__s64)t1 >= 0;
 }
Signature · 1 line
1.7.1
#9 lore raw

Re: [PATCH 08/10] staging: lustre: libcfs: remove NULL comparisons in headers

In reply to James Simmons

drivers/staging/lustre/include/linux/libcfs/libcfs_private.h line 99

Quoted 10 lines · James Simmons
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +1 -1
index 93bff1b..fc180b8 100644
@@ -96,7 +96,7 @@
 
 #define LIBCFS_ALLOC_POST(ptr, size)					    \
 do {									    \
-	if (unlikely((ptr) == NULL)) {					    \
+	if (!unlikely((ptr))) {						    \

Argh.... No. You did this with a Perl script?

This should be:

	if (unlikely(!ptr)) { ...

drivers/staging/lustre/include/linux/libcfs/libcfs_private.h line 150

Quoted 9 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +1 -1
 		CERROR("LNET: out of memory at %s:%d (tried to alloc '"	    \
 		       #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));  \
 	} else {							    \
@@ -147,7 +147,7 @@
 
 #define LIBCFS_FREE(ptr, size)					  \
 do {								    \
-	if (unlikely((ptr) == NULL)) {				  \
+	if (!unlikely((ptr))) {						\

Same.

Otherwise the unlikely hint is reversed from what we want.

regards,
dan carpenter

#11 lore raw

Re: [lustre-devel] [PATCH 09/10] staging: lustre: libcfs: remove zero comparisons in headers

In reply to James Simmons
Quoted 15 lines · James Simmons

Remove the zero comparisions in the libcfs headers.

---

.../lustre/include/linux/libcfs/libcfs_crypto.h    |    2 +-
.../lustre/include/linux/libcfs/libcfs_fail.h      |    4 +-
.../lustre/include/linux/libcfs/libcfs_hash.h      |   32 ++++++++++----------
3 files changed, 19 insertions(+), 19 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h +0 -0
index a0865e5..8f34c5d 100644

drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h static inline unsigned char cfs_crypto_hash_alg(const char *algname) · line 140

Quoted 5 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h +1 -1
@@ -137,7 +137,7 @@ static inline unsigned char cfs_crypto_hash_alg(const char *algname)
 	enum cfs_crypto_hash_alg hash_alg;
 
 	for (hash_alg = 0; hash_alg < CFS_HASH_ALG_MAX; hash_alg++)
-		if (strcmp(hash_types[hash_alg].cht_name, algname) == 0)
+		if (!strcmp(hash_types[hash_alg].cht_name, algname))

I'd really rather keep the "== 0" comparison for strcmp(), because IMHO !strcmp() reads like "the strings do not compare the same" and is confusing.

drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h

Quoted 6 lines

static inline int
cfs_hash_is_iterating(struct cfs_hash *hs)

{
	/* someone is calling cfs_hash_for_each_* */
drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h +1 -1
-	return hs->hs_iterating || hs->hs_iterators != 0;
+	return hs->hs_iterating || hs->hs_iterators;

Likewise, I'd rather keep comparisons == 0 or != 0 for cases where the variable is an actual number instead of just a return code or a pointer.

I don't think we need to be totally dogmatic about removing every comparison with 0 in all of the code, as that can reduce readability in some cases.

I know this patch has already landed, and it isn't the end of the world either way, but just wanted to forestall similar changes being made through the rest of the code.

Cheers, Andreas