Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1218503

Re: [GIT] Networking

From Joe Perches <joe@perches.com>
Newsgroups linux.kernel
Subject Re: [GIT] Networking
Date 2015-09-03 20:40 +0200
Message-ID <q4HAu-3ib-17@gated-at.bofh.it> (permalink)
References <q4vpF-2GW-25@gated-at.bofh.it> <q4FS3-M8-27@gated-at.bofh.it> <q4GO6-28h-25@gated-at.bofh.it> <q4HqO-37a-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, 2015-09-03 at 11:22 -0700, Linus Torvalds wrote:
> On Thu, Sep 3, 2015 at 10:40 AM, David Miller <davem@davemloft.net> wrote:
> >
> > Linus, what GCC version are you using and what does the warning look
> > like?
> 
> I'm on whatever is in F22. gcc -v says
> 
>    gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)
> 
> and the warning looks like so:
> 
>   net/mac80211/rate.c: In function ‘rate_control_cap_mask’:
>   net/mac80211/rate.c:719:25: warning: ‘sizeof’ on array function
> parameter ‘mcs_mask’ will return size of ‘u8 * {aka unsigned char *}’
> [-Wsizeof-array-argument]
>      for (i = 0; i < sizeof(mcs_mask); i++)
>                            ^
> 
> (note the lack of warning about the use of an array in the function
> definition parameter list - I tried to find if there's any way to
> enable such a warning, but couldn't find anything. Maybe my google-fu
> is weak, but more probably that just doesn't exist).

Coccinelle might be a better tool for this but
a possible checkpatch patch is below:

It produces output like:

$ ./scripts/checkpatch.pl -f net/iucv/iucv.c --types=sized_array_argument
WARNING: Avoid sized array arguments
#716: FILE: net/iucv/iucv.c:716:
+static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
+{

WARNING: Avoid sized array arguments
#878: FILE: net/iucv/iucv.c:878:
+int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
+		     u8 userdata[16], void *private)
+{

WARNING: Avoid sized array arguments
#925: FILE: net/iucv/iucv.c:925:
+int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
+		      u8 userid[8], u8 system[8], u8 userdata[16],
+		      void *private)
+{

WARNING: Avoid sized array arguments
#988: FILE: net/iucv/iucv.c:988:
+int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
+{

WARNING: Avoid sized array arguments
#1020: FILE: net/iucv/iucv.c:1020:
+int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
+{

WARNING: Avoid sized array arguments
#1050: FILE: net/iucv/iucv.c:1050:
+int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
+{

total: 0 errors, 6 warnings, 0 checks, 2119 lines checked
---
 scripts/checkpatch.pl | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e14dcdb..747b164 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5422,6 +5422,24 @@ sub process {
 			     "externs should be avoided in .c files\n" .  $herecurr);
 		}
 
+# check for function arguments using arg[SIZE]
+		if ($^V && $^V ge 5.10.0 &&
+		    defined $stat &&
+		    $stat =~ /^.\s*(?:$Declare|$DeclareMisordered)\s*$Ident\s*($balanced_parens)\s*\{/s) {
+			my $func_args = $1;
+			if ($func_args =~ /(.*)\[\s*(?:$Constant|[A-Z0-9_]+)\s*\]/ && (!defined($1) || $1 !~ /\[\s*\]\s*$/)) {
+				my $ctx = '';
+				my $herectx = $here . "\n";
+				my $cnt = statement_rawlines($stat);
+				for (my $n = 0; $n < $cnt; $n++) {
+					$herectx .= raw_line($linenr, $n) . "\n";
+					$n = $cnt if ($herectx =~ /{/);
+				}
+				WARN("SIZED_ARRAY_ARGUMENT",
+				     "Avoid sized array arguments\n" . $herectx);
+			}
+		}
+
 # checks for new __setup's
 		if ($rawline =~ /\b__setup\("([^"]*)"/) {
 			my $name = $1;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-03 18:50 +0200
  Re: [GIT] Networking David Miller <davem@davemloft.net> - 2015-09-03 19:50 +0200
    Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-03 20:30 +0200
      Re: [GIT] Networking Joe Perches <joe@perches.com> - 2015-09-03 20:40 +0200
        Re: [GIT] Networking Julia Lawall <julia.lawall@lip6.fr> - 2015-09-03 21:40 +0200
          Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-03 21:50 +0200
            Re: [GIT] Networking Julia Lawall <julia.lawall@lip6.fr> - 2015-09-03 23:00 +0200
              Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-03 23:10 +0200
                Re: [GIT] Networking Julia Lawall <julia.lawall@lip6.fr> - 2015-09-03 23:30 +0200
      Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-09-03 20:40 +0200
        Re: [GIT] Networking Marcel Holtmann <marcel@holtmann.org> - 2015-09-03 23:10 +0200
          RE: [GIT] Networking David Laight <David.Laight@ACULAB.COM> - 2015-09-04 11:10 +0200
            Re: [GIT] Networking "Rustad, Mark D" <mark.d.rustad@intel.com> - 2015-09-04 19:40 +0200
      Re: [GIT] Networking David Miller <davem@davemloft.net> - 2015-09-03 20:50 +0200
  Re: [GIT] Networking Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> - 2015-09-05 18:20 +0200

csiph-web