From patchwork Mon Jan 15 17:05:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 10164849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F6CA602C2 for ; Mon, 15 Jan 2018 17:06:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AAC920407 for ; Mon, 15 Jan 2018 17:06:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E8A92040D; Mon, 15 Jan 2018 17:06:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B44B120407 for ; Mon, 15 Jan 2018 17:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935350AbeAORGe (ORCPT ); Mon, 15 Jan 2018 12:06:34 -0500 Received: from mga14.intel.com ([192.55.52.115]:37504 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935343AbeAORGc (ORCPT ); Mon, 15 Jan 2018 12:06:32 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2018 09:06:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,364,1511856000"; d="scan'208";a="19908194" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 15 Jan 2018 09:06:30 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8026DD0; Mon, 15 Jan 2018 19:05:59 +0200 (EET) From: Andy Shevchenko To: Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v1] mptfusion: Use snprintf() instead of open coded divisions Date: Mon, 15 Jan 2018 19:05:58 +0200 Message-Id: <20180115170558.86823-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.15.1 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Numbers up to 100 snprintf() prints without using a division. Besides that the code looks more readable. Signed-off-by: Andy Shevchenko --- drivers/message/fusion/mptctl.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c index 7b3b41368931..8d12017b9893 100644 --- a/drivers/message/fusion/mptctl.c +++ b/drivers/message/fusion/mptctl.c @@ -2481,24 +2481,13 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size) else karg.host_no = -1; - /* Reformat the fw_version into a string - */ - karg.fw_version[0] = ioc->facts.FWVersion.Struct.Major >= 10 ? - ((ioc->facts.FWVersion.Struct.Major / 10) + '0') : '0'; - karg.fw_version[1] = (ioc->facts.FWVersion.Struct.Major % 10 ) + '0'; - karg.fw_version[2] = '.'; - karg.fw_version[3] = ioc->facts.FWVersion.Struct.Minor >= 10 ? - ((ioc->facts.FWVersion.Struct.Minor / 10) + '0') : '0'; - karg.fw_version[4] = (ioc->facts.FWVersion.Struct.Minor % 10 ) + '0'; - karg.fw_version[5] = '.'; - karg.fw_version[6] = ioc->facts.FWVersion.Struct.Unit >= 10 ? - ((ioc->facts.FWVersion.Struct.Unit / 10) + '0') : '0'; - karg.fw_version[7] = (ioc->facts.FWVersion.Struct.Unit % 10 ) + '0'; - karg.fw_version[8] = '.'; - karg.fw_version[9] = ioc->facts.FWVersion.Struct.Dev >= 10 ? - ((ioc->facts.FWVersion.Struct.Dev / 10) + '0') : '0'; - karg.fw_version[10] = (ioc->facts.FWVersion.Struct.Dev % 10 ) + '0'; - karg.fw_version[11] = '\0'; + /* Reformat the fw_version into a string */ + snprintf(karg.fw_version, sizeof(karg.fw_version), + "%.2hhu.%.2hhu.%.2hhu.%.2hhu", + ioc->facts.FWVersion.Struct.Major, + ioc->facts.FWVersion.Struct.Minor, + ioc->facts.FWVersion.Struct.Unit, + ioc->facts.FWVersion.Struct.Dev); /* Issue a config request to get the device serial number */