From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753388AbdKWXaI (ORCPT ); Thu, 23 Nov 2017 18:30:08 -0500 Received: from smtprelay0231.hostedemail.com ([216.40.44.231]:43647 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752460AbdKWXaG (ORCPT ); Thu, 23 Nov 2017 18:30:06 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2553:2559:2562:2828:2898:3138:3139:3140:3141:3142:3355:3622:3653:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6299:7903:9008:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12555:12740:12760:12895:12986:13439:14093:14097:14659:14721:21080:21221:21433:21451:21627:30012:30054: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: rake94_74e66e99d372e X-Filterd-Recvd-Size: 3891 Message-ID: <1511479801.5308.6.camel@perches.com> Subject: Re: [PATCH] net: usb: hso.c: remove unneeded DRIVER_LICENSE #define From: Joe Perches To: Greg Kroah-Hartman Cc: netdev@vger.kernel.org, Julia Lawall , cocci , outreachy-kernel@googlegroups.com, "David S. Miller" , Andreas Kemnade , Johan Hovold , linux-kernel@vger.kernel.org, Philippe Ombredanne , linux-usb@vger.kernel.org Date: Thu, 23 Nov 2017 15:30:01 -0800 In-Reply-To: <20171122171201.GA6528@kroah.com> References: <20171117141939.GD17880@kroah.com> <1511370336.6989.100.camel@perches.com> <20171122171201.GA6528@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 On Wed, 2017-11-22 at 18:12 +0100, Greg Kroah-Hartman wrote: > On Wed, Nov 22, 2017 at 09:05:36AM -0800, Joe Perches wrote: > > On Fri, 2017-11-17 at 15:19 +0100, Greg Kroah-Hartman wrote: > > > There is no need to #define the license of the driver, just put it in > > > the MODULE_LICENSE() line directly as a text string. > > > > > > This allows tools that check that the module license matches the source > > > code license to work properly, as there is no need to unwind the > > > unneeded dereference. > > > > [] > > > diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c > > > > [] > > > @@ -76,7 +76,6 @@ > > > > > > #define MOD_AUTHOR "Option Wireless" > > > #define MOD_DESCRIPTION "USB High Speed Option driver" > > > -#define MOD_LICENSE "GPL" > > > > > > #define HSO_MAX_NET_DEVICES 10 > > > #define HSO__MAX_MTU 2048 > > > @@ -3288,7 +3287,7 @@ module_exit(hso_exit); > > > > > > MODULE_AUTHOR(MOD_AUTHOR); > > > MODULE_DESCRIPTION(MOD_DESCRIPTION); > > > -MODULE_LICENSE(MOD_LICENSE); > > > +MODULE_LICENSE("GPL"); > > > > Probably all of these MODULE_(MOD_) uses could be > > simplified as well. > > Agreed, I did that for a bunch of USB drivers, need to do it for others > as well. Here's a little perl and bash script that seems to do the right thing --- --- /dev/null 2017-11-23 06:19:12.943046739 -0800 +++ single_use_module.pl 2017-11-23 15:23:11.729812156 -0800 @@ -0,0 +1,15 @@ +$/ = undef; +my $var = $ARGV[0]; +my $file = $ARGV[1]; +print("var: <$var> file: <$file>\n"); +open my $fh, "<", $file or die; +my $data = <$fh>; +close $fh; +$data =~ s/\n#[ \t]*define\s+$var\s+(.*)\n/\n/; +my $string = $1; +print("string: <$string>\n"); +$string =~ s/\s+\n//; +$data =~ s~$var~$string~; +open my $fh, ">", $file or die; +print $fh $data; +close $fh; --- /dev/null 2017-11-23 06:19:12.943046739 -0800 +++ single_use_module.bash 2017-11-23 15:23:01.964676948 -0800 @@ -0,0 +1,25 @@ +#!/bin/bash +git grep -P '\bMODULE_[A-Z]+\s*\(\s*[A-Z_]+\s*\)' $@ | + while read line ; do + file=$(echo $line | cut -f1 -d":") + define=$(echo $line | cut -f2- -d":") + var=$(echo $define | sed -r -e 's/^MODULE_[A-Z_]+\s*\(\s*//' -r -e 's/^([A-Z_]+).*$/\1/') + + # see if the define exists in the file + count1=$(git grep -c -P "^\s*#\s*define\s+$var\s+" $file | cut -f2- -d":") + if [[ $count1 != 1 ]] ; then + continue + fi + + # see if the var exists twice (once in the #define, once in the use) + count2=$(git grep -c -P -w $var $file | cut -f2- -d":") + if [[ $count2 != 2 ]] ; then + continue + fi + + if [[ "${defline: -1}" == "\\" ]] ; then + continue + fi + + perl single_use_module.pl $var $file + done