From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753980AbcJMKrG (ORCPT ); Thu, 13 Oct 2016 06:47:06 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:35304 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752904AbcJMKq5 (ORCPT ); Thu, 13 Oct 2016 06:46:57 -0400 From: Nicolai Stange To: Arnd Bergmann Cc: Nicolai Stange , Greg Kroah-Hartman , Andy Shevchenko , Rajneesh Bhardwaj , Darren Hart , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] debugfs: improve DEFINE_DEBUGFS_ATTRIBUTE for !CONFIG_DEBUGFS_FS References: <20161010111313.119658-1-arnd@arndb.de> <87vawwmuw5.fsf@gmail.com> <5795991.0oAm3xDhR2@wuerfel> Date: Thu, 13 Oct 2016 12:46:36 +0200 In-Reply-To: <5795991.0oAm3xDhR2@wuerfel> (Arnd Bergmann's message of "Thu, 13 Oct 2016 12:29:44 +0200") Message-ID: <87r37kmsqb.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Arnd Bergmann writes: > On Thursday, October 13, 2016 11:59:54 AM CEST Nicolai Stange wrote: >> > >> > +ssize_t debugfs_attr_read(struct file *file, char __user *buf, >> > + size_t len, loff_t *ppos); >> > +ssize_t debugfs_attr_write(struct file *file, const char __user *buf, >> > + size_t len, loff_t *ppos); >> > + >> > +#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ >> > +static int __fops ## _open(struct inode *inode, struct file *file) \ >> > +{ \ >> > + __simple_attr_check_format(__fmt, 0ull); \ >> > + return simple_attr_open(inode, file, __get, __set, __fmt); \ >> > +} \ >> > +static const struct file_operations __fops = { \ >> > + .owner = THIS_MODULE, \ >> > + .open = __fops ## _open, \ >> > + .release = simple_attr_release, \ >> > + .read = debugfs_attr_read, \ >> > + .write = debugfs_attr_write, \ >> >> This depends on GCC dead code elimination to always work for this >> situation, otherwise we'd get undefined references to >> debugfs_attr_read/write(), right? > > Correct. > >> In order to avoid having to test your patch against all those older >> versions of GCC, can we have a safety net here and define some dummy >> debugfs_attr_read/write() for the !CONFIG_DEBUGFS case? > > The question of dead-code elimination in older gcc versions comes up > occasionally, and I think all versions that are able to build the > kernel these days get this right all the time, otherwise any code > using IS_ENABLED() helpers to control the calling of external interfaces > would be broken. > > We could probably use that macro here if you think that's better > and do: > > static const struct file_operations __fops = { > .owner = THIS_MODULE, > .open = IS_ENABLED(CONFIG_DEBUGFS_FS) ? __fops ## _open : NULL, > ... > >> If nothing else, it would IMHO make the !CONFIG_DEBUGFS case more >> understandable because one had not to figure out that this actually >> relies on dead code elimination to work. > > Sure, that's fine. Can you do the new version of that patch with > the change then? I'd be happy to (won't be able to do this before tomorrow though). Thanks, Nicolai