LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] staging: lustre: libcfs: add parens around macros args
@ 2018-05-22 13:34 Ivan Bornyakov
  2018-05-22 19:36 ` [PATCH] checkpatch: Fix macro argument precedence test Joe Perches
  2018-05-30 12:06 ` [PATCH] staging: lustre: libcfs: add parens around macros args Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Ivan Bornyakov @ 2018-05-22 13:34 UTC (permalink / raw)
  To: lustre-devel
  Cc: oleg.drokin, andreas.dilger, jsimmons, gregkh, devel,
	linux-kernel, Ivan Bornyakov

One may call 'CFS_FAIL_TIMEOUT(id, secs + 5);' and get unexpected result
after macro substitution, viz., 'secs + 5' will turn into
'secs + 5 * 1000'

Signed-off-by: Ivan Bornyakov <brnkv.i1@gmail.com>
---
 drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
index d6fc3164e7e7..f96b9a51554d 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
@@ -140,7 +140,7 @@ static inline int cfs_fail_timeout_set(u32 id, u32 value, int ms, int set)
 
 /* If id hit cfs_fail_loc, sleep for seconds or milliseconds */
 #define CFS_FAIL_TIMEOUT(id, secs) \
-	cfs_fail_timeout_set(id, 0, secs * 1000, CFS_FAIL_LOC_NOSET)
+	cfs_fail_timeout_set(id, 0, (secs) * 1000, CFS_FAIL_LOC_NOSET)
 
 #define CFS_FAIL_TIMEOUT_MS(id, ms) \
 	cfs_fail_timeout_set(id, 0, ms, CFS_FAIL_LOC_NOSET)
@@ -150,10 +150,10 @@ static inline int cfs_fail_timeout_set(u32 id, u32 value, int ms, int set)
  * sleep seconds or milliseconds
  */
 #define CFS_FAIL_TIMEOUT_ORSET(id, value, secs) \
-	cfs_fail_timeout_set(id, value, secs * 1000, CFS_FAIL_LOC_ORSET)
+	cfs_fail_timeout_set(id, value, (secs) * 1000, CFS_FAIL_LOC_ORSET)
 
 #define CFS_FAIL_TIMEOUT_RESET(id, value, secs) \
-	cfs_fail_timeout_set(id, value, secs * 1000, CFS_FAIL_LOC_RESET)
+	cfs_fail_timeout_set(id, value, (secs) * 1000, CFS_FAIL_LOC_RESET)
 
 #define CFS_FAIL_TIMEOUT_MS_ORSET(id, value, ms) \
 	cfs_fail_timeout_set(id, value, ms, CFS_FAIL_LOC_ORSET)
-- 
2.16.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] checkpatch: Fix macro argument precedence test
  2018-05-22 13:34 [PATCH] staging: lustre: libcfs: add parens around macros args Ivan Bornyakov
@ 2018-05-22 19:36 ` Joe Perches
  2018-05-30 12:06 ` [PATCH] staging: lustre: libcfs: add parens around macros args Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2018-05-22 19:36 UTC (permalink / raw)
  To: Andrew Morton, Andy Whitcroft, LKML; +Cc: Ivan Bornyakov, lustre-devel

checkpatch's macro argument precedence test is broken so fix it.

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index baddac9379f0..68879aa65cfd 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5041,7 +5041,7 @@ sub process {
 				$tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
 				$tmp_stmt =~ s/\#+\s*$arg\b//g;
 				$tmp_stmt =~ s/\b$arg\s*\#\#//g;
-				my $use_cnt = $tmp_stmt =~ s/\b$arg\b//g;
+				my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;
 				if ($use_cnt > 1) {
 					CHK("MACRO_ARG_REUSE",
 					    "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: lustre: libcfs: add parens around macros args
  2018-05-22 13:34 [PATCH] staging: lustre: libcfs: add parens around macros args Ivan Bornyakov
  2018-05-22 19:36 ` [PATCH] checkpatch: Fix macro argument precedence test Joe Perches
@ 2018-05-30 12:06 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2018-05-30 12:06 UTC (permalink / raw)
  To: Ivan Bornyakov
  Cc: lustre-devel, devel, gregkh, linux-kernel, oleg.drokin, andreas.dilger

On Tue, May 22, 2018 at 04:34:39PM +0300, Ivan Bornyakov wrote:
> One may call 'CFS_FAIL_TIMEOUT(id, secs + 5);' and get unexpected result
> after macro substitution, viz., 'secs + 5' will turn into
> 'secs + 5 * 1000'
> 

We actually do that in ptl_send_rpc() as well so this is a real bug.

It's sort of an interesting coincidence that the code in ptl_send_rpc()
looks almost exactly like your theoretical code:

	OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_DELAY_SEND, request->rq_timeout + 5);

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-30 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-22 13:34 [PATCH] staging: lustre: libcfs: add parens around macros args Ivan Bornyakov
2018-05-22 19:36 ` [PATCH] checkpatch: Fix macro argument precedence test Joe Perches
2018-05-30 12:06 ` [PATCH] staging: lustre: libcfs: add parens around macros args Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).