Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754678AbdLTJyz (ORCPT ); Wed, 20 Dec 2017 04:54:55 -0500 Received: from smtprelay0246.hostedemail.com ([216.40.44.246]:45285 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754070AbdLTJyu (ORCPT ); Wed, 20 Dec 2017 04:54:50 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: X-HE-Tag: help16_635ba0b11195c X-Filterd-Recvd-Size: 5998 Message-ID: <1513763681.1234.101.camel@perches.com> Subject: Re: [-next PATCH 2/4] treewide: Use DEVICE_ATTR_RW From: Joe Perches To: Greg Kroah-Hartman Cc: Jarkko Nikula , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Cezary Jackiewicz , Darren Hart , Andy Shevchenko , Sebastian Ott , Peter Oberparleiter , James Smart , Dick Kennedy , Zhang Rui , Eduardo Valentin , Mathias Nyman , Felipe Balbi , "Luis R. Rodriguez" , Peter Ujfalusi , Martin Schwidefsky , Heiko Carstens , David Airlie , "James E.J. Bottomley" , "Martin K. Petersen" , Jiri Slaby , Bartlomiej Zolnierkiewicz , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, platform-driver-x86@vger.kernel.org, linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux-fbdev@vger.kernel.org, alsa-devel@alsa-project.org, linux-omap@vger.kernel.org Date: Wed, 20 Dec 2017 01:54:41 -0800 In-Reply-To: <20171220093211.GA16177@kroah.com> References: <20171220083403.GA27231@bitmer.com> <1513761884.1234.83.camel@perches.com> <20171220093211.GA16177@kroah.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3479 Lines: 105 On Wed, 2017-12-20 at 10:32 +0100, Greg Kroah-Hartman wrote: > On Wed, Dec 20, 2017 at 01:24:44AM -0800, Joe Perches wrote: > > On Wed, 2017-12-20 at 10:34 +0200, Jarkko Nikula wrote: > > > On Tue, Dec 19, 2017 at 10:15:07AM -0800, Joe Perches wrote: > > > > Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible. > > > > [] > > > > diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c > > > > [] > > > > @@ -854,7 +854,7 @@ static ssize_t dma_op_mode_store(struct device *dev, > > > > return size; > > > > } > > > > > > > > -static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store); > > > > +static DEVICE_ATTR_RW(dma_op_mode); > > > > > > > > > > While I can ack this part here if it helps generic cleanup effort I > > > don't understart would it improve code readability in general? Mode 644 > > > is clear and don't need any grepping but for DEVICE_ATTR_RW() I had to go > > > through all of these files in order to see what does it mean: > > Yeah, 644 is "clear", but _RW() is even more clear. Ideally I want to > get rid of all of the "non-standard" users that set random modes of > sysfs files, as we get it wrong too many times. Using the "defaults" is > much better. > > > Are you suggesting that device.h (as that is where > > DEVICE_ATTR and the other DEVICE_ATTR_ variants > > are #defined) should have better comments for the > > _ variants? > > > > > DEVICE_ATTR_RW: include/linux/device.h > > > __ATTR_RW: include/linux/sysfs.h > > > S_IWUSR: include/uapi/linux/stat.h > > > S_IRUGO: include/linux/stat.h > > > > btw: patch 1/4 of the series does remove the uses of > > S_ from these macros in sysfs.h and converts > > them to simple octal instead. > > Why you didn't send that patch to the sysfs maintainer is a bit odd... :) So here's an opportunity for you: The sysfs maintainer hasn't added include/linux/sysfs.h to the list of maintained files... DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS M: Greg Kroah-Hartman T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git S: Supported F: Documentation/kobject.txt F: drivers/base/ F: fs/debugfs/ F: fs/sysfs/ F: include/linux/debugfs.h F: include/linux/kobj* F: lib/kobj* > I should be taking this whole series through my tree. Joe, thanks for > doing this in an automated way, I've been wanting to see this done for a > long time. btw: there are many uses of a reversed declaration style of DEVICE_ATTR Here's another thing that could be done for more DEVICE_ATTR_ uses. === Some DEVICE_ATTR definitions use a reversed static function form from the typical. Convert them to use the more common macro form so it is easier to grep for the style. i.e.: static ssize_t show_(...) and static ssize_t store_(...) where the static function names in the DEVICE_ATTR_RW macro are reversed static ssize_t _show(...) and static ssize_t _store(...) Done with perl script $ cat dev_attr_rw_backwards.perl local $/; while (<>) { my $file = $_; while ($file =~ m/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,/g) { my $var = $1; if ($file =~ s/\bDEVICE_ATTR\s*\(\s*${var}\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S $file =~ s/\bshow_${var}\b/${var}_show/g; $file =~ s/\bstore_${var}\b/${var}_store/g; } } print $file; } $ git grep --name-only -w DEVICE_ATTR | \ xargs perl -i dev_attr_rw_backwards.perl