Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp28040imm; Thu, 30 Aug 2018 06:15:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbcfXZDldbFF2lhE7FXgBrIIC38y9CCflsJ4qD5fp2+SVamS71Q1vBr51Gjgjz5kt1nRYNQ X-Received: by 2002:aa7:818f:: with SMTP id g15-v6mr10447497pfi.71.1535634947984; Thu, 30 Aug 2018 06:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535634947; cv=none; d=google.com; s=arc-20160816; b=cuCNK82enDqrpM/+AZ0u+ltFkFfalDgxujoH2B5jjrI4HbPbUiPIqR8iDf+uH/IDzk hyqPleQ+Xoa/GY2IOH077s2jP/lQ260sHeQJhHUTNeDWR8hfmpctZPo9Y5zpv5Eu4s04 PB/O/e6TKY5CsczWxx+z2dfFBmjBmVtElHCtGHPxY8mhaUGzEhyTUd/+joc2kNcgtvlH C3wzkgIISNXBgcU3fZJNhcmtB3C2Bf4k+p9CzqJRhCC7li+L4d+U7GrQEXcvyxqeh1HO NdgX6zY6nkBtliMZHC9qTfRzMR6/2rlRjyMmA628NWUebjZ4EAwSSNiQjmNkZ44fm+qC HsOw== 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:dkim-signature:arc-authentication-results; bh=shqp801gxGgttkh+vfo02+52v2YI5Uvaa05tuPvvFOI=; b=Kw+E1d0tpR0ZayGOn+5y8NgftFL2xWoBmoWHs0Un7eCSWIVmlPyDZ33rdcR04zrBV9 T5n+sLSU2uQQMdZqRfJVWASvnIWU+9NGepALgvgXJR148He9gnL21HuR9aJrFFE+2kMv yWi5W5hJ7+mBD0WbxBaEBWLiCTZA69lAAuA2MO0fHyReTNldUEVUqCUWYWaHEcHFxosE gLpQn2zEY4E0oejzIXjO/2sfQb8EIrrta+AqP8Eb9KMJt5ky+p3Zhm75q264L5Bfog11 UtMpLJn/2/t/bvtMieZNpKfP80GrEqu2mx8OFc/yEP4vtbM4v9vImccEgUlHZvZERX07 kplg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U3LjZSaR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2-v6si6406638plt.112.2018.08.30.06.15.31; Thu, 30 Aug 2018 06:15:47 -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=@gmail.com header.s=20161025 header.b=U3LjZSaR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728990AbeH3RPn (ORCPT + 99 others); Thu, 30 Aug 2018 13:15:43 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:33631 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728273AbeH3RPm (ORCPT ); Thu, 30 Aug 2018 13:15:42 -0400 Received: by mail-ed1-f65.google.com with SMTP id h9-v6so6502323edr.0 for ; Thu, 30 Aug 2018 06:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=shqp801gxGgttkh+vfo02+52v2YI5Uvaa05tuPvvFOI=; b=U3LjZSaRm5zwofF/cG3/KeFEyJEYMSKv21rqdEV+kNTa20LkoWoHuNdyhcpmQEC7ho dkw2M0xAFuJs0tLpY+Ob5Ot6+GGsIGkuaoRFEoqpb7K6GdRHl3/DjW71JiohjnDFXYx1 HUZLRkR6LGDtwfJWwuFQRzSlVHoeamFp518sQCcjAcloAy7fKN3vwk6W7+86p6teQjCs VmBnM780hiEPfuIfhBXZ6svvu7WHC3UZ6Gedn4/Knn7arzmQgni/5yFeAGBVzAtG1vSN f1QFI7mgxpPLFpRW5Iih35+3frJFu6zbuPlYrBziD3ck2al71DyFePl2qnFUEY0/21O8 VQSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=shqp801gxGgttkh+vfo02+52v2YI5Uvaa05tuPvvFOI=; b=rougvoKADRadK1hpbAIw3Xr5S60bd1jI1m6787Zc99ALr5PVmtX2JsWlsvdOJa9YaI EccW0guxI6MjY883QuSLHedW//8HrkLtB3CJQimLdJXejyPOAfBrNqbxJgGzy35wqEsC T8zVCInsuGwGMdYkp5QOJGLAIWBc8UAC4/gdxbSYRs39gbgWZ24qpsflpOhE94rB0As8 ur1N9G0MfDhMxm5St1K7hE6XGPV59oq9+Q2Vp9dReokKwZ3V8/NV0y3wUBQGvMo4XomF 8E1C6b8uwXKTPjSapfUCR3Y7zV4+64uRuqoQUDPn2Wz+C5NIdtTxrYyJwqGTN9yQaPz/ qhvg== X-Gm-Message-State: APzg51ACDMr2mEPyNQd3bh5VpboFEz7U18wYvOJoleYMoPlcMYgyHu34 0O3xqnmJzxYuIV/pP7QcRFaPUZY= X-Received: by 2002:aa7:d141:: with SMTP id r1-v6mr13304282edo.83.1535634816063; Thu, 30 Aug 2018 06:13:36 -0700 (PDT) Received: from avx2 (nat4-minsk-pool-46-53-177-92.telecom.by. [46.53.177.92]) by smtp.gmail.com with ESMTPSA id j10-v6sm2946845ede.5.2018.08.30.06.13.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 06:13:35 -0700 (PDT) Date: Thu, 30 Aug 2018 16:13:33 +0300 From: Alexey Dobriyan To: David Laight Cc: "akpm@linux-foundation.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 06/13] proc: convert /proc/self to _print_integer() Message-ID: <20180830131333.GA31422@avx2> References: <20180827231503.26899-1-adobriyan@gmail.com> <20180827231503.26899-6-adobriyan@gmail.com> <54cb86c6d96b47bc8017a69be124c105@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <54cb86c6d96b47bc8017a69be124c105@AcuMS.aculab.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 29, 2018 at 09:50:50AM +0000, David Laight wrote: > From: Alexey Dobriyan > > Sent: 28 August 2018 00:15 > > --- > > fs/proc/self.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/fs/proc/self.c b/fs/proc/self.c > > index 127265e5c55f..b2279412237b 100644 > > --- a/fs/proc/self.c > > +++ b/fs/proc/self.c > > @@ -14,6 +14,7 @@ static const char *proc_self_get_link(struct dentry *dentry, > > { > > struct pid_namespace *ns = proc_pid_ns(inode); > > pid_t tgid = task_tgid_nr_ns(current, ns); > > + char buf[10], *p = buf + sizeof(buf); > > char *name; > > > > if (!tgid) > > @@ -22,7 +23,11 @@ static const char *proc_self_get_link(struct dentry *dentry, > > name = kmalloc(10 + 1, dentry ? GFP_KERNEL : GFP_ATOMIC); > > if (unlikely(!name)) > > return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD); > > - sprintf(name, "%u", tgid); > > + > > Best not to 'hide' the initialisation of 'p' at the top of the function. > Much easier to see what is going on if it is moved here. It was written that way to have initialization near the buffer, so that it is obvious that pointer and buffer are connected and making p = _print_integer_uNN(p, x); standard building block which can be copypasted left and right and still be correct. > > + p = _print_integer_u32(p, tgid); > > or just: > p = _print_integer(buf + sizeof(buf), tgid); > > (What a horrid interface ...) It is. The problem is that adding bound checking will get you current vsnprintf() and number() and num_to_str(). > > + memcpy(name, p, buf + sizeof(buf) - p); > > + name[buf + sizeof(buf) - p] = '\0'; > > + > > set_delayed_call(done, kfree_link, name); > > return name; > > }