From patchwork Mon Apr 24 07:51:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9695779 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 0AFDC601E9 for ; Mon, 24 Apr 2017 07:51:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBCC02654B for ; Mon, 24 Apr 2017 07:51:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0A6C26CFF; Mon, 24 Apr 2017 07:51:43 +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,DKIM_SIGNED, DKIM_VALID,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 576A32654B for ; Mon, 24 Apr 2017 07:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1166260AbdDXHvl (ORCPT ); Mon, 24 Apr 2017 03:51:41 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:8132 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1166215AbdDXHvj (ORCPT ); Mon, 24 Apr 2017 03:51:39 -0400 X-IronPort-AV: E=Sophos;i="5.37,243,1488816000"; d="scan'208";a="13405424" Received: from mail-dm3nam03lp0017.outbound.protection.outlook.com (HELO NAM03-DM3-obe.outbound.protection.outlook.com) ([207.46.163.17]) by ob1.hgst.iphmx.com with ESMTP; 24 Apr 2017 15:51:39 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=SdOk+d6bypvXXdTFbb5zjwKDfEiiO5x24V8sWIO7Opk=; b=IK/qhAewAxh6ZHHkqmtbNtabw0nC1HGRbsmgEub1vx/amCCDpDN+cbohiJ7OcaO4i438iKk/Eg58NMSa+/3XA0DMLUVNnYXC/PofvGW4kqzQRgMCf6Eg9Bs6IFH1e6uC+CcscEsLj/ndJq13HghwXO9ev2FZkrDvIN+2eo+AOhU= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.173) by CY1PR04MB1980.namprd04.prod.outlook.com (10.166.191.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1047.13; Mon, 24 Apr 2017 07:51:34 +0000 From: damien.lemoal@wdc.com To: linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Damien Le Moal Subject: [PATCH v2 4/7] scsi: Improve scsi_get_sense_info_fld Date: Mon, 24 Apr 2017 16:51:12 +0900 Message-Id: <20170424075115.30337-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170424075115.30337-1-damien.lemoal@wdc.com> References: <20170424075115.30337-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Originating-IP: [199.255.44.173] X-ClientProxiedBy: BN6PR1401CA0004.namprd14.prod.outlook.com (10.174.237.142) To CY1PR04MB1980.namprd04.prod.outlook.com (10.166.191.16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d93a53e5-16be-4d8f-3763-08d48ae6bc23 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY1PR04MB1980; X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 3:pDJEPFzFjPDEt6yaK4NZGUtRK6tvlbQUsyHHGWxHDNboGPl5hJDN2gs6oB50wqnbzSkjpYcn0UC0YM4Y4KwLU4nqadFgWdDSamp1il+IsKgfNMsCjCAxdfg0oKAlsqDwhHe+lzMaScuy5+RaxrOO4fHFlcwmlqwXNRjV+xiaKr6qwOzOGK42pDkuuFTr6zXrtNfd73MTDD5U/r2CuvaoytlYt3slBkEn/yCF6L6br4qEYvhdOM1VLCtqrYvE7bmblF04krNvUuGHrjBP2w4EEjUx2SaEWpS+SZeuqy13wrfgMmEJJWLeHkSXOzHNDS+ypaTuNkevU17LhGk276Z6UrOtJJxnrIVfxsgn3m/i/8I=; 25:5q5etfs5rPPORW8RoO0JVUqlEG7f7VE5nsScbFqsYoFRyo6TYhWh7Tq+UrLYqv7MS63WOZqcAMTmt3D805StPJSLSk6ur/mof43V6n+1m5HvvVFi2CNIDkNCl3ZSisGyZBeAEVWV6wCtQ3gH+j+m/EKg22PZkDoWcQ49XZDiM9Ne0nsMunP42MIevGaUFATd5lOKRPjH8PXCz7hcU2H4TuLBtyd3QT/5JwwodpPN7NDJMq3mDEjmy2J9URzAPPOsf4nc9iF8HDhFGU+koA2K9ZPMjdpxjlL60eM9Bh9rIT3e2bWPcuMEuqy269Jc5m3bWvNLcx3Q4+J+iE+EzNf3yQpy7RPmVd0IM3rbAZzt8mkaDAqr+V11FeaALEziCWy4nff4EXIrGy649qVhXVYYQv4qR1dvYrhoovr3WBZloYMgCrKxrTjRzdGR5VUoaEUCoUcbEnZBjHcMu3/dJvknpg== X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 31:L06o28gXWccxo4ZcgvRZF4jerVyCXEnFEJMePROYWmWA2aREO4GzRPYrIIpDWuI36ht+ZH3E+rOAzZQIf4lxDToDwvgUy2dMeldNbsYcPHxnjlMw72+2LPNEfNQG3RRkBEKCi0G7SetkCbqQ1jaZt/O9NMPMAQvRh5HTTIOzQnUXEQiWzr5Ly+UFeSsqRjCQVksvhPTT8mNaPj1ObRsuT9uMpBHtdtChDsumVvp7DWs=; 20:IuDAjaH0uRwRqC8GB3ZuCi9AfFsyp3D+tsK25VP9tenOj8/BhG3kwMOj0Og6ihCbDNYRyRGkZqBK6tukNG05bWE3lNCcWDDtNLNm5KfKfqW5tSWYRnrn2HKT8GJt97yf8HfOsMFpr1C1loqDuqoddyEbEXSfmfkOxYnw2oWJRoP1P3ESU9F1p0czZRMGFpxA42ZWkTea1J1pha2oidG54B4dI70iykD9jqHl/MhRRY04+3n8pnWgImo8zSZ/iYLZOC1tLGWc3+uW5SwUgiLmeHeGSrC8HnNSxf3+fokPX4ds8NXEUk2zk0hCVjs3NHkKolRiAjXjcwtnTDaBWOSTUJDgmyRKX0naRZBbrj+GP/AQYFRcv4fx9Cv+wOf4xxHVtZO4Lz7eEHaKpF4vDzUMnRAxQ+PLsZ0qrH0HFe2mheJIolEZzmTXgRa5bzPMYtXq7mf86BOzgH+jmNWvPCmH6FugwnjaNc4zc3LTq3US8kwnzJoyBnzuJ9WNQDtuph17 WDCIPOUTBOUND: EOP-TRUE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(6072148); SRVR:CY1PR04MB1980; BCL:0; PCL:0; RULEID:; SRVR:CY1PR04MB1980; X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 4:N7D/F+AuCcf+9t69/j3F+x+sL3YISajUs+eoYKgTD6ceNFLOMIJYaUcBeY7OXLfuTwY2qvchvBbc3qYIGilTMlQMnuJWEQuEwUSSY3BHZJTqDI4Js0NOi8kgWKVGUpwmeQRTtbk5JxPjB4ThJZYltEE1Ufjo2VZoowMmI2A8wtkJ2bSa8XE6cZ7HblEFw34757z24sl4Ma/Hf0Zo4mEvZY96n/WJqm9LZGovup+LJ73XWE3OO7fr23Iw1NqerOd622i7csIUtsUdSmnqYW3QQFNxjB48yx/MWOZRn3qNaOKiV5KWc3o5xF/CE0DombvvUkz33rFVgh+mBQW5FYn6CWRlLlyIRNJGPax3m2cxfPZ68hFX16QeZZLJoa5sSFdp+z5asgBVPowFAgYDXd0eJF/fQE2MnoNTbFhhxNozE1T494PTPi+O7mS1W/1kchs599lpvMYcbyXFCUgKuFfd1Pgo6Qd5jWZSczUo07/++bKLhGZ+Nga20ZoQz7TTtR8Zux8MOYu8u02te/hzk3YxOajEjE5vc+L42DMnvyLji7eIhItrFvxqWkKunh2yciBH5e8CQEVK2Ns/8NpFGstWUcJ+gXPomQqZpyk7SOcocku6UaVwiOW/CVXEIDOKF8gc847LH3B44C4H2aCna8LU/DOCsF3akGGjN3ZxRLNd0lt1WkAc5EZsHxarDYx4CdXjy8hw/nt9rP9HgHaR9Sg/nrM6C/9wnybreB4teomcHPQ7+mLCuaSVbrRjDLSFEnlyqWccQKSbI/P+7rnJUPhY0g== X-Forefront-PRVS: 0287BBA78D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39450400003)(39840400002)(39410400002)(39850400002)(39400400002)(39860400002)(33646002)(6512007)(9686003)(6666003)(81166006)(66066001)(8676002)(76176999)(7736002)(50986999)(305945005)(189998001)(50466002)(42186005)(6486002)(2950100002)(6916009)(47776003)(48376002)(54906002)(4326008)(2906002)(38730400002)(110136004)(5003940100001)(53936002)(25786009)(36756003)(86362001)(50226002)(1076002)(6116002)(3846002)(5660300001)(85782001)(85772001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR04MB1980; H:washi.fujisawa.hgst.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-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GOFDYzwDvv28eEJtoANbxnXtDtAw==; 24:Xj8RZOjdwP5cEH2A0rm4RiOcTNSVlJvACjNeh71diruSu5jbe/bhQLnrX8AQNU5gwKFrZaZiHDKyVdWrEiFA9fA8/qa/AgDAmNP9HnrU3UU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 7:BwUL0orvGOVGAFt54TNGHxJh8XlUU9ZRDytCdpXRvryXjmF7WbWisBrd9FtIunqrDJeK9dtNiMFmnjG4t8YFTjTBJjIs5gyaXp79hLlh7SmU0YVoZUXkD2lj+P2Ki7CkQMg6CH+uJmBo84aTc82LYL2KNfE+y3BQtkssJxxngbBrf1VzlYFLELcJNR4D6r6m8a4OWWuorX0Wm8zW6Pmo003dPbXW8qCbyU8Gc7DjeuR7zO26u74IWrEGb92Pr8jeEGJGU1btuauDs3TBmngJgRCJ2iK6DWxoxMdLxF23yfjDdqFunfuCspgvDGuYw2mNuGrWn0JbAI8rTVRPACiExA==; 20:TOEsgtMOp53DyLjkch/dyA3s6k8f36FHBQbhebRyB88XzNJ0Eom9LCrzXr6a3M5K6/+Pu6j5nZyhiVLQST5nHWdniDXiZR6eh6sqlugFc6ntvWjqdDMa6zl4gK58aW4x9HWLkvXI1+yjbpSItfTxui65AI6BemM9tzBmrjBq83s= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2017 07:51:34.8491 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR04MB1980 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 From: Damien Le Moal Use get_unaligned_be32 and get_unaligned_be64 to obtain values from the sense buffer instead of open coding the operations. Also change the function return value to a bool and fix the function signature declaration to remove spaces triggering checkpatch warnings. No functional change is introduced by this patch. Signed-off-by: Damien Le Moal Reviewed-by: Bart Van Assche Reviewed-by: Christoph Hellwig --- drivers/scsi/scsi_error.c | 38 +++++++++++++++----------------------- include/scsi/scsi_eh.h | 4 ++-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 53e3343..d70c67c 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -46,6 +46,8 @@ #include +#include + static void scsi_eh_done(struct scsi_cmnd *scmd); /* @@ -2361,44 +2363,34 @@ EXPORT_SYMBOL(scsi_command_normalize_sense); * field will be placed if found. * * Return value: - * 1 if information field found, 0 if not found. + * true if information field found, false if not found. */ -int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len, - u64 * info_out) +bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len, + u64 *info_out) { - int j; const u8 * ucp; - u64 ull; if (sb_len < 7) - return 0; + return false; switch (sense_buffer[0] & 0x7f) { case 0x70: case 0x71: if (sense_buffer[0] & 0x80) { - *info_out = (sense_buffer[3] << 24) + - (sense_buffer[4] << 16) + - (sense_buffer[5] << 8) + sense_buffer[6]; - return 1; - } else - return 0; + *info_out = get_unaligned_be32(&sense_buffer[3]); + return true; + } + return false; case 0x72: case 0x73: ucp = scsi_sense_desc_find(sense_buffer, sb_len, 0 /* info desc */); if (ucp && (0xa == ucp[1])) { - ull = 0; - for (j = 0; j < 8; ++j) { - if (j > 0) - ull <<= 8; - ull |= ucp[4 + j]; - } - *info_out = ull; - return 1; - } else - return 0; + *info_out = get_unaligned_be64(&ucp[4]); + return true; + } + return false; default: - return 0; + return false; } } EXPORT_SYMBOL(scsi_get_sense_info_fld); diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index a25b328..64d30d8 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -23,8 +23,8 @@ static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr) return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1)); } -extern int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len, - u64 * info_out); +extern bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len, + u64 *info_out); extern int scsi_ioctl_reset(struct scsi_device *, int __user *);