public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] checkpatch: Check for invalid return codes
@ 2018-07-03 23:41 Prakruthi Deepak Heragu
  2018-07-04  1:40 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Prakruthi Deepak Heragu @ 2018-07-03 23:41 UTC (permalink / raw)
  To: apw, joe
  Cc: linux-kernel, ckadabi, bryanh, tsoni, Patrick Pannuto,
	Stepan Moskovchenko, Prakruthi Deepak Heragu

The only valid integer return is 0, anything else
following "return" should be -ERRCODE or a function. Also, display context
so that the user knows where the return value is incorrect.

http://lkml.org/lkml/2010/7/23/318
  There's lots of "return -1;" statements in this patch - it's obscene
  that this is used to indicate "some error occurred" in kernel space
  rather than a real errno value - even when an existing function
  (eg, request_irq) gave you an error code already.

Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
Signed-off-by: Prakruthi Deepak Heragu <pheragu@codeaurora.org>
---
Changes in v1:
- Use CHK instead of ERROR
- Rephrase the warning message
- Provide the file name and line number where return value is incorrect

 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a9c0550..2808c27 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6197,6 +6197,12 @@ sub process {
 			     "switch default: should use break\n" . $herectx);
 		}
 
+# check for return codes on error paths
+		if ($line =~ /\breturn\s+-\d+/) {
+			CHK("NO_ERROR_CODE",
+			      "invalid return value, please return -<APPROPRIATE_ERRNO>\n" . $herecurr);
+		}
+
 # check for gcc specific __FUNCTION__
 		if ($line =~ /\b__FUNCTION__\b/) {
 			if (WARN("USE_FUNC",
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


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

end of thread, other threads:[~2018-07-04  1:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-03 23:41 [PATCH v1] checkpatch: Check for invalid return codes Prakruthi Deepak Heragu
2018-07-04  1:40 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox