Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp507293ybe; Tue, 10 Sep 2019 23:49:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsdTvjfNgvloT2IsUdlyDzo7eow7+z24FYleDLigr7ou+nZQhs0g0uGna5P027ayNLW4Dl X-Received: by 2002:a05:6402:1e7:: with SMTP id i7mr36052358edy.103.1568184544274; Tue, 10 Sep 2019 23:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568184544; cv=none; d=google.com; s=arc-20160816; b=FsGo7skmKzpS4Alt1Nhg34JfYVrPaOAFbvQ+/c11WOa7x1Z+NMbJlnl31CWeAcHcaj IvnzZcAsoWa9TgQBl2NePrPsQHnne0/JLsI8XuiNxiA07qWYpVrtU0Rc4eTDOda8vBXc vBYGV57bTyKOv54zyHnCIrx46SjGwSteS7FqNUFHiazvfThPTF4YR7ei1L9ZpsKLnYUJ i3egWorlUhS6gxm4XFvuYpL6AUzAgPyS7D5qp87iTHh74OWJKnSVm8Ta7GO0lLC6gUWo l1VM8a8mV9nzxDUm+wDHuXwVZ0Dtz+HtJ+PnGHVYMlo5rzmNFTG5dOfGppJyx9KZPnto 6Nfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=xBgrDTpEw0rQgn/ixXrLh1SNi1gyM1DCfH7+wgZte8w=; b=fUJ31SFqvLt6Eg32Th+mSG6jcgs+lS1DaWzPHG9APPjNlxTf3hvXsNtDU6ejnpjUj/ gxU/1DEB8lPowo4jYQ/zKiOqry+WsPc6xJ7aD38ja5CtQYqBVb10oP0q4euSzILVycaJ rFBTY3W/kNrit/rYInPvAUD+8Bi2wHcOK1vBQzSr3vcxwiKPFCiLr2C+rHDdb03vv3qw D3WhpU5PSsNmwabzMCdvpXZWRzwNbmHhz2CTcs8bkX1L6vv4bBxFnpDPsbzB1jgmEZOf 4AvDllutqEwHhcJggkTQbHHlpngVyUaPjy3keqLi5THYLvxAnL4Ecphxlvo5WTfWX2Ql bJ/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Mdw1iEYP; 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 w5si4859063edf.283.2019.09.10.23.48.38; Tue, 10 Sep 2019 23:49:04 -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=@rasmusvillemoes.dk header.s=google header.b=Mdw1iEYP; 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 S1727055AbfIKGn0 (ORCPT + 99 others); Wed, 11 Sep 2019 02:43:26 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:45388 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbfIKGn0 (ORCPT ); Wed, 11 Sep 2019 02:43:26 -0400 Received: by mail-lj1-f194.google.com with SMTP id q64so8305252ljb.12 for ; Tue, 10 Sep 2019 23:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=xBgrDTpEw0rQgn/ixXrLh1SNi1gyM1DCfH7+wgZte8w=; b=Mdw1iEYPDsvdfG5R5BFHqM9Ekeawea62W7kvbDYteHhXCjwpip22SznIrXvysioEpT n4f9dVtyyGthnBVqxblNhg2whX1+TymJSoxGUAKko+JjoCTr2uQlyTmqX6wBrrK/RfD7 1mD9BtpHJY0jIMVTBSjWDiP3Im0E1Cy1qawiQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xBgrDTpEw0rQgn/ixXrLh1SNi1gyM1DCfH7+wgZte8w=; b=MqXH1pFona69RGmJhwNVtm+NZlGCV8rIbSK93T4VEke6CTQtZQLVimzmUY5W51m3Ad Ci/JdcwbWl2hA7pQwM+m3WHtau/fQm0fYkIjficsuYeWPPwWVHH8Raulv61ZOKbrJge9 VHm0cZNTHam2TtbINNyjqhf3XaiovLty9QT27opke2+qSCDTeArUWdrsCn5Vg8KGNFEA zAhWu8teXC9JseIbN0iza75PST8SGKf4R7hGp5ybjIdZHPdbbVYNHKwNxcUi0GllBb0X bleTK7ZOaTW4nVUmOIFpPpqviru0wIkXm51VTatMCRsZGtVl+AX7dgs9eTidP+16HuON OQFQ== X-Gm-Message-State: APjAAAVIFuS5LE17t/pJy4Qw83scNB9a9oCpm9ykjMmhJQbA31MO1HnX xCgb7GbxU1GGvSwNYT6j12qRdQ== X-Received: by 2002:a2e:96da:: with SMTP id d26mr21538874ljj.7.1568184202827; Tue, 10 Sep 2019 23:43:22 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id 77sm4416923ljj.84.2019.09.10.23.43.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Sep 2019 23:43:22 -0700 (PDT) Subject: Re: [PATCH v2] printf: add support for printing symbolic error codes To: Joe Perches , Andy Shevchenko Cc: Andrew Morton , Jonathan Corbet , Petr Mladek , Sergey Senozhatsky , Jani Nikula , Linux Kernel Mailing List , =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , Linux Documentation List References: <20190830214655.6625-1-linux@rasmusvillemoes.dk> <20190909203826.22263-1-linux@rasmusvillemoes.dk> <95a9f6fbc8fc2cf81e9eadc6f7fef8dd3592e60b.camel@perches.com> From: Rasmus Villemoes Message-ID: <354dc1f5-45b8-9e51-1ba0-b1fd368be45a@rasmusvillemoes.dk> Date: Wed, 11 Sep 2019 08:43:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <95a9f6fbc8fc2cf81e9eadc6f7fef8dd3592e60b.camel@perches.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/09/2019 02.15, Joe Perches wrote: > On Tue, 2019-09-10 at 18:26 +0300, Andy Shevchenko wrote: >> On Mon, Sep 9, 2019 at 11:39 PM Rasmus Villemoes >> wrote: >>> +#define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = #err >>> +#define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = #err >> >> From long term prospective 300 and 550 hard coded here may be forgotten. No? The point of the BUILD_BUG_ON_ZEROs is that if you add a new Esomething, you'll get an instant build error if Esomething doesn't fit nicely in the array you put it in. Then one can go back and figure out whether the limit should be raised, a new codes_foo should be created, or if it's early enough so it's not ABI yet, simply change Esomething to a saner value. A much bigger problem is that it's possible to add something to some errno.h without updating this table, but there's no good solution for that, I'm afraid. However, new Esomething are very rarely added, and printf() will still handle it gracefully until somebody notices. >>> +const char *errcode(int err) >> We got long, why not to use long type for it? Because errno values by definition have type int - and the linux syscall ABI very clearly limits values to [1,4095]. I can change the type used in vsnprintf.c if you prefer. >>> +{ >>> + /* Might as well accept both -EIO and EIO. */ >>> + if (err < 0) >>> + err = -err; >>> + if (err <= 0) /* INT_MIN or 0 */ >>> + return NULL; >>> + if (err < ARRAY_SIZE(codes_0)) >>> + return codes_0[err]; >> >> It won't work if one of the #ifdef:s in the array fails. >> Would it? I don't understand what you mean. How can an ifdef fail(?), and what exactly won't work? >>> +} >>> + long err = PTR_ERR(ptr); >>> + const char *sym = errcode(-err); >> >> Do we need additional sign change if we already have such check inside >> errcode()? Nah, but I went back and forth on this and ended up falling between two stools. I think I'll drop the handling of negative arguments to errcode(), the INT_MIN case makes that slightly ugly anyway. > How is EBUSY differentiated from ZERO_SIZE_PTR ? Huh? ZERO_SIZE_PTR aka (void*)(16L) is not IS_ERR(), so we won't get here in that case. Rasmus