lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Thu,  5 Jul 2018 14:21:14 -0700
From:   Prakruthi Deepak Heragu <pheragu@...eaurora.org>
To:     apw@...onical.com, joe@...ches.com
Cc:     linux-kernel@...r.kernel.org, ckadabi@...eaurora.org,
        tsoni@...eaurora.org, bryanh@...eaurora.org,
        linux@....linux.org.uk,
        Prakruthi Deepak Heragu <pheragu@...eaurora.org>
Subject: [PATCH v2] checkpatch: Check for invalid return codes

Negative integer return codes should prefer to use #define -<ERRNO>
values instead of negative numbers. This patch checks if there are any
negative numbers returned. 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: Prakruthi Deepak Heragu <pheragu@...eaurora.org>
---
Changes in v2:
- Edit the descritpion to 'avoid returning any negative integers' rather 
  than saying 'returning anything but 0 is incorrect'
- Use APPROPRIATE_ERRNO instead of NO_ERROR_CODE as type of the message

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..0f9c717 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("APPROPRIATE_ERRNO",
+			      "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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ