Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp367837pxj; Fri, 28 May 2021 06:02:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX/WabFCzWJKo9Cf9WBJmmnNTOHWsdXEgZVzsKCrZZyJgRQeriW+MKIsL4GuDkSgJkO6u8 X-Received: by 2002:a92:c70b:: with SMTP id a11mr7386975ilp.136.1622206942071; Fri, 28 May 2021 06:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622206942; cv=none; d=google.com; s=arc-20160816; b=dXW1ei5zofB3amteKP9jtVauvf8Q9o7xA3zjaZUSY/jz2lo3yYOmDDfsbEB4oXy2Qa Z337ZbDnuRZfwW6SFay4DEZDR3VFKtPsBScDwUsk6MM4DYDFMcwBxw3wUJ2E/e6TeeZc /K4q7CPSoj3STvmjqwPuH3QC5beXNiPavGekvjUOmVs+RQBi/7dYrc7iveMQoKHc5uQD rXk3Lh4rY8XVF2irgmkTUwtILhiYRhbmB89w1pvJq4nOwSU56mDCNPn9Upo77eTm9Ahc C6BBGpFFvphQ3ONnJktEZO0fGNWFU87N8CoYNMAIZJejnLVJRlEpRkttVUcq3P/npACs Gtfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZUYH3Mi14wG7kdhKEHxhtXEvN0lUYTCSCOFLNtrHy8U=; b=VPCozSwIoFLJ1sT7sFJSFNuFs63STb4jKPSstRFwA8hYQcDy8xUa0Gl57+Wy0g3dGX HMnaK8dIte6IOFzSPOU8MPf6mLJJ/XmcT0MtjjYlWIv7EmP7H635N4ynX6ddKR78F0X7 kCEuJKscsOS9T98WPOOFeo0oGj4gC7rqkhb3/eZCUjHLiJj0UnNI8kuvENSEF2QwMITX KqRoqvIuol5x0xlVq62LlQjVC9JVyEs9fkzfqdw+Gei6b2LnSx/dgo+a2KZVLNpJhhfL zKsqKseWQBWpeB46PTN5aHewY0909gbrBdhS7UXr4+WWeLcA70ZSUAu6Qi51fGiMpxF5 iptw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ApeMuFTF; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 o2si6411589iov.96.2021.05.28.06.01.54; Fri, 28 May 2021 06:02:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ApeMuFTF; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235662AbhE1NCk (ORCPT + 99 others); Fri, 28 May 2021 09:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbhE1NCi (ORCPT ); Fri, 28 May 2021 09:02:38 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A74C061574; Fri, 28 May 2021 06:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ZUYH3Mi14wG7kdhKEHxhtXEvN0lUYTCSCOFLNtrHy8U=; b=ApeMuFTFAmYrhq5vjgQD8SK9L/ 3Jr36omDQW+jP9z71Yj9q4mcFfIz/QvWcbW3MCmXI72eJdE1Y5CazcfgIM1KZlUU0nj8C/g9CsVzw JKe4dEZD2Sixv0LFh+4vEfEAGlUJLVI+4zFcx3bk1VkKcBWsJrhdhAS1cELocq0ONIO/futC6J2Aq HGOB9N/6/r+hJ0EseI9fOa1ZvYakcOj6SqqytcT2I2IAB4wjRGFqVs5x0EFt7375ZAMJCnZjchi1y Q7rzBYzdSQoBv+iMBZ8WNrVbZOtW5VIuygblyl3g40Gqxjo83YwPPspTP3s1kczXA3S3m/uzVwy9l 7IyoDrsQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lmc5i-006clg-A9; Fri, 28 May 2021 12:59:59 +0000 Date: Fri, 28 May 2021 13:59:54 +0100 From: Matthew Wilcox To: Jia He Cc: Linus Torvalds , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Alexander Viro , Luca Coelho , Kalle Valo , "David S. Miller" , Jakub Kicinski , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Johannes Berg , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org Subject: Re: [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file Message-ID: References: <20210528113951.6225-1-justin.he@arm.com> <20210528113951.6225-3-justin.he@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210528113951.6225-3-justin.he@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Fri, May 28, 2021 at 07:39:50PM +0800, Jia He wrote: > We have '%pD' for printing a filename. It may not be perfect (by > default it only prints one component.) > > As suggested by Linus at [1]: > A dentry has a parent, but at the same time, a dentry really does > inherently have "one name" (and given just the dentry pointers, you > can't show mount-related parenthood, so in many ways the "show just > one name" makes sense for "%pd" in ways it doesn't necessarily for > "%pD"). But while a dentry arguably has that "one primary component", > a _file_ is certainly not exclusively about that last component. > > Hence "file_dentry_name()" simply shouldn't use "dentry_name()" at all. > Despite that shared code origin, and despite that similar letter > choice (lower-vs-upper case), a dentry and a file really are very > different from a name standpoint. > > Here stack space is preferred for file_d_path_name() because it is > much safer. The stack size 256 is a compromise between stack overflow > and too short full path. How is it "safer"? You already have a buffer passed from the caller. Are you saying that d_path_fast() might overrun a really small buffer but won't overrun a 256 byte buffer? > @@ -920,13 +921,25 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp > } > > static noinline_for_stack > -char *file_dentry_name(char *buf, char *end, const struct file *f, > +char *file_d_path_name(char *buf, char *end, const struct file *f, > struct printf_spec spec, const char *fmt) > { > + const struct path *path; > + char *p; > + char full_path[256]; > + > if (check_pointer(&buf, end, f, spec)) > return buf; > > - return dentry_name(buf, end, f->f_path.dentry, spec, fmt); > + path = &f->f_path; > + if (check_pointer(&buf, end, path, spec)) > + return buf; > + > + p = d_path_fast(path, full_path, sizeof(full_path)); > + if (IS_ERR(p)) > + return err_ptr(buf, end, p, spec); > + > + return string_nocheck(buf, end, p, spec); > } > #ifdef CONFIG_BLOCK > static noinline_for_stack