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


Groups > linux.kernel > #1585792 > unrolled thread

checkpatch suspected false positive

Started by"Tobin C. Harding" <me@tobin.cc>
First post2017-02-22 00:10 +0100
Last post2017-02-22 01:00 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  checkpatch suspected false positive "Tobin C. Harding" <me@tobin.cc> - 2017-02-22 00:10 +0100
    Re: checkpatch suspected false positive Joe Perches <joe@perches.com> - 2017-02-22 00:20 +0100
      Re: checkpatch suspected false positive "Tobin C. Harding" <me@tobin.cc> - 2017-02-22 01:00 +0100

#1585792 — checkpatch suspected false positive

From"Tobin C. Harding" <me@tobin.cc>
Date2017-02-22 00:10 +0100
Subjectcheckpatch suspected false positive
Message-ID<tdrJg-Yh-3@gated-at.bofh.it>
Checkpatch may be giving a false positive of type CONST_STRUCT when
parsing files in drivers/staging/comedi/drivers.

$ pwd
build/kernel/linux-trees/gregKH/staging/

$ cd drivers/staging/comedi/drivers

$ checkpatch --terse --show-types *.c | grep CONST_STRUCT
addi_apci_3501.c:97: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
das16.c:972: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
das16.c:1006: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
jr3_pci.c:659: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
jr3_pci.c:667: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
jr3_pci.c:668: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
ni_670x.c:212: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const

snippet from das16.c

/* get any user-defined input range */
if (pg_type == das16_pg_none && (min || max)) {
	struct comedi_lrange *lrange;
	struct comedi_krange *krange;

	/* allocate single-range range table */
	lrange = comedi_alloc_spriv(s, sizeof(*lrange) + sizeof(*krange));
	if (!lrange)
		return &range_unknown;

	/* initialize ai range */
	lrange->length = 1;
	krange = lrange->range;
	krange->min = min;
	krange->max = max;
	krange->flags = UNIT_volt;

	return lrange;
}

From snippet it may be seen that struct comedi_lrange *lrange should
not be const.

In the event that I am in the wrong and checkpatch is correct please
feel free to bluntly correct me.

thanks,
Tobin.

[toc] | [next] | [standalone]


#1585798

FromJoe Perches <joe@perches.com>
Date2017-02-22 00:20 +0100
Message-ID<tdrSV-11G-7@gated-at.bofh.it>
In reply to#1585792
On Wed, 2017-02-22 at 10:01 +1100, Tobin C. Harding wrote:
> Checkpatch may be giving a false positive of type CONST_STRUCT when
> parsing files in drivers/staging/comedi/drivers.
> 
> $ pwd
> build/kernel/linux-trees/gregKH/staging/
> 
> $ cd drivers/staging/comedi/drivers
> 
> $ checkpatch --terse --show-types *.c | grep CONST_STRUCT
> addi_apci_3501.c:97: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> das16.c:972: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> das16.c:1006: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> jr3_pci.c:659: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> jr3_pci.c:667: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> jr3_pci.c:668: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> ni_670x.c:212: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const

checkpatch is brainless, it just looks for patterns
that are atypical.

$ git grep -E "struct\s+comedi_lrange\b" | wc -l
223
$ git grep -E "const\s+struct\s+comedi_lrange\b" | wc -l
215

So, yes, that struct is normally const.
Normally doesn't mean always or has to be.

[toc] | [prev] | [next] | [standalone]


#1585815

From"Tobin C. Harding" <me@tobin.cc>
Date2017-02-22 01:00 +0100
Message-ID<tdsvD-1fc-3@gated-at.bofh.it>
In reply to#1585798
On Tue, Feb 21, 2017 at 03:19:22PM -0800, Joe Perches wrote:
> On Wed, 2017-02-22 at 10:01 +1100, Tobin C. Harding wrote:
> > Checkpatch may be giving a false positive of type CONST_STRUCT when
> > parsing files in drivers/staging/comedi/drivers.
> > 
> > $ pwd
> > build/kernel/linux-trees/gregKH/staging/
> > 
> > $ cd drivers/staging/comedi/drivers
> > 
> > $ checkpatch --terse --show-types *.c | grep CONST_STRUCT
> > addi_apci_3501.c:97: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> > das16.c:972: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> > das16.c:1006: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> > jr3_pci.c:659: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> > jr3_pci.c:667: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> > jr3_pci.c:668: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> > ni_670x.c:212: WARNING:CONST_STRUCT: struct comedi_lrange should normally be const
> 
> checkpatch is brainless, it just looks for patterns
> that are atypical.
> 
> $ git grep -E "struct\s+comedi_lrange\b" | wc -l
> 223
> $ git grep -E "const\s+struct\s+comedi_lrange\b" | wc -l
> 215
> 
> So, yes, that struct is normally const.
> Normally doesn't mean always or has to be.
> 

Cheers Joe. I'm sure this is not the first time you have explained
that. Would it be a good idea to add some documentation (in
Documentation/process) about checkpatch gotchas. Perhaps we could save
some people some time if every newbie didn't have to make the same
mistakes (or ask the same questions).

The first two could be;

1. Don't fix line over 80 warnings if it does not objectively make the
code more readable (see coding-style.rst, grep for 'Statements longer
than 80 columns').

2. Warning struct foo should normally be const ... description of how
checkpatch decides this warning is necessary.

thanks,
Tobin.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web