Skip to contentSkip to conversation

staging:android_pmem.h: Fixes the space and other formating issues pointed out by checkpatch.pl

PATCH Dan Carpenter 3 participants 10 messages Jan 18, 2012 – Jan 20, 2012 3 messages not in the archive

lore
Share & tools
lore
#3 lore raw
In reply to a message not in the archive
Quoted 6 lines · Pradheep Shrinivasan
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

-#define PMEM_IOCTL_MAGIC 'p'

+#define PMEM_IOCTL_MAGIC ('p')

You don't need parenthesis here. Did checkpatch really complain about this?

Quoted 7 lines

Yes the check patch does complain about the parenthesis.

pradheep@ubuntu:~/linux-next/ linux-next/drivers/staging/android$ checkpatch android_pmem.h android_pmem.h:10: ERROR: trailing whitespace android_pmem.h:19: ERROR: Macros with complex values should be enclosed in parenthesis

That seems like a bug in checkpatch.pl. It's hard to imagine less complex macro than: #define PMEM_IOCTL_MAGIC 'p'

Perhaps if the check looked for one of these characters: */+-=<>|&

regards,
dan carpenter

#4 lore raw
Quoted 9 lines · Dan Carpenter
Quoted 8 lines · Pradheep Shrinivasan
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

-#define PMEM_IOCTL_MAGIC 'p'

+#define PMEM_IOCTL_MAGIC ('p')

You don't need parenthesis here.  Did checkpatch really complain about this?

Yes the check patch does complain about the parenthesis.

Quoted 8 lines
Quoted 5 lines

pradheep@ubuntu:~/linux-next/ linux-next/drivers/staging/android$ checkpatch android_pmem.h android_pmem.h:10: ERROR: trailing whitespace android_pmem.h:19: ERROR: Macros with complex values should be enclosed in parenthesis

That seems like a bug in checkpatch.pl.  It's hard to imagine less complex macro than:  #define PMEM_IOCTL_MAGIC 'p'

I can think of no way in which an unprotected character is different to an unprotected integer constant. So ...

Does the version here work better for you:

http://people.canonical.com/~apw/checkpatch/checkpatch-next.pl

-apw

#5 lore raw

It still complains about the following macros where parenthesis are not needed.

ERROR: Macros with complex values should be enclosed in parenthesis #156: FILE: staging/android/pmem.c:156:
+#define PMEM_IS_FREE(id, index) !(pmem[id].bitmap[index].allocated)

Let's just make the check look for an operator with a low precedence.
http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

Otherwise the submitters are going to change it to:

#define PMEM_IS_FREE(id, index) (!(pmem[id].bitmap[index].allocated))

That has two pairs of unneeded paranthesis and we run the risk of reprogramming the kernel in lisp, by mistake.

regards,
dan carpenter

#6 lore raw
Quoted 11 lines · Dan Carpenter

It still complains about the following macros where parenthesis are not needed.

ERROR: Macros with complex values should be enclosed in parenthesis #156: FILE: staging/android/pmem.c:156:
+#define PMEM_IS_FREE(id, index) !(pmem[id].bitmap[index].allocated)

Let's just make the check look for an operator with a low precedence.
http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

Quoted 6 lines

Otherwise the submitters are going to change it to:

#define PMEM_IS_FREE(id, index) (!(pmem[id].bitmap[index].allocated))

That has two pairs of unneeded paranthesis and we run the risk of reprogramming the kernel in lisp, by mistake.

Yep we want to avoid that. As -> binds tighter than many of the operators in these bands we can only safely avoid the ()'s if the operator does not potentially make a pointer, so for now I have added unary minus and the two unary not operators. I think I want to see some examples of other operators before I would be keen to have any further exceptions.

Anyhow how does this work for you:

http://people.canonical.com/~apw/checkpatch/checkpatch-next.pl

-apw

#10 lore raw
In reply to Andy Whitcroft
Quoted 6 lines · Andy Whitcroft
Quoted 5 lines · Dan Carpenter
Quoted 4 lines · Pradheep Shrinivasan
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

-#define PMEM_IOCTL_MAGIC 'p'

+#define PMEM_IOCTL_MAGIC ('p')

You don't need parenthesis here. Did checkpatch really complain about this?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Yes the check patch does complain about the parenthesis.

That seems like a bug in checkpatch.pl. It's hard to imagine less complex macro than: #define PMEM_IOCTL_MAGIC 'p'

I can think of no way in which an unprotected character is different to an unprotected integer constant. So ...
Does the version here work better for you:
http://people.canonical.com/~apw/checkpatch/checkpatch-next.pl

diff here is:

@@ -2838,7 +2849,8 @@

                        if ($dstat ne '' &&
                            $dstat !~ /^(?:$Ident|-?$Constant),$/ &&                    # 10, // foo(),
                            $dstat !~ /^(?:$Ident|-?$Constant);$/ &&                    # foo();
-                           $dstat !~ /^(?:$Ident|-?$Constant)$/ &&                     # 10 // foo()
+                           $dstat !~ /^[!~-]?(?:$Ident|$Constant)$/ &&         # 10 // foo() // !foo // ~foo // -foo
+                           $dstat !~ /^'X'$/ &&                                        # character constants
                            $dstat !~ /$exceptions/ &&
                            $dstat !~ /^\.$Ident\s*=/ &&                                # .foo =
                            $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&       # do {...} while (...); // do {...} while (...)

I think the character change test is fine but
the !~- addition/change is suspect.

!~- are precedence level 3 operators
and can be impacted by things like ++
and function calls.

#7 lore raw
In reply to Dan Carpenter
Quoted 11 lines · Dan Carpenter

It still complains about the following macros where parenthesis are not needed.

ERROR: Macros with complex values should be enclosed in parenthesis #156: FILE: staging/android/pmem.c:156:
+#define PMEM_IS_FREE(id, index) !(pmem[id].bitmap[index].allocated)

Let's just make the check look for an operator with a low precedence.
http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

Quoted 6 lines

Otherwise the submitters are going to change it to:

#define PMEM_IS_FREE(id, index) (!(pmem[id].bitmap[index].allocated))

That has two pairs of unneeded paranthesis and we run the risk of reprogramming the kernel in lisp, by mistake.

I think the outer parens are necessary. Imagine PMEM_IS_FREE(foo, bar).another_dereference

#11 lore raw
In reply to Joe Perches
Quoted 11 lines · Joe Perches
(quoted diff) +2 -1
@@ -2838,7 +2849,8 @@
                        if ($dstat ne '' &&
                            $dstat !~ /^(?:$Ident|-?$Constant),$/ &&                    # 10, // foo(),
                            $dstat !~ /^(?:$Ident|-?$Constant);$/ &&                    # foo();
-                           $dstat !~ /^(?:$Ident|-?$Constant)$/ &&                     # 10 // foo()
+                           $dstat !~ /^[!~-]?(?:$Ident|$Constant)$/ &&         # 10 // foo() // !foo // ~foo // -foo
+                           $dstat !~ /^'X'$/ &&                                        # character constants
                            $dstat !~ /$exceptions/ &&
                            $dstat !~ /^\.$Ident\s*=/ &&                                # .foo =
                            $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&       # do {...} while (...); // do {...} while (...)
Quoted 4 lines

I think the character change test is fine but
the !~- addition/change is suspect.

!~- are precedence level 3 operators

Level 2?

Quoted 1 line

and can be impacted by things like ++

They work like you would expect:

#define NOT_FOO !foo
	++NOT_FOO <-- compile error.
	NOT_FOO++ <-- works.

Anyway if people are really writing macros which are used this way, then that's something which is outside of the scope of checkpatch.pl to fix.

regards,
dan carpenter

#8 lore raw
In reply to Joe Perches
Quoted 7 lines · Joe Perches
Quoted 4 lines

#define PMEM_IS_FREE(id, index) (!(pmem[id].bitmap[index].allocated))

That has two pairs of unneeded paranthesis and we run the risk of reprogramming the kernel in lisp, by mistake.

I think the outer parens are necessary. Imagine PMEM_IS_FREE(foo, bar).another_dereference

That's not going to happen in real life.

regards,
dan carpenter

#9 lore raw
In reply to Joe Perches
Quoted 14 lines · Joe Perches
Quoted 13 lines · Dan Carpenter

It still complains about the following macros where parenthesis are not needed.

ERROR: Macros with complex values should be enclosed in parenthesis #156: FILE: staging/android/pmem.c:156:
+#define PMEM_IS_FREE(id, index) !(pmem[id].bitmap[index].allocated)

Let's just make the check look for an operator with a low precedence.
http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

Otherwise the submitters are going to change it to:

Quoted 7 lines
Quoted 4 lines

#define PMEM_IS_FREE(id, index) (!(pmem[id].bitmap[index].allocated))

That has two pairs of unneeded paranthesis and we run the risk of reprogramming the kernel in lisp, by mistake.

I think the outer parens are necessary. Imagine PMEM_IS_FREE(foo, bar).another_dereference

I don't believe that makes any sense does it, those are pointer operations, and passing 0/1 to those is going to make the . very unhappy. But that is why I am only proposing to do the three which are non-sensicle on pointers.

-apw

#12 lore raw
In reply to Dan Carpenter
Quoted 15 lines · Dan Carpenter
Quoted 10 lines · Joe Perches
(quoted diff) +2 -1
@@ -2838,7 +2849,8 @@
                        if ($dstat ne '' &&
                            $dstat !~ /^(?:$Ident|-?$Constant),$/ &&                    # 10, // foo(),
                            $dstat !~ /^(?:$Ident|-?$Constant);$/ &&                    # foo();
-                           $dstat !~ /^(?:$Ident|-?$Constant)$/ &&                     # 10 // foo()
+                           $dstat !~ /^[!~-]?(?:$Ident|$Constant)$/ &&         # 10 // foo() // !foo // ~foo // -foo
+                           $dstat !~ /^'X'$/ &&                                        # character constants
                            $dstat !~ /$exceptions/ &&
                            $dstat !~ /^\.$Ident\s*=/ &&                                # .foo =
                            $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&       # do {...} while (...); // do {...} while (...)
Quoted 3 lines

I think the character change test is fine but
the !~- addition/change is suspect.
!~- are precedence level 3 operators

Level 2?

Table I looked at said 3,
http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/language/ref/clrc05preeval.htm
but 1 is c++ only, so you're right
c level 2.

Quoted 3 lines

Anyway if people are really writing macros which are used this way, then that's something which is outside of the scope of checkpatch.pl to fix.

I think there are some convenience macros like:
#define helper(a, b) some->long[a]->dereference.b

but likely anyone that really wants to add a
!~- prefix to those should be mindful anyway.