Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4527981ybp; Mon, 14 Oct 2019 06:10:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqybQUK+JHLq+mSPoFWLo/h8hiJ8IxTfswXjIhN7QAxCIcOQRQKlxM+bH7nFAMRK8rtUQ/Ci X-Received: by 2002:a17:906:792:: with SMTP id l18mr27788183ejc.170.1571058601697; Mon, 14 Oct 2019 06:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571058601; cv=none; d=google.com; s=arc-20160816; b=ifJ6wW1RIQ6w8bYFDI587UPF50EZC7OkKCYyser3MoOUEzeV38J00H+m4ijbRgonhj L61fgGUFbzj4z/cNpKMriF5nDgZrIt5g7KN3rlKajsFnT2JVau2TA9cU2LV+PZyGxn+/ LMfdXk2Q2MsT7FtCWlnjoGLZQ9CY9UUssrsLrpio9SzK0tnVFk8wV9dUWug+G38Y/xAr 7cHS/elxJeNEEzeAfm0mvmDq9ZluOREd7aIJoju4Yq93byotxWPJ87C/CmkHzWAIwZXO BxxMwQUBjVGAFYfWuWE0qikInD2WFi3sjLa/dFeSNR9Zn3drlWGsqteZUr3+X7ccEvOQ OihQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eeMnInU3ZngVCzjI+RchXxAWwJD+qh1ZUXEOrIgdBoQ=; b=hv7k6iPQ6gzd2U8tqY7txuI1Ms50c00WXN1sUgRmn+DO9KxET6FAepxLXOSr57PCKR ZetQZB2F6dooX5AGj9cEX6bF9vqdaOdUM5puxdvJ2+lZjbZwqADGZldeEJ0XtM/C0XqY dyvada+esqL4JOKPCM0midB6M7JeHlmxLEnf5RBVD/EKXos4uy5IHmTeJowkPMBk8aaC JWEhlAfPt60IuCCC8ZlkBAbOOlJ/yFecdsQIMod3EZCY0qnP5VO6Kb1b+H2FxMBAFnA7 yG9GkAnv121Dw8WXHurJEAOoMEkLc6YSIc4zukIrHR18XmZUKLPuJXRPzzrzCVKtnInY zuVg== 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 v53si11946433edc.378.2019.10.14.06.09.37; Mon, 14 Oct 2019 06:10:01 -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 S1731975AbfJNNCv (ORCPT + 99 others); Mon, 14 Oct 2019 09:02:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:46146 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727948AbfJNNCu (ORCPT ); Mon, 14 Oct 2019 09:02:50 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CC1ACBAC1; Mon, 14 Oct 2019 13:02:48 +0000 (UTC) Date: Mon, 14 Oct 2019 15:02:47 +0200 From: Petr Mladek To: Rasmus Villemoes Cc: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Joe Perches , Andy Shevchenko , Andrew Morton , Jonathan Corbet , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/1] printf: add support for printing symbolic error names Message-ID: <20191014130247.rag2g7qz54uiw54z@pathway.suse.cz> References: <20190917065959.5560-1-linux@rasmusvillemoes.dk> <20191011133617.9963-1-linux@rasmusvillemoes.dk> <20191011133617.9963-2-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191011133617.9963-2-linux@rasmusvillemoes.dk> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2019-10-11 15:36:17, Rasmus Villemoes wrote: > It has been suggested several times to extend vsnprintf() to be able > to convert the numeric value of ENOSPC to print "ENOSPC". This > implements that as a %p extension: With %pe, one can do Reviewed-by: Petr Mladek I like the patch. There are only two rather cosmetic things. > diff --git a/lib/errname.c b/lib/errname.c > new file mode 100644 > index 000000000000..30d3bab99477 > --- /dev/null > +++ b/lib/errname.c > +const char *errname(int err) > +{ > + bool pos = err > 0; > + const char *name = __errname(err > 0 ? err : -err); > + > + return name ? name + pos : NULL; This made me to check C standard. It seems that "true" really has to be "1". But I think that I am not the only one who is not sure. I would prefer to make it less tricky and use, for example: const char *name = __errname(err > 0 ? err : -err); if (!name) return NULL; return err > 0 ? name + 1 : name; > +} > diff --git a/lib/test_printf.c b/lib/test_printf.c > index 5d94cbff2120..4fa0ccf58420 100644 > --- a/lib/test_printf.c > +++ b/lib/test_printf.c > @@ -593,6 +593,29 @@ flags(void) > kfree(cmp_buffer); > } > > +static void __init > +errptr(void) > +{ > + char buf[PLAIN_BUF_SIZE]; > + > + test("-1234", "%pe", ERR_PTR(-1234)); > + > + /* Check that %pe with a non-ERR_PTR gets treated as ordinary %p. */ > + BUILD_BUG_ON(IS_ERR(PTR)); > + snprintf(buf, sizeof(buf), "(%p)", PTR); > + test(buf, "(%pe)", PTR); There is a small race. "(____ptrval____)" is used for %p before random numbers are initialized. The switch is done via workqueue work, see enable_ptr_key_workfn(). It means that it can be done in parallel. I doubt that anyone would ever hit the race. But it could be very confusing and hard to debug. I would replace it with: test_hashed("%pe", PTR); If would like to have the two things fixed. I am not sure if you want to send one more revision. Or I could also change it by follow up patch when pushing. What is your preference, please? Best Regards, Petr