Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754628AbbL3KpE (ORCPT ); Wed, 30 Dec 2015 05:45:04 -0500 Received: from mail-db3on0128.outbound.protection.outlook.com ([157.55.234.128]:21258 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754311AbbL3Ko7 convert rfc822-to-8bit (ORCPT ); Wed, 30 Dec 2015 05:44:59 -0500 From: "Gujulan Elango, Hari Prasath (H.)" To: Joe Perches CC: "gregkh@linuxfoundation.org" , "christian.gromm@microchip.com" , "andrey.shvetsov@k2l.de" , "adrianremonda@gmail.com" , "sudipm.mukherjee@gmail.com" , "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] staging: most: replace multiple if..else with table lookup Thread-Topic: [PATCH] staging: most: replace multiple if..else with table lookup Thread-Index: AQHRPjiy5DBP5u35i0eMShkwZ4SifZ7aTaMAgAkUW4A= Date: Wed, 30 Dec 2015 10:44:45 +0000 Message-ID: <20151230104536.GA21902@IND12F0122> References: <20151224104946.GA15381@IND12F0122> <1450973186.3554.13.camel@perches.com> In-Reply-To: <1450973186.3554.13.camel@perches.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=hgujulan@visteon.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [91.212.132.116] x-microsoft-exchange-diagnostics: 1;DB5PR06MB1573;5:sDke+HbFDiX9a4V6reGVNgZddn3a0TgztWuA9+clw47wnPPaGGBXMuFdgldvBSgh9otQpAz8IaPFHHC64Lyxg4Yj5Sv+KtxigwOI+SW45Rceh9cnN3h7Xza2i1ew2H4tLKpli9yykHz+rJ9OKXmwrQ==;24:pHIjXTnjuPYFaDNl6BZwZsZi1xR0XIA7CMt89ulpuxhebmsqbzZk/rQlUL4HJsoTujFymnZoUiGEswD0JCuzlxkNBxmduLyv17Ru8fgHYCA= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1573; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(208512329853888); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(3002001)(10201501046);SRVR:DB5PR06MB1573;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1573; x-forefront-prvs: 08062C429B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(199003)(189002)(377424004)(24454002)(97736004)(19580405001)(1096002)(66066001)(33656002)(5004730100002)(50986999)(10400500002)(86362001)(5001960100002)(4001150100001)(54356999)(2860100001)(76176999)(92566002)(122556002)(3846002)(189998001)(40100003)(5008740100001)(81156007)(2900100001)(77096005)(87936001)(5002640100001)(2950100001)(6116002)(105586002)(110136002)(106116001)(1076002)(586003)(1220700001)(33716001)(102836003)(11100500001)(19580395003)(106356001)(101416001);DIR:OUT;SFP:1102;SCL:1;SRVR:DB5PR06MB1573;H:DB5PR06MB1573.eurprd06.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-ID: Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: visteon.com X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Dec 2015 10:44:45.8920 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7a147aaf-01ec-498c-80a1-e34a8c63c548 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR06MB1573 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3249 Lines: 91 On Thu, Dec 24, 2015 at 08:06:26AM -0800, Joe Perches wrote: > On Thu, 2015-12-24 at 10:49 +0000, Gujulan Elango, Hari Prasath (H.) wrote: > > From: Hari Prasath Gujulan Elango > > > > Replace multiple if..else if..statements with simple table lookup in two > > functions. > > > > Signed-off-by: Hari Prasath Gujulan Elango > > --- > > ?drivers/staging/most/mostcore/core.c | 39 ++++++++++++++++++++---------------- > > ?1 file changed, 22 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c > > index ed1ed25..7b4636b 100644 > > --- a/drivers/staging/most/mostcore/core.c > > +++ b/drivers/staging/most/mostcore/core.c > > @@ -82,6 +82,14 @@ struct most_inst_obj { > > ? struct list_head list; > > ?}; > > ? > > +static const struct { > > + int most_ch_data_type; > > + char *name; > > +} ch_data_type[] = { { MOST_CH_CONTROL, "control\n" }, > > + { MOST_CH_ASYNC, "async\n" }, > > + { MOST_CH_SYNC, "sync\n" }, > > + { MOST_CH_ISOC_AVP, "isoc_avp\n"} }; > > + > > ?#define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj) > > ? > > ?/** > > @@ -414,14 +422,12 @@ static ssize_t show_set_datatype(struct most_c_obj *c, > > ? ?struct most_c_attr *attr, > > ? ?char *buf) > > ?{ > > - if (c->cfg.data_type & MOST_CH_CONTROL) > > - return snprintf(buf, PAGE_SIZE, "control\n"); > > - else if (c->cfg.data_type & MOST_CH_ASYNC) > > - return snprintf(buf, PAGE_SIZE, "async\n"); > > - else if (c->cfg.data_type & MOST_CH_SYNC) > > - return snprintf(buf, PAGE_SIZE, "sync\n"); > > - else if (c->cfg.data_type & MOST_CH_ISOC_AVP) > > - return snprintf(buf, PAGE_SIZE, "isoc_avp\n"); > > + int i; > > + > > + for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) { > > + if (c->cfg.data_type & ch_data_type[i].most_ch_data_type) > > + return snprintf(buf, PAGE_SIZE, ch_data_type[i].name); > > + } > > ? return snprintf(buf, PAGE_SIZE, "unconfigured\n"); > > ?} > > ? > > @@ -430,15 +436,14 @@ static ssize_t store_set_datatype(struct most_c_obj *c, > > ? ??const char *buf, > > ? ??size_t count) > > ?{ > > - if (!strcmp(buf, "control\n")) { > > - c->cfg.data_type = MOST_CH_CONTROL; > > - } else if (!strcmp(buf, "async\n")) { > > - c->cfg.data_type = MOST_CH_ASYNC; > > - } else if (!strcmp(buf, "sync\n")) { > > - c->cfg.data_type = MOST_CH_SYNC; > > - } else if (!strcmp(buf, "isoc_avp\n")) { > > - c->cfg.data_type = MOST_CH_ISOC_AVP; > > - } else { > > + int i; > > + > > + for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) { > > + if (!strcmp(buf, ch_data_type[i].name)) > > + c->cfg.data_type = ch_data_type[i].most_ch_data_type; > > Missing braces and break; > > > + } > > + > > + if (i == ARRAY_SIZE(ch_data_type)) { > > ? pr_info("WARN: invalid attribute settings\n"); > > ? return -EINVAL; > > ? } > > This seems like a lot of code for a simple test. > Hello Joe, I have sent a v2 for this patch with corrections made. Regards, Hari Prasath-- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/