Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp932611ybp; Fri, 11 Oct 2019 06:39:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsfY+EIgXKC/0ElXPDwxoHjyfPCcdJgZxW4l7WP7GsFfth6B95n3CBfNN+hOuBIuLcaT4C X-Received: by 2002:a17:906:1e43:: with SMTP id i3mr13286014ejj.77.1570801192810; Fri, 11 Oct 2019 06:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570801192; cv=none; d=google.com; s=arc-20160816; b=ka7dUNDUOWaw6ElqU4WBPXdJblFOmkiue2c8o42+IkMUmEL00258Xerp4QRYCAuju4 9sgLeDQV9PNjTXyTPL0IRb2g7/CE3/1DqKo/4Dr9qgUiL39LqMzUo6WpIhdmLVCyCr8Y hFJmFZixKvn+ox9QyPzSkj4X68FgvKCjXMW/AutvN71hRfZq62+w1HpcbNBBvBSS9M6I wH21Qu0XWMhlqswvA9lec/QzOU1Ge/e7bn7QzJHHfytmNLsWVexzILTOkTAyxFH+7wvw AnR75RGwQl+8SLLPc4KthFXRT7eUgX7/PoFi9njsOSv+GDgsoCMmupnK3G81r6foGloW g9PA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W3mkaQtz/EVWMeltP+joTbw4vbppxsJsoSSQJ3ZRvuQ=; b=IlUMQWDG3tAj0UJU9exbp7VaaR6et8eTiXGuNHf34KAWrpCcl8kXWVToZ5G6BV4Mp4 aHgrYANclqxtAfskk7wIkhl2zkqnkT/qtfFm3TZZhq+5x9O+JgUWcUugKVFJJJxgDSgn yzAhJIpee463DAV2dKoXUxMPoMZUYZCFIEwVQvrMTLPiV1pR0B5ixqNIUPj0O+oN8pwZ IeTz13zb+3M2wds8M6jys6NNuo2QXcD2j89lZAP80e0EWh/yqz48tIgu8SAblLHqUV3v pibudppWDYx6TeU0yYuzP5xCJgclKbcxWBv0I3t0+VesqgBcbphJznAKEc6mNbv8JH4V /aJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=MVySzTdS; 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 c10si6624281edc.419.2019.10.11.06.39.29; Fri, 11 Oct 2019 06:39: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=@rasmusvillemoes.dk header.s=google header.b=MVySzTdS; 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 S1728507AbfJKNgZ (ORCPT + 99 others); Fri, 11 Oct 2019 09:36:25 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:40975 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728084AbfJKNgZ (ORCPT ); Fri, 11 Oct 2019 09:36:25 -0400 Received: by mail-lf1-f67.google.com with SMTP id r2so7050234lfn.8 for ; Fri, 11 Oct 2019 06:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W3mkaQtz/EVWMeltP+joTbw4vbppxsJsoSSQJ3ZRvuQ=; b=MVySzTdSAwO2C1fF9Cur6SWzvOrt4vAf12/lvx2Ruxg2g9PD6c2Fxr0zcffaoT7rke M9kXMLtFPjC2kKIOnqDTcT2OjV9ubrMwOKQ7FBpUmImtduxxPW9qDJCR+FOqrrE9B1Kp /hU9191gbbLAyLxtBFPbWjsLJ6EDTGvSojtpA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W3mkaQtz/EVWMeltP+joTbw4vbppxsJsoSSQJ3ZRvuQ=; b=JyHau3WQ467z7ximHsNgNk0Ad2yNc/Bdau2pKBni2zZzP8l1vf34JSvGztmzkDay2C Gcg5kQAZSfrfcnbC/7rEzUkyUQZyFtIbHS4HsZl6W0GOOFx9xeTr42xcFCIkBo2Fsv3I Kq/NhhgDxaczSFxfWtWBRjZtLkJJsxiQlgNRW5w/g0JmEODENsfvyTQyD/tocMIt4J4U xPdHW9hiMPv0bPGpKCp27sSFfbAWyn+PQJceT5/M4JRHZk3Vt7w9/+q0qBth1uCcaTEQ AsgKURk9amJsWWgpj2Rzzs0q7kK6CYoaoeIxIi9r47JM0KxqZGl/MWbeUFadC1c0rmnY j8aQ== X-Gm-Message-State: APjAAAWtwuq0NHZwo8S41Qs3roW3urdcs2D+vyJERfW+t9h4kJiSUqTw kVNZVqSk1l/sbM9RI2KXI4Xiam23Qgbw4w== X-Received: by 2002:a19:4f0e:: with SMTP id d14mr8687182lfb.177.1570800981788; Fri, 11 Oct 2019 06:36:21 -0700 (PDT) Received: from prevas-ravi.prevas.se (ip-5-186-115-54.cgn.fibianet.dk. [5.186.115.54]) by smtp.gmail.com with ESMTPSA id g10sm2010311lfb.76.2019.10.11.06.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 06:36:21 -0700 (PDT) From: Rasmus Villemoes To: Joe Perches , Petr Mladek , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Andrew Morton , linux-kernel@vger.kernel.org, Andy Shevchenko , Jonathan Corbet , Rasmus Villemoes Subject: [PATCH v4 0/1] printf: add support for printing symbolic error names Date: Fri, 11 Oct 2019 15:36:16 +0200 Message-Id: <20191011133617.9963-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190917065959.5560-1-linux@rasmusvillemoes.dk> References: <20190917065959.5560-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a bit much for under the ---, so a separate cover letter for this single patch. v4: Dropped Uwe's ack since it's changed quite a bit. Change errcode->errname as suggested by Petr. Make it 'default y if PRINTK' so it's available in the common case, while those who have gone to great lengths to shave their kernel to the bare minimum are not affected. Also require the caller to use %pe instead of printing all ERR_PTRs symbolically. I can see some value in having the call site explicitly indicate that they're printing an ERR_PTR (i.e., having the %pe), but I also still believe it would make sense to print ordinary %p, ERR_PTR() symbolically instead of as a random hash value that's not stable across reboots. But in the interest of getting this in, I'll leave that for now. It's easy enough to do later by just changing the "case 'e'" to do a break (with an updated comment), then do an IS_ERR() check after the switch. Something I've glossed over in previous versions, and nobody has commented on, is that I produced "ENOSPC" while the 'fallback' would print "-28" (i.e., there's no minus in the symbolic case). I don't care much either way, but here I've tried to show how I'd do it if we want the minus also in the symbolic case. At first, I tried just using the standard idiom if (buf < end) *buf = '-'; buf++; followed by string(sym, ...). However, that doesn't work very well if one wants to honour field width - for that to work, the whole string including - must come from the errname() lookup and be handled by string(). The simplest seemed to be to just unconditionally prefix all strings with "-" when building the tables, and then change errname() back to supporting both positive and negative error numbers. As I said, I don't care much either way, so if somebody thinks this is too complicated and would prefer just printing "ENOSPC" (because really the minus doesn't offer much except that it's perhaps easier to recognize for a kernel developer) just speak up. I've also given some thought to Petr's suggestion of how to improve the handling of ERR_PTRs that are accidentally passed to %p. But I'll do that as a separate series on top - for now I think this should go into -next if nobody complains loudly. Rasmus Villemoes (1): printf: add support for printing symbolic error names Documentation/core-api/printk-formats.rst | 12 ++ include/linux/errname.h | 16 ++ lib/Kconfig.debug | 9 + lib/Makefile | 1 + lib/errname.c | 222 ++++++++++++++++++++++ lib/test_printf.c | 24 +++ lib/vsprintf.c | 27 +++ 7 files changed, 311 insertions(+) create mode 100644 include/linux/errname.h create mode 100644 lib/errname.c -- 2.20.1