Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753510AbbLXLW6 (ORCPT ); Thu, 24 Dec 2015 06:22:58 -0500 Received: from mail-am1on0108.outbound.protection.outlook.com ([157.56.112.108]:53324 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752268AbbLXLW4 convert rfc822-to-8bit (ORCPT ); Thu, 24 Dec 2015 06:22:56 -0500 X-Greylist: delayed 1080 seconds by postgrey-1.27 at vger.kernel.org; Thu, 24 Dec 2015 06:22:56 EST From: "Gujulan Elango, Hari Prasath (H.)" To: "gregkh@linuxfoundation.org" , "christian.gromm@microchip.com" , "andrey.shvetsov@k2l.de" , "adrianremonda@gmail.com" , "sudipm.mukherjee@gmail.com" CC: "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH] staging: most: replace multiple if..else with table lookup Thread-Topic: [PATCH] staging: most: replace multiple if..else with table lookup Thread-Index: AQHRPjiy5DBP5u35i0eMShkwZ4SifQ== Date: Thu, 24 Dec 2015 10:49:00 +0000 Message-ID: <20151224104946.GA15381@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: [74.112.164.116] x-microsoft-exchange-diagnostics: 1;DB5PR06MB1574;5:i6e+0UJebxQfavj9YVtstovCyteBf8sL70iJ9eoFX4xjfW5DUIlo2FTWZ5woEBrqf03bf7z11iviPFLO9tiwwGMAD0+6cI8msDSZ9tg+eD2rMf9n8DC7kwkAWrva9X1x/QD2EIJBsIkUUMTwgKDHqA==;24:4yb/SiSG6PMLSan63718e9TQQq0oHkGp3zFRwhIGvpNhThlO0BQJ5UCUHZNWPpIK9BkkAyZYqw1niA9qQwA3PW/CrZXG/zjKbmSPZzcA4ko= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1574; 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:DB5PR06MB1574;BCL:0;PCL:0;RULEID:;SRVR:DB5PR06MB1574; x-forefront-prvs: 0800C0C167 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(199003)(11100500001)(5001960100002)(189998001)(586003)(1076002)(105586002)(5001770100001)(97736004)(1096002)(86362001)(77096005)(2860100001)(106116001)(2201001)(1220700001)(106356001)(2900100001)(81156007)(2501003)(92566002)(102836003)(6116002)(10400500002)(3846002)(5008740100001)(5004730100002)(33656002)(122556002)(66066001)(40100003)(87936001)(5002640100001)(33716001)(19580395003)(19580405001)(54356999)(229853001)(101416001)(50986999);DIR:OUT;SFP:1102;SCL:1;SRVR:DB5PR06MB1574;H:DB5PR06MB1573.eurprd06.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A: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: 24 Dec 2015 10:49:00.6394 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7a147aaf-01ec-498c-80a1-e34a8c63c548 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR06MB1574 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2645 Lines: 81 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; + } + + 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/