Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1079935imm; Thu, 5 Jul 2018 14:22:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcJLKnyl4GuzL9sDKhs40AbD764lANc4hujD5Z7ctsVJRZeoKugpoHlautFRqsRE8+uyKvw X-Received: by 2002:a63:9543:: with SMTP id t3-v6mr1132506pgn.77.1530825772808; Thu, 05 Jul 2018 14:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530825772; cv=none; d=google.com; s=arc-20160816; b=Wk0+tl6RPTy4baVcX5Gw4dobXdSKcOC89FNVw+RMVyiaXPEDm+ofmcbfmZDj5X7LPL IqWq6I5tLOD3dm9RhsLycRDMRm02VebBM+LPQmMjFkeKXyz0NkMHL32hSRsvz1+4hFYb P9e7hacTRXRY/U0CN2aFvF8psVprxorMyBREZWvmhutFTzjaeV5BH9OU5ddBOarfb4w3 093Xhk6nCU34i0xBonyA0ehT/g8vIWy9l9QzQIYlET6oB6zvMtrUw07qp2ewKu5+xeVy 1tEhJ4fwECW8XX7yyo/RsTzmKWxajrDXPciZKjezBkIGcfboZj07TJT0gImR5gss5hTC Xiyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=0guluaHIOsH7YfldJPpbEjJ0acQ/k2AvWhU8Qt48Al8=; b=oFI4k0giJDEi6/q+MSUEaNO6goTmjpibbi2M+ZJsFLyZhXE8lwH9WpWz0kaRBoJC9n sHsHFhmJ45Yf5dZlRUSx0aSmTpX+ddgK9bHfJDQbMEKFlAkezs5vxxi7R9qNsXDH11TN yK+8XqkXCTe2A5kw+c+EnPraU5f4Ebqr3CNRKj8oLphsYEQxGFF/c2lxH3p7mMMKO6di q2z+07rhp9ghjmxI3PXoTuJw6gsVClGcva5ArwzqhF85AU5hrp1a6dueUm9jOo+w6/9v ouVPArWiR2sdk61IUsR1ZMeNueEg7+3wOVbtcdmfGdfaFFNQD2Kb3wl+1/+EvIxW8qqq /USg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=TK6nf3T9; dkim=pass header.i=@codeaurora.org header.s=default header.b=TK6nf3T9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10-v6si6795874pla.98.2018.07.05.14.22.38; Thu, 05 Jul 2018 14:22:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=TK6nf3T9; dkim=pass header.i=@codeaurora.org header.s=default header.b=TK6nf3T9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754221AbeGEVVr (ORCPT + 99 others); Thu, 5 Jul 2018 17:21:47 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:54724 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753928AbeGEVVq (ORCPT ); Thu, 5 Jul 2018 17:21:46 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DB61D60B19; Thu, 5 Jul 2018 21:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530825705; bh=M/5OQxHFijykufZ1bEODyWAYGHZgf4ucNE1PY1sodEo=; h=From:To:Cc:Subject:Date:From; b=TK6nf3T9mceV3RC/afBYFKe4pMEhQ9GmpledAyCN3Fh+zdBGcfksGhqTh4/Ib96FO o1q7SMmvJJJmY62Uh/pEyycZA1iejQo4lmI5xelxtQH1xVUiUHX+ykwjvVq6wV23tB wOYqjeSy3gfzEV1OtzKQ3ZOAy9VbyyjqESoK2Mck= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from pheragu-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: pheragu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3A9D960721; Thu, 5 Jul 2018 21:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530825705; bh=M/5OQxHFijykufZ1bEODyWAYGHZgf4ucNE1PY1sodEo=; h=From:To:Cc:Subject:Date:From; b=TK6nf3T9mceV3RC/afBYFKe4pMEhQ9GmpledAyCN3Fh+zdBGcfksGhqTh4/Ib96FO o1q7SMmvJJJmY62Uh/pEyycZA1iejQo4lmI5xelxtQH1xVUiUHX+ykwjvVq6wV23tB wOYqjeSy3gfzEV1OtzKQ3ZOAy9VbyyjqESoK2Mck= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3A9D960721 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=pheragu@codeaurora.org From: Prakruthi Deepak Heragu To: apw@canonical.com, joe@perches.com Cc: linux-kernel@vger.kernel.org, ckadabi@codeaurora.org, tsoni@codeaurora.org, bryanh@codeaurora.org, linux@arm.linux.org.uk, Prakruthi Deepak Heragu Subject: [PATCH v2] checkpatch: Check for invalid return codes Date: Thu, 5 Jul 2018 14:21:14 -0700 Message-Id: <1530825674-22131-1-git-send-email-pheragu@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Negative integer return codes should prefer to use #define - 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 --- 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 -\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