Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751846AbbL1Izp (ORCPT ); Mon, 28 Dec 2015 03:55:45 -0500 Received: from mail-am1on0121.outbound.protection.outlook.com ([157.56.112.121]:47999 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751502AbbL1Izn convert rfc822-to-8bit (ORCPT ); Mon, 28 Dec 2015 03:55:43 -0500 From: "Gujulan Elango, Hari Prasath (H.)" To: "gregkh@linuxfoundation.org" , "christian.gromm@microchip.com" , "joe@perches.com" , "andrey.shvetsov@k2l.de" , "sudipm.mukherjee@gmail.com" , "adrianremonda@gmail.com" CC: "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" Subject: [PATCHv2] staging: most: replace multiple if..else with table lookup Thread-Topic: [PATCHv2] staging: most: replace multiple if..else with table lookup Thread-Index: AQHRQU2FkHKLKfeyo0Si/S/RD+N/5Q== Date: Mon, 28 Dec 2015 08:55:37 +0000 Message-ID: <20151228085627.GA6862@IND12F0122> 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;DB5PR06MB1576;5:A1RFszY72sEJleDyDC3HVVwWu9gH4J+TLAzoczCtOgQJBUK/NOlTlMAn1r9vMepgxC72l+9T99RB0zLR1Wp+jfRqSZwPvqTu/oeacw3fZUqnMq+G4fMsVnO8mIU6x87EkfEP46LFdjsAwb7ZPSs3Nw==;24:ixU291k9/WogmHmbSMVBcJLxXcydhBOB8LkqkMv+KFpS3+B1U+XGBzmJ2y4VH1MBS7NFphRQhwKZCEx4tsmtCW8s/87ZgTGsknmPut2JQf4= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1576; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(208512329853888); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001);SRVR:DB5PR06MB1576;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1576; x-forefront-prvs: 08041D247D x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(199003)(189002)(229853001)(92566002)(2201001)(106116001)(66066001)(33716001)(105586002)(33656002)(106356001)(586003)(102836003)(101416001)(19580405001)(11100500001)(1220700001)(1096002)(1076002)(40100003)(54356999)(5001770100001)(5004730100002)(19580395003)(50986999)(5001960100002)(97736004)(189998001)(87936001)(5002640100001)(77096005)(3846002)(2900100001)(5008740100001)(122556002)(2501003)(2860100001)(86362001)(6116002)(81156007)(10400500002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB5PR06MB1576;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="us-ascii" Content-ID: Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: visteon.com X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Dec 2015 08:55:37.8508 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7a147aaf-01ec-498c-80a1-e34a8c63c548 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR06MB1576 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2663 Lines: 83 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 | 41 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index ed1ed25..fe6705a 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,16 @@ 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; + break; + } + } + + if (i == ARRAY_SIZE(ch_data_type)) { pr_info("WARN: invalid attribute settings\n"); return -EINVAL; } -- 1.9.1 -- 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/