From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=0.1 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_MUA_MOZILLA,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E346AC4338F for ; Sun, 25 Jul 2021 18:08:08 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 526E46052B for ; Sun, 25 Jul 2021 18:08:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 526E46052B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1m7iXD-0000GX-IQ; Sun, 25 Jul 2021 14:07:31 -0400 Received: from ciao.gmane.io ([116.202.254.214]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m7iXC-0000GR-Dn for kernelnewbies@kernelnewbies.org; Sun, 25 Jul 2021 14:07:30 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1m7iX9-00081x-4p for kernelnewbies@kernelnewbies.org; Sun, 25 Jul 2021 20:07:27 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: kernelnewbies@kernelnewbies.org From: Ian Pilcher Subject: Return value for "impossible" situations Date: Sun, 25 Jul 2021 13:07:21 -0500 Message-ID: Mime-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 X-Mozilla-News-Host: news://news.gmane.org:119 Content-Language: en-US X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kernelnewbies-bounces@kernelnewbies.org In user space, I use assertions to check (and document) the assumptions built in to my code - this value won't ever be negative, this int will only ever by one of these 3 values, etc. For kernel code, I can use pr_err, dump_stack, WARN_ON, etc. to report the issue in the log, but I often also need to return some sort of error code (negative errno value). Is there any sort of convention around what to return in the case of an error in the logic of the code itself, something that will make it as obvious as possible that the problem is a bug. TIA! -- ======================================================================== In Soviet Russia, Google searches you! ======================================================================== _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies