Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933565AbdGTAHy (ORCPT ); Wed, 19 Jul 2017 20:07:54 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33215 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933229AbdGTAHu (ORCPT ); Wed, 19 Jul 2017 20:07:50 -0400 Subject: Re: [PATCH] scsi: mpt3sas_scsih: remove unnecessary statics From: James Bottomley To: "Gustavo A. R. Silva" , "Martin K. Petersen" Cc: MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 19 Jul 2017 17:07:43 -0700 In-Reply-To: <20170719220636.GA8136@embeddedgus> References: <20170719220636.GA8136@embeddedgus> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 17072000-0040-0000-0000-00000382CEA5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007389; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00890030; UDB=6.00444631; IPR=6.00670201; BA=6.00005479; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016283; XFM=3.00000015; UTC=2017-07-20 00:07:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17072000-0041-0000-0000-00000776E513 Message-Id: <1500509263.3701.39.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-07-19_16:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707190376 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2123 Lines: 65 On Wed, 2017-07-19 at 17:06 -0500, Gustavo A. R. Silva wrote: > Remove unnecessary static on local variables raid_device. > Such variables are initialized before being used, on > every execution path throughout the functions. The > static has no benefit and, removing it reduces the > object file size. > > This issue was detected using Coccinelle and the following semantic > patch: > > @bad exists@ > position p; > identifier x; > type T; > @@ > > static T x@p; > ... > x = <+...x...+> > > @@ > identifier x; > expression e; > type T; > position p != bad.p; > @@ > > -static >  T x@p; >  ... when != x >      when strict > ?x = e; > > In the following log you can see a significant difference in the > object file size. This log is the output of the size command, before > and after the code change: > > before: >    text    data     bss     dec     hex filename >  126304   30384    1280  157968   26910 > drivers/scsi/mpt3sas/mpt3sas_scsih.o > > after: >    text    data     bss     dec     hex filename >  126292   30240    1152  157684   267f4 > drivers/scsi/mpt3sas/mpt3sas_scsih.o I've got to say I'm deeply uneasy about using a data/bss size reduction as the benchmark for saying something shouldn't be declared static.  In this particular case the reduction is minimal, so it probably doesn't matter; however, if the reduction were more significant, changing from static to dynamic (i.e. on stack) allocation would increase the risk that we'd blow the kernel stack.  Indeed one reason you might find static declarations in functions is precisely to avoid blowing the stack, so we wouldn't want to reverse them. Other reasons for having static allocations instead of dynamic ones is that you need to DMA to/from the structure (you can't DMA to stack) or because you want to preserve values across function invocations. There are definite reasons why statics in functions are a bad idea: they prevent recursion and trip up code analysis, but in none of the above cases would the fix be to remove the static qualifier. James