Skip to contentSkip to conversation

Checkpatch.pl false positive? "ERROR: return is not a function, parentheses are not required"

DISCUSSION Olimpiu Pascariu 4 participants 5 messages Mar 28, 2010 – Sep 2, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

I've used checkpatch.pl to verify drivers/staging/dt3155/dt3155_isr.c, in order to provide a patch which fixes the errors and warnings found by checkpatch.
The script returns the following error:
ERROR: return is not a function, parentheses are not required #155: FILE: staging/dt3155/dt3155_isr.c:155:
+ return (dt3155_fbuffer[m]->ready_head -

The original code is:

  return (dt3155_fbuffer[m]->ready_head -
           dt3155_fbuffer[m]->ready_len +
           dt3155_fbuffer[m]->nbuffers)%
          (dt3155_fbuffer[m]->nbuffers);

I've deleted the the first open parenthesis and the last close parenthesis, and now the code looks like this:

  return (dt3155_fbuffer[m]->ready_head -
           dt3155_fbuffer[m]->ready_len +
           dt3155_fbuffer[m]->nbuffers)%
          (dt3155_fbuffer[m]->nbuffers);

IMHO the code is correct, though an auxiliary variable could be used to avoid this error returned by checkpatch.pl.

Regards,
Olimpiu Pascariu

#1 lore raw
Quoted 18 lines · Olimpiu Pascariu

I've used checkpatch.pl to verify drivers/staging/dt3155/dt3155_isr.c, in order to provide a patch which fixes the errors and warnings found by checkpatch.
The script returns the following error:
ERROR: return is not a function, parentheses are not required #155: FILE: staging/dt3155/dt3155_isr.c:155:
+ return (dt3155_fbuffer[m]->ready_head -

The original code is:

  return (dt3155_fbuffer[m]->ready_head -
           dt3155_fbuffer[m]->ready_len +
           dt3155_fbuffer[m]->nbuffers)%
          (dt3155_fbuffer[m]->nbuffers);

I've deleted the the first open parenthesis and the last close parenthesis, and now the code looks like this:

Quoted 7 lines
  return (dt3155_fbuffer[m]->ready_head -
           dt3155_fbuffer[m]->ready_len +
           dt3155_fbuffer[m]->nbuffers)%
          (dt3155_fbuffer[m]->nbuffers);

IMHO the code is correct, though an auxiliary variable could be used to avoid this error returned by checkpatch.pl.

Yes, checkpatch.pl doesn't understand C.

#2 lore raw
Quoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Olimpiu Pascariu

return (dt3155_fbuffer[m]->ready_head -

           dt3155_fbuffer[m]->ready_len +
           dt3155_fbuffer[m]->nbuffers)%
          (dt3155_fbuffer[m]->nbuffers);

IMHO the code is correct, though an auxiliary variable could be used to avoid this error returned by checkpatch.pl.

Yes, checkpatch.pl doesn't understand C.

And as currently implemented, can not.

I think this passes checkpatch without warning:

	return (dt3155_fbuffer[m]->ready_head -
		dt3155_fbuffer[m]->ready_len +
		dt3155_fbuffer[m]->nbuffers) %
	       dt3155_fbuffer[m]->nbuffers;

It might be better to use a temporary for dt3155_fbuffer[m] so the code could look more like:

	return (p->ready_head - p->ready_len + p->nbuffers) % p->nbuffers;
#3 lore raw
Quoted 1 line · Joe Perches

I think this passes checkpatch without warning:

Yes, you are right.
Thank you.

#4 lore raw
In reply to Olimpiu Pascariu
Quoted 20 lines · Olimpiu Pascariu

Hi,

I've used checkpatch.pl to verify drivers/staging/dt3155/dt3155_isr.c, in order to provide a patch which fixes the errors and warnings found by checkpatch.
The script returns the following error:
ERROR: return is not a function, parentheses are not required #155: FILE: staging/dt3155/dt3155_isr.c:155:
+ return (dt3155_fbuffer[m]->ready_head -

The original code is:

  return (dt3155_fbuffer[m]->ready_head -
           dt3155_fbuffer[m]->ready_len +
           dt3155_fbuffer[m]->nbuffers)%
          (dt3155_fbuffer[m]->nbuffers);

I've deleted the the first open parenthesis and the last close parenthesis, and now the code looks like this:

Quoted 7 lines
  return (dt3155_fbuffer[m]->ready_head -
           dt3155_fbuffer[m]->ready_len +
           dt3155_fbuffer[m]->nbuffers)%
          (dt3155_fbuffer[m]->nbuffers);

IMHO the code is correct, though an auxiliary variable could be used to avoid this error returned by checkpatch.pl.

This code is indeed correct. This is a bug in checkpatch, I think I have sorted out the bug in the version below (which should be mirrored out shortly). If you could test the version below and let me know that would be helpful:

http://www.kernel.org/pub/linux/kernel/people/apw/checkpatch/checkpatch.pl-testing

-apw