From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934314AbcIGPJp (ORCPT ); Wed, 7 Sep 2016 11:09:45 -0400 Received: from smtprelay0005.hostedemail.com ([216.40.44.5]:36636 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753874AbcIGPJn (ORCPT ); Wed, 7 Sep 2016 11:09:43 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::,RULES_HIT:41:355:379:541:599:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3867:3868:3870:3871:3872:3874:4321:5007:7903:10004:10400:10848:11026:11232:11473:11658:11914:12043:12048:12438:12740:13069:13161:13229:13311:13357:13439:13894:13972:14659:14721:21080:21451:30012:30029:30054:30064:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: dog90_8ddfc2fb98238 X-Filterd-Recvd-Size: 2312 Message-ID: <1473260973.29864.13.camel@perches.com> Subject: Re: [PATCH v4 1/5] gpio: pca953x: code shrink From: Joe Perches To: Bartosz Golaszewski , Linus Walleij , Alexandre Courbot , Andy Shevchenko , Vignesh R , Yong Li , Geert Uytterhoeven Cc: linux-gpio , LKML Date: Wed, 07 Sep 2016 08:09:33 -0700 In-Reply-To: <1473259770-26224-2-git-send-email-bgolaszewski@baylibre.com> References: <1473259770-26224-1-git-send-email-bgolaszewski@baylibre.com> <1473259770-26224-2-git-send-email-bgolaszewski@baylibre.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.21.91-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2016-09-07 at 16:49 +0200, Bartosz Golaszewski wrote: > There are multiple places in the driver code where a > switch (chip->chip_type) is used to determine the proper register > offset. > > Unduplicate the code by adding a simple structure holding the possible > offsets that differ between the pca953x and pca957x chip families and > use it to avoid the checks. [] > diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c [] > @@ -94,6 +94,24 @@ MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids); >   >  #define NBANK(chip) DIV_ROUND_UP(chip->gpio_chip.ngpio, BANK_SZ) >   > +struct pca953x_offset { > > + int direction; > > + int output; > > + int input; > +}; The struct name seems suboptimal. Maybe pca95xx_reg_io_config or some such. > +static const struct pca953x_offset pca953x_offsets = { > > + .direction = PCA953X_DIRECTION, > > + .output = PCA953X_OUTPUT, > > + .input = PCA953X_INPUT, > +}; > + > +static const struct pca953x_offset pca957x_offsets = { > > + .direction = PCA957X_CFG, > > + .output = PCA957X_OUT, > > + .input = PCA957X_IN, > +}; The more naming consistency for #defines would be nice too at some point. >