Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5618775imm; Tue, 16 Oct 2018 13:11:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV60quFjiKYD/cx9HRQPzP72q31tqFV6WwywmMS9VwTRy5it8d6gOCktRsgSL57CW/4xj2ya8 X-Received: by 2002:a62:1551:: with SMTP id 78-v6mr23347237pfv.178.1539720683498; Tue, 16 Oct 2018 13:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539720683; cv=none; d=google.com; s=arc-20160816; b=XDv58uvZy61Tve8SbUos/BYDXfBRWLB59NrDKgDHC952+nA4H4Su4BEoSU7Zp4+3po pAB23yIjVo8fXsCBkcNc/q+c5XXgZ/KJJfOdd8NilqiW/wVC9LxPvcN4MHx5OCdB4Pdi DWcxv2l4fAIsbrGHkpI6SA7lAyVUxoHBUVsFSmJSUBAVItI7c7/UnC/Sybqy/3Ez7lG1 1GI54pgksKKbIBOUizokIFW9vHi6wrWFG/rnT1K2LmKVHBXWXsRU08JSrbju8Rg77vXt mR6aEfkGSstfFlPqXrXnRQxTzUHeqoDLudQI3sjqOQJp6jI0fL4yNDGkctQNcNsk+OjC e8HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:organization :content-disposition:mime-version:message-id:subject:cc:to:from:date; bh=fKEFsPoARbKw6gpbJelaiMBtU3yb+anZ7Un1GVgt7Rs=; b=zUeLicd5l24qL883GpLUDEJaXNwTjZTco7qPpKhTzOTGzKiN+RMPWEB2yCwQ8hHNFR lERxZB1wMQrBbqOSjyTbKC6V+FRvgYjp0bpRHV7XhK0iLAxT9W7ezVwwuupJxQcZA63k 8EtX9BH3uPZ9WEBJ3VHIfZIzLI43PtoYFdrom74SpwUA2orf0qmjw9NSsKDTyPhQq+wo AwnahYasxUIkjeuDy7raBIoif4fU5H4KVLO9LIDA9GC0eMz4s7qpAdatroCfB3HbWn+B cN28AgQajx+DM6gAJKJD/kIpoEkU/r5LyfwZnzNtelYqdHuseoHEHuQLq35vx6jZxh97 SGOw== ARC-Authentication-Results: i=1; mx.google.com; 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 j10-v6si14578578pgk.22.2018.10.16.13.11.07; Tue, 16 Oct 2018 13:11:23 -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; 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 S1727162AbeJQECt (ORCPT + 99 others); Wed, 17 Oct 2018 00:02:49 -0400 Received: from mail.gnudd.com ([77.43.112.34]:50937 "EHLO mail.gnudd.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725938AbeJQECt (ORCPT ); Wed, 17 Oct 2018 00:02:49 -0400 Received: from mail.gnudd.com (localhost [127.0.0.1]) by mail.gnudd.com (8.14.4/8.14.4/Debian-4+deb7u1) with ESMTP id w9GKASJh003265; Tue, 16 Oct 2018 22:10:28 +0200 Received: (from rubini@localhost) by mail.gnudd.com (8.14.4/8.14.4/Submit) id w9GKASVS003264; Tue, 16 Oct 2018 22:10:28 +0200 Date: Tue, 16 Oct 2018 22:10:28 +0200 From: Alessandro Rubini To: u.kleine-koenig@pengutronix.de Cc: viro@ZenIV.linux.org.uk, Michal.Vokac@ysoft.com, corbet@lwn.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, thierry.reding@gmail.com, kernel@pengutronix.de, akpm@linux-foundation.org Subject: Re: [PATCH RFC] err.h: document that PTR_ERR should only be used if IS_ERR returns true Message-ID: <20181016201028.GA3257@mail.gnudd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Organization: GnuDD, Device Drivers, Embedded Systems, Courses In-Reply-To: <20181016192928.pinjwxfors4reigh@pengutronix.de> References: <20181016192928.pinjwxfors4reigh@pengutronix.de> <20181014202807.16412-1-uwe@kleine-koenig.org> <20181015093708.GA22876@mail.gnudd.com> <20181016180650.GZ32577@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Me: >> > OTOH I admit you can compare any value with -EINVAL, after PTR_ERR. >> > But in general you first detect the error condition and then split >> > among error (or print a message according to the exact value. Al Viro: >> >> if (IS_ERR(p) && PTR_ERR(p) == -ENOENT) >> instead of >> if (p == ERR_PTR(-ENOENT)) >> >> is ugly, obfuscating what's going on for no good reason and I'm going >> to keep killing those every time I run into one... Sure. I was talking about selecting among errors in the error path, after you left the fast path jumping away with IS_ERR(). (in short, I agree). Uwe kleine-koenig > And what do you do if you see a > > p = somefunc(...); > if (PTR_ERR(p) == -ENOENT) > > without first checking for IS_ERR(p)? I see no problem. The original suggestion (only use if IS_ERR), which was mine, refers to doing error management in error cases. Sure if you know the return value is valid or -ENOENT you don't need to verify it is negative before comparing with -2. Both PTR_ERR and ERR_PTR are just a cast to prevent a warning (and tell the reader that you convert from err to ptr or vv), so I think the two are equivalent. Al's version above is maybe cleaner, but we are bikeshedding, IMHO. best /alessandro