Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp650298pxf; Wed, 24 Mar 2021 12:25:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycddUqSWyMtssplc0688WzvUQk4dg1l4IV79MWj4SbZsrdMaDmrew39ziu2e/NLHZJ4WyW X-Received: by 2002:a17:906:1453:: with SMTP id q19mr5549219ejc.76.1616613947937; Wed, 24 Mar 2021 12:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616613947; cv=none; d=google.com; s=arc-20160816; b=ACDqU3In+H8v96HrRYnj/Z1uCH7uqamLOMJ6mt9DCKh9/kcKbEwudb1R8v1+pljAWd tYQ80fvim35ufMSQ3NtteUi3/wePEFfyY/XCbVirFeaRJJUYWyaw42etII2O37yb3hNh eWi38TdmggWr9lNPcyo2DODo/Ve33S9rzzk3N3gff8Glc+MTPnjssvA7oRSu2/y4qAuc htwbOzOYKk4ibYLoAhmIrBtWaT/qIuW6PJrpCmotIZML1uwXYmARCTTMSlS3OLs/2Mpv vNMnxJJdirrJ0fKMg7D3nst0Ze78guqdowO9RiuQ+mEdRaUf+Tg9Wc6whFv8PyolGqOv 5m2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=7HpDiD64bZaEU5m00nuO4alh8mBl3jGOF/jKiwU8ki8=; b=c8UoAw7/npSlSgHeJJMFKlQNdj6irJnYPT5LnH/vERFY/Hqfg5j0yUuSeQj6prH7eY MJN4ODvQUcG4W72XVO/dfiyv6fZjIBibEMvLZcjnfaB30JOiedwLAB0X1zqJfizG2PIq qoobw1z9lyYx0p272cHMiOSF//UAnUCPkOx+plzAeH51tddzSjEbrzeTer9rQXo7TlDi Y1W2Mu3KJTS2qI5F5o5G/grfVaBPeaGFSi0TbMNlJm9nnpYQMLrEvPQIrzpUd4VN3LxD 575XuMaoTBBe0JnwMI3cmGFVfChnO2JU4xj0n4Ep0uvwEl1NENdf1gqd42p04kmpG6eh q+qQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be2si2532632edb.153.2021.03.24.12.25.24; Wed, 24 Mar 2021 12:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237809AbhCXTY1 (ORCPT + 99 others); Wed, 24 Mar 2021 15:24:27 -0400 Received: from smtprelay0082.hostedemail.com ([216.40.44.82]:58252 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237667AbhCXTYP (ORCPT ); Wed, 24 Mar 2021 15:24:15 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id BB3571801AC84; Wed, 24 Mar 2021 19:24:14 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:152:355:379:421:599:800:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1605:1711:1730:1747:1777:1792:1801:2198:2199:2393:2553:2559:2562:2689:2731:3138:3139:3140:3141:3142:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4605:5007:6119:6120:6691:6742:7652:7903:10004:10400:10848:11026:11232:11233:11473:11657:11658:11783:11914:12043:12048:12296:12297:12438:12740:12895:13894:14181:14659:14721:21080:21433:21451:21627:21740:21990:30012:30054:30060:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: fish34_600c2bf2777d X-Filterd-Recvd-Size: 4692 Received: from [192.168.1.159] (unknown [47.151.137.21]) (Authenticated sender: joe@perches.com) by omf02.hostedemail.com (Postfix) with ESMTPA; Wed, 24 Mar 2021 19:24:11 +0000 (UTC) Message-ID: Subject: Re: [RFC patch] vsprintf: Allow %pe to print non PTR_ERR %pe uses as decimal From: Joe Perches To: Rasmus Villemoes , Arnd Bergmann , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko Cc: Philipp Zabel , David Airlie , Daniel Vetter , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Marco Felsch , Laurent Pinchart , Liu Ying , dri-devel , Linux ARM , Linux Kernel Mailing List Date: Wed, 24 Mar 2021 12:24:10 -0700 In-Reply-To: <9feab1e8-4dee-6b79-03f7-7b9f0cb24f6e@rasmusvillemoes.dk> References: <20210324121832.3714570-1-arnd@kernel.org> <810d36184b9fa2880d3ba7738a8f182e27f5107b.camel@perches.com> <3252fd83141aa9e0e6001acee1dd98e87c676b9a.camel@perches.com> <9feab1e8-4dee-6b79-03f7-7b9f0cb24f6e@rasmusvillemoes.dk> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2021-03-24 at 18:33 +0100, Rasmus Villemoes wrote: > On 24/03/2021 18.20, Joe Perches wrote: > > On Wed, 2021-03-24 at 09:52 -0700, Joe Perches wrote: > > > On Wed, 2021-03-24 at 17:42 +0100, Arnd Bergmann wrote: > > > > On Wed, Mar 24, 2021 at 3:20 PM Joe Perches wrote: > > > [] > > > > > > diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c > > > > > [] > > > > > > @@ -197,6 +197,12 @@ static void imx_ldb_encoder_enable(struct drm_encoder *encoder) > > > > > >       int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; > > > > > >       int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); > > > > > > > > > > > > + if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) { > > > > > > + dev_warn(ldb->dev, "%s: invalid mux %d\n", > > > > > > + __func__, ERR_PTR(mux)); > > > > > > > > > > This does not compile without warnings. > > > > > > > > > > drivers/gpu/drm/imx/imx-ldb.c: In function ‘imx_ldb_encoder_enable’: > > > > > drivers/gpu/drm/imx/imx-ldb.c:201:22: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘void *’ [-Wformat=] > > > > >   201 | dev_warn(ldb->dev, "%s: invalid mux %d\n", > > > > >       | ^~~~~~~~~~~~~~~~~~~~~~ > > > > > > > > > > If you want to use ERR_PTR, the %d should be %pe as ERR_PTR > > > > > is converting an int a void * to decode the error type and > > > > > emit it as a string. > > > > > > > > Sorry about that. > > > > > > > > I decided against using ERR_PTR() in order to also check for > > > > positive array overflow, but the version I tested was different from > > > > the version I sent. > > > > > > > > v3 coming. > > > > > > Thanks. No worries. > > > > > > Up to you, vsprintf would emit the positive mux as a funky hashed > > > hex value by default if you use ERR_PTR with mux > ARRAY_SIZE so > > > perhaps %d without the ERR_PTR use makes the most sense. > > > > > > > > Maybe it's better to output non PTR_ERR %pe uses as decimal so this > > sort of code would work. > > No, because that would leak the pointer value when somebody has > accidentally passed a real kernel pointer to %pe. I think it's not really an issue. _All_ code that uses %p extensions need inspection anyway. It's already possible to intentionally 'leak' the ptr value by using %pe, -ptr so I think that's not really an issue. > > If the code wants a cute -EFOO string explaining what's wrong, what > about "%pe", ERR_PTR(mux < 0 : mux : -ERANGE)? Or two separate error > messages > > if (mux < 0) >   ... > else if (mux >= ARRAY_SIZE()) >   ... Multiple tests, more unnecessary code, multiple format strings, etc...