From patchwork Tue May 23 23:48:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9744427 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 6374F6037F for ; Tue, 23 May 2017 23:49:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5186C28854 for ; Tue, 23 May 2017 23:49:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 434C02885B; Tue, 23 May 2017 23:49:22 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 A461928818 for ; Tue, 23 May 2017 23:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966515AbdEWXtT (ORCPT ); Tue, 23 May 2017 19:49:19 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:56777 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1765533AbdEWXtG (ORCPT ); Tue, 23 May 2017 19:49:06 -0400 X-IronPort-AV: E=Sophos;i="5.38,383,1491235200"; d="scan'208";a="19876945" Received: from mail-by2nam01lp0184.outbound.protection.outlook.com (HELO NAM01-BY2-obe.outbound.protection.outlook.com) ([216.32.181.184]) by ob1.hgst.iphmx.com with ESMTP; 24 May 2017 07:49:05 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ezD03ji25Ecv8AySursNSE0W3FMQQDSgQGIBC5YqEQ0=; b=PM1/7t1YNaNCF2fEunucpuvBkx3IsnMnkVBfphSWTQxUOkEQBW+dKId+9cO7H31m8ZmQkE8ZuBoEyLGWHt/SWrNFeFInieaIHTkSwWrEhTBac7bG7YnoR/AMg6YpNxoSyhqxmrZMUwH+GEqzw0xDeLTZ957rqvIFlrs99fjfNbw= Received: from DM5PR04CA0047.namprd04.prod.outlook.com (10.171.152.161) by CY4PR04MB0505.namprd04.prod.outlook.com (10.173.190.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Tue, 23 May 2017 23:49:03 +0000 Received: from BN3NAM04FT057.eop-NAM04.prod.protection.outlook.com (2a01:111:f400:7e4e::202) by DM5PR04CA0047.outlook.office365.com (2603:10b6:3:12b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14 via Frontend Transport; Tue, 23 May 2017 23:49:03 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.225) smtp.mailfrom=sandisk.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.225 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.225; helo=milsmgep14.sandisk.com; Received: from milsmgep14.sandisk.com (63.163.107.225) by BN3NAM04FT057.mail.protection.outlook.com (10.152.93.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1075.5 via Frontend Transport; Tue, 23 May 2017 23:49:02 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id CA.64.19026.D6AC4295; Tue, 23 May 2017 16:49:01 -0700 (PDT) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Tue, 23 May 2017 16:48:58 -0700 X-AuditID: 0ac94371-41ba798000004a52-01-5924ca6d5462 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 69.F2.18148.A6AC4295; Tue, 23 May 2017 16:48:58 -0700 (PDT) From: Bart Van Assche To: Nicholas Bellinger CC: , Bart Van Assche , Andy Grover , "David Disseldorp" Subject: [PATCH 06/33] target: Use {get, put}_unaligned_be*() instead of open coding these functions Date: Tue, 23 May 2017 16:48:27 -0700 Message-ID: <20170523234854.21452-7-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170523234854.21452-1-bart.vanassche@sandisk.com> References: <20170523234854.21452-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsXCddJ5kW7uKZVIg5OdAhb7Zz1jsvj6fzqL RdvqM4wWrUvfMjmweNzffoTJ4/2+q2wem09Xe3zeJBfAEsVlk5Kak1mWWqRvl8CV8fPkHNaC c8cYK/Yuvs/cwPh8PmMXIyeHhICJREPvHyYQW0hgKZPE5kmSXYxcQPYORol3vRvYuxg5wIqO /YuAiG9klPg94xFYA5uAkcS39zNZQGwRAR2JWXdfsIMUMQvMYJSYuPggWEJYIFni39457CA2 i4CqxLtDd8A28wrYS9y5f5YZ4gp5ibNbdoLZnAIOEiv3bGMGWSwEVHP5uzLITAmBLlaJG/uO M0H0CkqcnPkEbD6zgITEwRcvmCE+UJc4uWQ+0wRGoVlIymYhKVvAyLSKUSw3M6c4Nz21wNBE rzgxLyWzOFsvOT93EyMktAt3ML6+7X2IUYCDUYmHN8FBJVKINbGsuDL3EKMEB7OSCO/yDUAh 3pTEyqrUovz4otKc1OJDjNIcLErivFmyUyOEBNITS1KzU1MLUotgskwcnFINjOF1d7K1bbkP rvXiXGdrf2rqllM6ObY7j+yePvFR4Jtl2vXl9tL2hZ8mOcjriUiVx66Y4Sj2ZdXMK5bL/wVV 66ZuPftywhTN/uYrqs9+cXKu3qu8vJf74f+37f21LZf7IpNFr75NsZB98zittldU02PO6xWG bHe1HmVWi1i7OJ1nubdTUf3xRiWW4oxEQy3mouJEACwyZT5pAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGJMWRmVeSWpSXmKPExsXCtZGTTTfrlEqkwfmZ4hb7Zz1jsjj4s43R 4uv/6SwWbavPMFq0Ln3L5MDqcX/7ESaP9/uusnlMW3OeyWPz6WqPz5vkAlijuGxSUnMyy1KL 9O0SuDJ+npzDWnDuGGPF3sX3mRsYn89n7GLk4JAQMJE49i+ii5GLQ0hgPaPE8QvfWboYOTnY BIwkvr2fCWaLCOhIzLr7gh2kiFlgBqNEf/M1ZpCEsECyxL+9c9hBbBYBVYl3h+4wgti8AvYS T7e+ZgKxJQTkJc5u2QlWzyngILFyzzZmkMVCQDWXvytPYORewMiwilEsNzOnODc9s8DQSK84 MS8lszhbLzk/dxMjJCSidjBen2h+iJGJg1OqgTE7YN+FnU07je+dY5vycrPiQlX7p0UGt9NS jloYss78NvGuI+OMnpM/mlaa+W83ZngmwvO6y5r/6ezOmBCz4CK+hkauye8bwuynytqZMNk9 ejzhjtXHldzvGR0Ue3R3PzI9b6Rt1BaXfyCDl1O/aJ3A092rk3Z05jEx3ijvkdy8Oy6mXfnW biWW4oxEQy3mouJEADkGIB25AQAA MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:63.163.107.225; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(39860400002)(39850400002)(39400400002)(39450400003)(39410400002)(39840400002)(2980300002)(438002)(189002)(199003)(40224003)(9170700003)(356003)(50466002)(38730400002)(33646002)(72206003)(50986999)(76176999)(5660300001)(110136004)(86362001)(478600001)(1076002)(48376002)(2906002)(189998001)(575784001)(4326008)(47776003)(36756003)(77096006)(106466001)(81166006)(54906002)(8676002)(50226002)(6916009)(8936002)(53936002)(2950100002)(305945005)(6666003)(5003940100001)(142933001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR04MB0505; H:milsmgep14.sandisk.com; FPR:; SPF:Pass; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN3NAM04FT057; 1:SotwRKci30RvOD67+cGZSY3vsOVd7NTzmoTJcYQ2dFYWC4Snw4xfXz/fjzUcAqBDkyq0STSheexJcksBqeibjWmAw18p1lR4KGw9tiD8E3sEClonXLumQQVDOj8t1Sc+1FLO8E5AKXu8sRCOaA7IYztiLgnCjjFafiAwL0/VawuP8XKw43cGO4IjKI+BQu12pgg1l5avZ4AymqJ6hcWaDSaLsNpQSF0K/bh9ocZPQUs1D+E88d5Mkl2luA5S7b/hygnmBKq9GCRhy/n+zeYrRuX3n7DqABukiXXDeY9tlabXoKIBaZFGwbQ/Dx4cHbnQAo12bpwQitHzBrdrzsUoSbqnC8EA2SkNpcn9sijdYu8nj1L9iElZH6A6bA3mrqxQZ1AFLVsgCFt8uwM1vyT58HemFiMThwepIPC56FHwR0oz6b5r2A05/UCbbO4/z5H12GI1SePZNlVi+6ei4H9W7CEdBBkV+hfTgiYX8/KCNhOVkuGdogXeQRebMA/PxjzBVgXKPYb7pBWv1F1CPjQlRny13ntlw0DM3T+Wl7MiCms= X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PR04MB0505: X-MS-Office365-Filtering-Correlation-Id: edc81009-f7d4-4012-8908-08d4a2364ab3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(8251501002)(2017030254075)(201703131423075)(201703031133081); SRVR:CY4PR04MB0505; X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB0505; 3:FNz8+Ug9z1J/6dv9UexJoeGNb0/T9aRzIPvloiCUg8ldTHm3DBT2Guwx5HoSDu4aqMdOwBVwSY8CrnCkE2lY1yvhpOj1AyHDo//ZzMs8O+TuHsscCRvu+dShEw+9uDOaYguVA5BD1N0RX2HVpxrwW8CuPE9ls99NX3F0yBTaUuViwOi7uIESSZrhK5UEPUvOiUw/X+u44s+SU4EJl0d9gxFBIgqvfhN8QKvPioXEifD0G/qGoxvUz9MW0AevZ3AH7c3/Elc+edAkjwml++WwMU/FIbSl8g4MGAt9gXdHngn1jzdo1m/f8s/5Vb0Csk7kfq4FfOLnkM3AIXc2GUAfT+rPB7w4XNM7qVoW3HA5pkzAkW3j+HV1/s0bgw+j9YzzGkr7a4xnauMKr5ALA/tZXzured+YwCuTzrlNGOnxE7MiwV+gXkHlwi6L9Tj7ZyGqRuQ7t1fibZwUeYPZdEj2kvBttvgl2GCYlwbVpP1g382icG0vRzIzeiTmnNvZrYb8 X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB0505; 25:gNR6OmoF08nNMCkzHwK5mDJDjXAm5Mz/tCisDw80+IxbederkcvN+cyYgDT/qW1nh4TI7BAX9Fe1RP0cIgQF6xtmdeUYX+FjZ04jpe3mYlzj/q4ED83VFcZxw/++AYI/GaDEfHUDdLxoOuWam47pMw3JHWLfSWZs4JaJqkDcvdN4qH6/BT/S+6HMH7fDGl3jiRzIWWeL+X0b47GXvf1qJGo2co/xE9/F+KHjSoyd5hh3HtalHkIz9KS4F846DoIICYQtIdF4Svv/n7s8t5rXr6W00oEqCIdzosB0V3H+UMszdJnWxLKRiOW5HYfjc6HbN3yMd7X3Sc7J83sWiFcmNeX2hjeLTvD+fYoQ0he9RQxaQz1j5MJMAAYIWlsUf/BCGqeJpslRVIERhN3aNOvvJQuWc5qH1sCH+BrjRDdccL047K9lBTXYFZ75fQ8SgGb9OYJzBl1QUrxM/DFWMqmYA3YRb8AJe8sF0+0Ps4H5aJw=; 31:cnAIYU5dEAj9Jyssvf0byD1u697UKIcHleZPy7TKmzJ8SLuNwRhOW417SG/D0sGaDXMBRBuqH9O3M7uiNB0uLuYT2HZ5JaT7hSOfe04+F+U4e+rVFIyQ8khcNmUgqHuOyJhsACZVfDJ3XcLFy6wT5/o211dGX8qKc6PNxY3SMGyFtH03SJivnuMsaRoQUa9sMbjU7ICidARKyFCH12hM6iePH6HEJDDKVSOo3jIB43gxEK5XB6pNICBH5zDknTE1OHDM2PT2py3uTVV91p/UWw== WDCIPOUTBOUND: EOP-TRUE X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB0505; 20:IyjKmqA9lY/PsOec61Z+rF3C7P9kmpBCmits715Nal3pdwx6pMD326faAYPWtF9t8HAVz/zEpvTJdlw124o77xbwiK6VCqE3aD2RnphdsJLsFqX2aPFPPItToabBS052fB4dGirbbbvltrCE6e7iAY24AB/vy1H3i1N1q2BSF+GCYeX6NwFvRpFQcUGv1fFxsrLITm1F2/PyvDvMxMcN4anYtWcPAPuehANGy0whQa86NwLrZc9wJyUEAd2qB7xyLYA7DzehSZtO1m8hPRJOfiF5EYquQYOQvzCrozm3FF2w3bztzwM6T8O+O8GFQozBmaIf7BTZqFtfK8bI9jcOmWYLY7FPq3i//Jq7Q6ageKJe5+CHDSUMxiYUqc8sOV7hC717Y/0SO0psR8/HkLBjOraR1Zd4zWm4D1/a0xfmBslVMNryf+/7+cStSJA9VwCiX0CmR/W6x2egFoa11J282RiQHaEHGJpRKca9cgRlX0VcsOfvwYpiBWmiza1WVZax X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705)(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(13018025)(8121501046)(13016025)(93006095)(93004095)(3002001)(10201501046)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(20161123560025)(20161123558100)(20161123555025)(6072148); SRVR:CY4PR04MB0505; BCL:0; PCL:0; RULEID:; SRVR:CY4PR04MB0505; X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB0505; 4:wiuPRrFGggZ2pSS6F8qM7FVamfw1x41iWI2HZPaFm57jGjS6VLd6nnWNKcEZvRjSyDakVdqj/nhngwIr4FGNr9C5IaTR6mWn0mxUQKJVtNq5Bom67hiKFcv07k2RSRLgWOE3hzUh4WXh0OyFXNjKcF2den0VMVKmLOfKqFeNEMKA83LUJeY5NJ0yMtq56wmL9WjYoQVsKs/Be/jjnNr7LY3tJdDUe5qzmdJFVjmelSjqvTLlVyBWApt4zdU0p0T9e+v/7l9zW9BXN1RpkitC13Bjg0iFPr/6VsYxWRIUy0g6NNPVK6q/M+bLBEWIUEmqYj+m5EvVe8dLpzEwS8uxyeKVmh8mnmgfc8XiNDlRvnl8CxJhHKdhvotQKgFco+bNV/zoObDCPQvzLhCjvOoChnnMCD2ocE5SQ3eWJphwIyDpEJrZQHLolpOKnIyq7EGKrRY3EFFn71zkb/fCy6QCQU4qpiZms1Gv3f+FBnODyly5InhaYGHoUQDhAYmpDmesjpCiCYNG341nVNQ3+/AgL5aDcYEwjyNWTEzZlgsLKx2h1oMyEw7xjcJT/NQHqcRTHyXfp67jaD6gUg1g88ffYnGIfIhDh08tJGEM9Ex78/TOHrfo8e4SIPsork6xSsugHwpd7DIk65Y4+ITSxpU6FfivonwO4zKoLi6L0Qf3re92/e+AFKn7Ao3IDAIab8TsSKP9sO8iym9xev2WZGnOYNpE/9FCWWGCM9uWx1VCh14XPQXukeFmd6vfUj+31fe/8sGSt+RgEcJiGT9wny5RvHm6J91KNXEhHRpEaQmPY1bFZWt9naQcd27X0Op7b2QdunvRYOOqjv2CIL3JcuQxYzpt0Jzaw9+EP/k+Co5YuMv2wM1o6XgxVPnTP9cTlrLJCKPuc51TYE3z3v/xtEFYy+COZsxIwvASsXjXMEJAFC 8= X-Forefront-PRVS: 0316567485 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR04MB0505; 23:zcbPYc19o0gytBVw1QHTlXdXe9DNRkHHuain5jh61?= =?us-ascii?Q?tnqRBH9KoTgnpiFSzEZQt7moddVva6luwazmO364jGu0uCQvdnG7REXvfQyS?= =?us-ascii?Q?F8X8ZAViMoE57h379AtBHxveM+Ifd2BNF3zOVy2uZ249NKwNU5pUuA4Z+LFr?= =?us-ascii?Q?Tw8Pr3cGYzVdQPdEXk4LiWF7cqSLyMfRGXI10UjiN99G0/XTCCFyXZE0utsT?= =?us-ascii?Q?VySPdUaGY/y/VVrrwL2BuWzXYuhWAVElSO3OYJtyK10btAufSo4dHNBAxfmP?= =?us-ascii?Q?4GZ3ZTYweVHDtYD5VyM7uNmT88kqp0sBlW06BIkHOmTpekNJPvu6lOcFe7o6?= =?us-ascii?Q?ex8EFE97nV3TgETfaN/6qtSGffthZjccGZaIESs2Edp4uz8yUL5iR7LIFr2B?= =?us-ascii?Q?skPseBk0awUiC840V+QCAc+dR00qbEfTb0m5T4pSRY46d5LH7J5mTjt8EyXm?= =?us-ascii?Q?BHyk6ledAFmfGoczVn8z7O9ROQGS/6F065+x4152jS07A5KGdXWkaOYM4GyR?= =?us-ascii?Q?A54nVa99xWyTXOJ1YmoJpnyVWFvBEzwVlEtyA8nuqYMiqLp8MpUbmNU90Hc6?= =?us-ascii?Q?wDQV8RUnsm9EPUof5xnfvfG519l0pMXPcybm/CBYsCN/UT9GZLRf6ge4Hf/B?= =?us-ascii?Q?TVgpax5+9/t/1CQtEHDKB2cE+aNH0FMhLLN954FSgjndSeXI4GmY/MGSetv4?= =?us-ascii?Q?HlS5lmGB+Y8Z+nOBkl34eHEumI06XAa9u4VXn420XB8BoTnD5E6BXD6RgaGq?= =?us-ascii?Q?87ZaaUbNztZLavBuI86yNOqO10mCwzZn0URAxbHbEe2hYiePTeTCedNJkglk?= =?us-ascii?Q?t4/w+wu2uivguZ81Tb/ViT/lFBVnql58fOiNzFn5QOx7kmUp4BpcxCXcc4UY?= =?us-ascii?Q?17Zo/nyEoLHw2ETcc32n/H1Yb5f5YI0EZ7pLmScLImcE2aX+kDiqlDukkgKf?= =?us-ascii?Q?CPgjzeQFUG/rFFNd5xdyqaMy9VX9sneYOe2/6Z5fU5rzSD7y0gZvbxLl91yo?= =?us-ascii?Q?5q23AbLYi8U8OEzKXrMRZ0PPt1seCBevuE4F+/Tx2brBugibNeC9z1sFPESq?= =?us-ascii?Q?v0u4ej4aOFynmQXrCYqsSKA6aekEGj0v8D1jjwQye23fV7ypLHY7k1jjvKfg?= =?us-ascii?Q?rk91ypybpBcVasHn08vLgX1eVhzQXGvwDKwaen3uP6oKmiSm/vpaQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB0505; 6:9ARaMZAz60dBAJAMCHryW2UgdCuoq8ZraM4zayoYjlgU6MNOaz0gEeO6KOr4UeW4kgACenAI/uyiRSZwmSy99qe0djH0pde9Ksp6nrXONFJ8/p8DxvUOmRqFZqSxKQEp+TVxfsVHzGKfkDc+TLv6adv5dyOlafYTzpIUkr0K7ZH+Hm4zWYQIHn4TIWvpVPmoEZA0XMCDoelZjr0qmPy0oabQFrbUoqvXd1KolT44sk4vHvsUx7pKxNTfo2idMmiJxFRdzHoay3JOphI0EHS8jMSdL1WN1pz5ZeZan0BHZHMgqKOoqDob1r0YKb7PUxj95JmPYxwiJ0gJtyjy3mX7HdflKskT/1OzubHUR+1KRbsoNNnuMuZefPk0KjPdEN45BrVJOHsoRV/qL+KPL8PwdZONqDBQ+7Y58m5laBqJxKD+7WhiZoelgHGBW4QxnQjX7+Z3/zGpGCfjZokvb4ozSaLWa9zzJ0//ybharsAEusSDQ9/IdacdUgA6akmvsDrmjsszaqDN5tBFtUnRmu1BPOmh3+PCqY9+6wnMXjOMm5Y=; 5:igeARa8mkrmC1zvwKmGTXo324t4a5XhvgSz2CEdDDIXw+R7fdE2+qdb3279HPU+F1FDIAABzxyp7Op9TvQcgkvfLyFGS12oWdpZj4ireYoQoxn476wyOKCnOkwtqZ7Jm7Navgvln+gmR/3EWJHU1MA==; 24:R3kuPFVgeTB1JCG7ZKbltUQ19km4pwo/VOZmApQnpPZKnffzoV5zpyPnLW7hfLNG+BvcOnCljepE1TLWYDUQ9O30uuQWzvzQATRfNB/787o= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB0505; 7:UpUQ0zPrA7+8F60DF73cXzPdyrdPqFPpDzZ9ywUF3wzNux+f8IcW10ueqxfQDmItf/wSYdfUggx5nQ8m+P3Wf2cAEKBE+d+cTh4qVVSpSwTPGg9MpTjYlA1SBPP9GTeGpez+Zfxldv7naZ4qsics52HHjLw6lMQH4WLpjO/JumRXbbenMi6MLq/fZBFDAp+BfCxnVBTUUmlhC4cqD0Bb+N9P+KpkGAXD7w7c8XHXXsDjLtRHJpnKReV9LkPqmV2k72XKLOcF8BwSJ0t/3o8VvLbWEjq8Tlmdc6u6Ut2LWGtqnjcLBlRriwlgL5l5xyUctDfISBhjiGJKwE3Gnto6dw==; 20:cwGEj/MYSn9AzV8VkQfHL2vsrktXo7u9OhtBu1qfuovdkOXCCHcXm7/MQgRLmTmmmNsEwrcbnN3n/jspj7JYal5R8XAIpWKDAUnLpbv6oP3HPX7Kua36SS4ThZ9a9NKX35Lw6al5R1s4glduPVMDgPn/7r4HZsIZA6oJbAIKnIQ= X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2017 23:49:02.6296 (UTC) X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=b61c8803-16f3-4c35-9b17-6f65f441df86; Ip=[63.163.107.225]; Helo=[milsmgep14.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR04MB0505 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce the function get_unaligned_be24(). Use {get,put}_unaligned_be*() where appropriate. This patch does not change any functionality. Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Cc: Andy Grover Cc: David Disseldorp --- drivers/target/target_core_alua.c | 8 +-- drivers/target/target_core_device.c | 8 +-- drivers/target/target_core_fabric_lib.c | 6 +- drivers/target/target_core_pr.c | 99 +++++++-------------------------- drivers/target/target_core_pscsi.c | 20 +++---- drivers/target/target_core_sbc.c | 59 +++++--------------- drivers/target/target_core_spc.c | 42 +++++++------- drivers/target/target_core_xcopy.c | 4 +- include/target/target_core_backend.h | 8 +++ 9 files changed, 83 insertions(+), 171 deletions(-) diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c index fc4a9c303d55..a91b7c25ffd4 100644 --- a/drivers/target/target_core_alua.c +++ b/drivers/target/target_core_alua.c @@ -205,8 +205,8 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd) /* * TARGET PORT GROUP */ - buf[off++] = ((tg_pt_gp->tg_pt_gp_id >> 8) & 0xff); - buf[off++] = (tg_pt_gp->tg_pt_gp_id & 0xff); + put_unaligned_be16(tg_pt_gp->tg_pt_gp_id, &buf[off]); + off += 2; off++; /* Skip over Reserved */ /* @@ -235,8 +235,8 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd) /* * Set RELATIVE TARGET PORT IDENTIFIER */ - buf[off++] = ((lun->lun_rtpi >> 8) & 0xff); - buf[off++] = (lun->lun_rtpi & 0xff); + put_unaligned_be16(lun->lun_rtpi, &buf[off]); + off += 2; rd_len += 4; } spin_unlock(&tg_pt_gp->tg_pt_gp_lock); diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index bab2cf4e429a..aa6ccf521e33 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -1086,19 +1086,19 @@ passthrough_parse_cdb(struct se_cmd *cmd, TRANSPORT_FLAG_PASSTHROUGH_PGR)) { if (cdb[0] == PERSISTENT_RESERVE_IN) { cmd->execute_cmd = target_scsi3_emulate_pr_in; - size = (cdb[7] << 8) + cdb[8]; + size = get_unaligned_be16(&cdb[7]); return target_cmd_size_check(cmd, size); } if (cdb[0] == PERSISTENT_RESERVE_OUT) { cmd->execute_cmd = target_scsi3_emulate_pr_out; - size = (cdb[7] << 8) + cdb[8]; + size = get_unaligned_be16(&cdb[7]); return target_cmd_size_check(cmd, size); } if (cdb[0] == RELEASE || cdb[0] == RELEASE_10) { cmd->execute_cmd = target_scsi2_reservation_release; if (cdb[0] == RELEASE_10) - size = (cdb[7] << 8) | cdb[8]; + size = get_unaligned_be16(&cdb[7]); else size = cmd->data_length; return target_cmd_size_check(cmd, size); @@ -1106,7 +1106,7 @@ passthrough_parse_cdb(struct se_cmd *cmd, if (cdb[0] == RESERVE || cdb[0] == RESERVE_10) { cmd->execute_cmd = target_scsi2_reservation_reserve; if (cdb[0] == RESERVE_10) - size = (cdb[7] << 8) | cdb[8]; + size = get_unaligned_be16(&cdb[7]); else size = cmd->data_length; return target_cmd_size_check(cmd, size); diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c index cb6497ce4b61..508da345b73f 100644 --- a/drivers/target/target_core_fabric_lib.c +++ b/drivers/target/target_core_fabric_lib.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -216,8 +217,7 @@ static int iscsi_get_pr_transport_id( if (padding != 0) len += padding; - buf[2] = ((len >> 8) & 0xff); - buf[3] = (len & 0xff); + put_unaligned_be16(len, &buf[2]); /* * Increment value for total payload + header length for * full status descriptor @@ -306,7 +306,7 @@ static char *iscsi_parse_pr_out_transport_id( */ if (out_tid_len) { /* The shift works thanks to integer promotion rules */ - add_len = (buf[2] << 8) | buf[3]; + add_len = get_unaligned_be16(&buf[2]); tid_len = strlen(&buf[4]); tid_len += 4; /* Add four bytes for iSCSI Transport ID header */ diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 129ca572673c..9921d4d6bb41 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -1562,10 +1562,7 @@ core_scsi3_decode_spec_i_port( * first extract TransportID Parameter Data Length, and make sure * the value matches up to the SCSI expected data transfer length. */ - tpdl = (buf[24] & 0xff) << 24; - tpdl |= (buf[25] & 0xff) << 16; - tpdl |= (buf[26] & 0xff) << 8; - tpdl |= buf[27] & 0xff; + tpdl = get_unaligned_be32(&buf[24]); if ((tpdl + 28) != cmd->data_length) { pr_err("SPC-3 PR: Illegal tpdl: %u + 28 byte header" @@ -3221,12 +3218,8 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key, goto out_put_pr_reg; } - rtpi = (buf[18] & 0xff) << 8; - rtpi |= buf[19] & 0xff; - tid_len = (buf[20] & 0xff) << 24; - tid_len |= (buf[21] & 0xff) << 16; - tid_len |= (buf[22] & 0xff) << 8; - tid_len |= buf[23] & 0xff; + rtpi = get_unaligned_be16(&buf[18]); + tid_len = get_unaligned_be32(&buf[20]); transport_kunmap_data_sg(cmd); buf = NULL; @@ -3552,16 +3545,6 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key, return ret; } -static unsigned long long core_scsi3_extract_reservation_key(unsigned char *cdb) -{ - unsigned int __v1, __v2; - - __v1 = (cdb[0] << 24) | (cdb[1] << 16) | (cdb[2] << 8) | cdb[3]; - __v2 = (cdb[4] << 24) | (cdb[5] << 16) | (cdb[6] << 8) | cdb[7]; - - return ((unsigned long long)__v2) | (unsigned long long)__v1 << 32; -} - /* * See spc4r17 section 6.14 Table 170 */ @@ -3619,8 +3602,8 @@ target_scsi3_emulate_pr_out(struct se_cmd *cmd) /* * From PERSISTENT_RESERVE_OUT parameter list (payload) */ - res_key = core_scsi3_extract_reservation_key(&buf[0]); - sa_res_key = core_scsi3_extract_reservation_key(&buf[8]); + res_key = get_unaligned_be64(&buf[0]); + sa_res_key = get_unaligned_be64(&buf[8]); /* * REGISTER_AND_MOVE uses a different SA parameter list containing * SCSI TransportIDs. @@ -3734,10 +3717,7 @@ core_scsi3_pri_read_keys(struct se_cmd *cmd) if (!buf) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; - buf[0] = ((dev->t10_pr.pr_generation >> 24) & 0xff); - buf[1] = ((dev->t10_pr.pr_generation >> 16) & 0xff); - buf[2] = ((dev->t10_pr.pr_generation >> 8) & 0xff); - buf[3] = (dev->t10_pr.pr_generation & 0xff); + put_unaligned_be32(dev->t10_pr.pr_generation, buf); spin_lock(&dev->t10_pr.registration_lock); list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, @@ -3749,23 +3729,13 @@ core_scsi3_pri_read_keys(struct se_cmd *cmd) if ((add_len + 8) > (cmd->data_length - 8)) break; - buf[off++] = ((pr_reg->pr_res_key >> 56) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 48) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 40) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 32) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 24) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 16) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 8) & 0xff); - buf[off++] = (pr_reg->pr_res_key & 0xff); - + put_unaligned_be64(pr_reg->pr_res_key, &buf[off]); + off += 8; add_len += 8; } spin_unlock(&dev->t10_pr.registration_lock); - buf[4] = ((add_len >> 24) & 0xff); - buf[5] = ((add_len >> 16) & 0xff); - buf[6] = ((add_len >> 8) & 0xff); - buf[7] = (add_len & 0xff); + put_unaligned_be32(add_len, &buf[4]); transport_kunmap_data_sg(cmd); @@ -3796,10 +3766,7 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) if (!buf) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; - buf[0] = ((dev->t10_pr.pr_generation >> 24) & 0xff); - buf[1] = ((dev->t10_pr.pr_generation >> 16) & 0xff); - buf[2] = ((dev->t10_pr.pr_generation >> 8) & 0xff); - buf[3] = (dev->t10_pr.pr_generation & 0xff); + put_unaligned_be32(dev->t10_pr.pr_generation, &buf[0]); spin_lock(&dev->dev_reservation_lock); pr_reg = dev->dev_pr_res_holder; @@ -3807,10 +3774,7 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) /* * Set the hardcoded Additional Length */ - buf[4] = ((add_len >> 24) & 0xff); - buf[5] = ((add_len >> 16) & 0xff); - buf[6] = ((add_len >> 8) & 0xff); - buf[7] = (add_len & 0xff); + put_unaligned_be32(add_len, &buf[4]); if (cmd->data_length < 22) goto err; @@ -3837,14 +3801,7 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) else pr_res_key = pr_reg->pr_res_key; - buf[8] = ((pr_res_key >> 56) & 0xff); - buf[9] = ((pr_res_key >> 48) & 0xff); - buf[10] = ((pr_res_key >> 40) & 0xff); - buf[11] = ((pr_res_key >> 32) & 0xff); - buf[12] = ((pr_res_key >> 24) & 0xff); - buf[13] = ((pr_res_key >> 16) & 0xff); - buf[14] = ((pr_res_key >> 8) & 0xff); - buf[15] = (pr_res_key & 0xff); + put_unaligned_be64(pr_res_key, &buf[8]); /* * Set the SCOPE and TYPE */ @@ -3882,8 +3839,7 @@ core_scsi3_pri_report_capabilities(struct se_cmd *cmd) if (!buf) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; - buf[0] = ((add_len >> 8) & 0xff); - buf[1] = (add_len & 0xff); + put_unaligned_be16(add_len, &buf[0]); buf[2] |= 0x10; /* CRH: Compatible Reservation Hanlding bit. */ buf[2] |= 0x08; /* SIP_C: Specify Initiator Ports Capable bit */ buf[2] |= 0x04; /* ATP_C: All Target Ports Capable bit */ @@ -3947,10 +3903,7 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd) if (!buf) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; - buf[0] = ((dev->t10_pr.pr_generation >> 24) & 0xff); - buf[1] = ((dev->t10_pr.pr_generation >> 16) & 0xff); - buf[2] = ((dev->t10_pr.pr_generation >> 8) & 0xff); - buf[3] = (dev->t10_pr.pr_generation & 0xff); + put_unaligned_be32(dev->t10_pr.pr_generation, &buf[0]); spin_lock(&dev->dev_reservation_lock); if (dev->dev_pr_res_holder) { @@ -3992,14 +3945,8 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd) /* * Set RESERVATION KEY */ - buf[off++] = ((pr_reg->pr_res_key >> 56) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 48) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 40) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 32) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 24) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 16) & 0xff); - buf[off++] = ((pr_reg->pr_res_key >> 8) & 0xff); - buf[off++] = (pr_reg->pr_res_key & 0xff); + put_unaligned_be64(pr_reg->pr_res_key, &buf[off]); + off += 8; off += 4; /* Skip Over Reserved area */ /* @@ -4041,8 +3988,8 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd) if (!pr_reg->pr_reg_all_tg_pt) { u16 sep_rtpi = pr_reg->tg_pt_sep_rtpi; - buf[off++] = ((sep_rtpi >> 8) & 0xff); - buf[off++] = (sep_rtpi & 0xff); + put_unaligned_be16(sep_rtpi, &buf[off]); + off += 2; } else off += 2; /* Skip over RELATIVE TARGET PORT IDENTIFIER */ @@ -4062,10 +4009,7 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd) /* * Set the ADDITIONAL DESCRIPTOR LENGTH */ - buf[off++] = ((desc_len >> 24) & 0xff); - buf[off++] = ((desc_len >> 16) & 0xff); - buf[off++] = ((desc_len >> 8) & 0xff); - buf[off++] = (desc_len & 0xff); + put_unaligned_be32(desc_len, &buf[off]); /* * Size of full desctipor header minus TransportID * containing $FABRIC_MOD specific) initiator device/port @@ -4082,10 +4026,7 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd) /* * Set ADDITIONAL_LENGTH */ - buf[4] = ((add_len >> 24) & 0xff); - buf[5] = ((add_len >> 16) & 0xff); - buf[6] = ((add_len >> 8) & 0xff); - buf[7] = (add_len & 0xff); + put_unaligned_be32(add_len, &buf[4]); transport_kunmap_data_sg(cmd); diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 3e4abb13f8ea..e0be4aa38328 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -168,7 +168,7 @@ static void pscsi_tape_read_blocksize(struct se_device *dev, /* * If MODE_SENSE still returns zero, set the default value to 1024. */ - sdev->sector_size = (buf[9] << 16) | (buf[10] << 8) | (buf[11]); + sdev->sector_size = get_unaligned_be24(&buf[9]); out_free: if (!sdev->sector_size) sdev->sector_size = 1024; @@ -209,8 +209,7 @@ pscsi_get_inquiry_vpd_serial(struct scsi_device *sdev, struct t10_wwn *wwn) cdb[0] = INQUIRY; cdb[1] = 0x01; /* Query VPD */ cdb[2] = 0x80; /* Unit Serial Number */ - cdb[3] = (INQUIRY_VPD_SERIAL_LEN >> 8) & 0xff; - cdb[4] = (INQUIRY_VPD_SERIAL_LEN & 0xff); + put_unaligned_be16(INQUIRY_VPD_SERIAL_LEN, &cdb[3]); ret = scsi_execute_req(sdev, cdb, DMA_FROM_DEVICE, buf, INQUIRY_VPD_SERIAL_LEN, NULL, HZ, 1, NULL); @@ -245,8 +244,7 @@ pscsi_get_inquiry_vpd_device_ident(struct scsi_device *sdev, cdb[0] = INQUIRY; cdb[1] = 0x01; /* Query VPD */ cdb[2] = 0x83; /* Device Identifier */ - cdb[3] = (INQUIRY_VPD_DEVICE_IDENTIFIER_LEN >> 8) & 0xff; - cdb[4] = (INQUIRY_VPD_DEVICE_IDENTIFIER_LEN & 0xff); + put_unaligned_be16(INQUIRY_VPD_DEVICE_IDENTIFIER_LEN, &cdb[3]); ret = scsi_execute_req(sdev, cdb, DMA_FROM_DEVICE, buf, INQUIRY_VPD_DEVICE_IDENTIFIER_LEN, @@ -254,7 +252,7 @@ pscsi_get_inquiry_vpd_device_ident(struct scsi_device *sdev, if (ret) goto out; - page_len = (buf[2] << 8) | buf[3]; + page_len = get_unaligned_be16(&buf[2]); while (page_len > 0) { /* Grab a pointer to the Identification descriptor */ page_83 = &buf[off]; @@ -669,19 +667,17 @@ static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg, } if (cdb[0] == MODE_SELECT) - bdl = (buf[3]); + bdl = buf[3]; else - bdl = (buf[6] << 8) | (buf[7]); + bdl = get_unaligned_be16(&buf[6]); if (!bdl) goto after_mode_select; if (cdb[0] == MODE_SELECT) - blocksize = (buf[9] << 16) | (buf[10] << 8) | - (buf[11]); + blocksize = get_unaligned_be24(&buf[9]); else - blocksize = (buf[13] << 16) | (buf[14] << 8) | - (buf[15]); + blocksize = get_unaligned_be24(&buf[13]); sd->sector_size = blocksize; } diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index 6517ea2c3859..509be053e8e0 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -71,14 +71,8 @@ sbc_emulate_readcapacity(struct se_cmd *cmd) else blocks = (u32)blocks_long; - buf[0] = (blocks >> 24) & 0xff; - buf[1] = (blocks >> 16) & 0xff; - buf[2] = (blocks >> 8) & 0xff; - buf[3] = blocks & 0xff; - buf[4] = (dev->dev_attrib.block_size >> 24) & 0xff; - buf[5] = (dev->dev_attrib.block_size >> 16) & 0xff; - buf[6] = (dev->dev_attrib.block_size >> 8) & 0xff; - buf[7] = dev->dev_attrib.block_size & 0xff; + put_unaligned_be32(blocks, &buf[0]); + put_unaligned_be32(dev->dev_attrib.block_size, &buf[4]); rbuf = transport_kmap_data_sg(cmd); if (rbuf) { @@ -102,18 +96,8 @@ sbc_emulate_readcapacity_16(struct se_cmd *cmd) unsigned long long blocks = dev->transport->get_blocks(dev); memset(buf, 0, sizeof(buf)); - buf[0] = (blocks >> 56) & 0xff; - buf[1] = (blocks >> 48) & 0xff; - buf[2] = (blocks >> 40) & 0xff; - buf[3] = (blocks >> 32) & 0xff; - buf[4] = (blocks >> 24) & 0xff; - buf[5] = (blocks >> 16) & 0xff; - buf[6] = (blocks >> 8) & 0xff; - buf[7] = blocks & 0xff; - buf[8] = (dev->dev_attrib.block_size >> 24) & 0xff; - buf[9] = (dev->dev_attrib.block_size >> 16) & 0xff; - buf[10] = (dev->dev_attrib.block_size >> 8) & 0xff; - buf[11] = dev->dev_attrib.block_size & 0xff; + put_unaligned_be64(blocks, &buf[0]); + put_unaligned_be32(dev->dev_attrib.block_size, &buf[8]); /* * Set P_TYPE and PROT_EN bits for DIF support */ @@ -134,8 +118,8 @@ sbc_emulate_readcapacity_16(struct se_cmd *cmd) if (dev->transport->get_alignment_offset_lbas) { u16 lalba = dev->transport->get_alignment_offset_lbas(dev); - buf[14] = (lalba >> 8) & 0x3f; - buf[15] = lalba & 0xff; + + put_unaligned_be16(lalba, &buf[14]); } /* @@ -262,18 +246,17 @@ static inline u32 transport_get_sectors_6(unsigned char *cdb) static inline u32 transport_get_sectors_10(unsigned char *cdb) { - return (u32)(cdb[7] << 8) + cdb[8]; + return get_unaligned_be16(&cdb[7]); } static inline u32 transport_get_sectors_12(unsigned char *cdb) { - return (u32)(cdb[6] << 24) + (cdb[7] << 16) + (cdb[8] << 8) + cdb[9]; + return get_unaligned_be32(&cdb[6]); } static inline u32 transport_get_sectors_16(unsigned char *cdb) { - return (u32)(cdb[10] << 24) + (cdb[11] << 16) + - (cdb[12] << 8) + cdb[13]; + return get_unaligned_be32(&cdb[10]); } /* @@ -281,29 +264,23 @@ static inline u32 transport_get_sectors_16(unsigned char *cdb) */ static inline u32 transport_get_sectors_32(unsigned char *cdb) { - return (u32)(cdb[28] << 24) + (cdb[29] << 16) + - (cdb[30] << 8) + cdb[31]; + return get_unaligned_be32(&cdb[28]); } static inline u32 transport_lba_21(unsigned char *cdb) { - return ((cdb[1] & 0x1f) << 16) | (cdb[2] << 8) | cdb[3]; + return get_unaligned_be24(&cdb[1]) & 0x1fffff; } static inline u32 transport_lba_32(unsigned char *cdb) { - return (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + return get_unaligned_be32(&cdb[2]); } static inline unsigned long long transport_lba_64(unsigned char *cdb) { - unsigned int __v1, __v2; - - __v1 = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - __v2 = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; - - return ((unsigned long long)__v2) | (unsigned long long)__v1 << 32; + return get_unaligned_be64(&cdb[2]); } /* @@ -311,12 +288,7 @@ static inline unsigned long long transport_lba_64(unsigned char *cdb) */ static inline unsigned long long transport_lba_64_ext(unsigned char *cdb) { - unsigned int __v1, __v2; - - __v1 = (cdb[12] << 24) | (cdb[13] << 16) | (cdb[14] << 8) | cdb[15]; - __v2 = (cdb[16] << 24) | (cdb[17] << 16) | (cdb[18] << 8) | cdb[19]; - - return ((unsigned long long)__v2) | (unsigned long long)__v1 << 32; + return get_unaligned_be64(&cdb[12]); } static sense_reason_t @@ -1111,8 +1083,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) cmd->t_task_cdb[1] & 0x1f); return TCM_INVALID_CDB_FIELD; } - size = (cdb[10] << 24) | (cdb[11] << 16) | - (cdb[12] << 8) | cdb[13]; + size = get_unaligned_be32(&cdb[10]); break; case SYNCHRONIZE_CACHE: case SYNCHRONIZE_CACHE_16: diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 2a91ed3ef380..f59ac7671031 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -287,8 +287,8 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) /* Skip over Obsolete field in RTPI payload * in Table 472 */ off += 2; - buf[off++] = ((lun->lun_rtpi >> 8) & 0xff); - buf[off++] = (lun->lun_rtpi & 0xff); + put_unaligned_be16(lun->lun_rtpi, &buf[off]); + off += 2; len += 8; /* Header size + Designation descriptor */ /* * Target port group identifier, see spc4r17 @@ -316,8 +316,8 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) off++; /* Skip over Reserved */ buf[off++] = 4; /* DESIGNATOR LENGTH */ off += 2; /* Skip over Reserved Field */ - buf[off++] = ((tg_pt_gp_id >> 8) & 0xff); - buf[off++] = (tg_pt_gp_id & 0xff); + put_unaligned_be16(tg_pt_gp_id, &buf[off]); + off += 2; len += 8; /* Header size + Designation descriptor */ /* * Logical Unit Group identifier, see spc4r17 @@ -343,8 +343,8 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) off++; /* Skip over Reserved */ buf[off++] = 4; /* DESIGNATOR LENGTH */ off += 2; /* Skip over Reserved Field */ - buf[off++] = ((lu_gp_id >> 8) & 0xff); - buf[off++] = (lu_gp_id & 0xff); + put_unaligned_be16(lu_gp_id, &buf[off]); + off += 2; len += 8; /* Header size + Designation descriptor */ /* * SCSI name string designator, see spc4r17 @@ -431,8 +431,7 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) /* Header size + Designation descriptor */ len += (scsi_target_len + 4); } - buf[2] = ((len >> 8) & 0xff); - buf[3] = (len & 0xff); /* Page Length for VPD 0x83 */ + put_unaligned_be16(len, &buf[2]); /* Page Length for VPD 0x83 */ return 0; } EXPORT_SYMBOL(spc_emulate_evpd_83); @@ -1288,7 +1287,7 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) cmd->execute_cmd = spc_emulate_modeselect; break; case MODE_SELECT_10: - *size = (cdb[7] << 8) + cdb[8]; + *size = get_unaligned_be16(&cdb[7]); cmd->execute_cmd = spc_emulate_modeselect; break; case MODE_SENSE: @@ -1296,25 +1295,25 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) cmd->execute_cmd = spc_emulate_modesense; break; case MODE_SENSE_10: - *size = (cdb[7] << 8) + cdb[8]; + *size = get_unaligned_be16(&cdb[7]); cmd->execute_cmd = spc_emulate_modesense; break; case LOG_SELECT: case LOG_SENSE: - *size = (cdb[7] << 8) + cdb[8]; + *size = get_unaligned_be16(&cdb[7]); break; case PERSISTENT_RESERVE_IN: - *size = (cdb[7] << 8) + cdb[8]; + *size = get_unaligned_be16(&cdb[7]); cmd->execute_cmd = target_scsi3_emulate_pr_in; break; case PERSISTENT_RESERVE_OUT: - *size = (cdb[7] << 8) + cdb[8]; + *size = get_unaligned_be16(&cdb[7]); cmd->execute_cmd = target_scsi3_emulate_pr_out; break; case RELEASE: case RELEASE_10: if (cdb[0] == RELEASE_10) - *size = (cdb[7] << 8) | cdb[8]; + *size = get_unaligned_be16(&cdb[7]); else *size = cmd->data_length; @@ -1327,7 +1326,7 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) * Assume the passthrough or $FABRIC_MOD will tell us about it. */ if (cdb[0] == RESERVE_10) - *size = (cdb[7] << 8) | cdb[8]; + *size = get_unaligned_be16(&cdb[7]); else *size = cmd->data_length; @@ -1338,7 +1337,7 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) cmd->execute_cmd = spc_emulate_request_sense; break; case INQUIRY: - *size = (cdb[3] << 8) + cdb[4]; + *size = get_unaligned_be16(&cdb[3]); /* * Do implicit HEAD_OF_QUEUE processing for INQUIRY. @@ -1349,7 +1348,7 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) break; case SECURITY_PROTOCOL_IN: case SECURITY_PROTOCOL_OUT: - *size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; + *size = get_unaligned_be32(&cdb[6]); break; case EXTENDED_COPY: *size = get_unaligned_be32(&cdb[10]); @@ -1361,19 +1360,18 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) break; case READ_ATTRIBUTE: case WRITE_ATTRIBUTE: - *size = (cdb[10] << 24) | (cdb[11] << 16) | - (cdb[12] << 8) | cdb[13]; + *size = get_unaligned_be32(&cdb[10]); break; case RECEIVE_DIAGNOSTIC: case SEND_DIAGNOSTIC: - *size = (cdb[3] << 8) | cdb[4]; + *size = get_unaligned_be16(&cdb[3]); break; case WRITE_BUFFER: - *size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8]; + *size = get_unaligned_be24(&cdb[6]); break; case REPORT_LUNS: cmd->execute_cmd = spc_emulate_report_luns; - *size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; + *size = get_unaligned_be32(&cdb[6]); /* * Do implicit HEAD_OF_QUEUE processing for REPORT_LUNS * See spc4r17 section 5.3 diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index cac5a20a4de0..f12cf0c12531 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -311,9 +311,7 @@ static int target_xcopy_parse_segdesc_02(struct se_cmd *se_cmd, struct xcopy_op (unsigned long long)xop->dst_lba); if (dc != 0) { - xop->dbl = (desc[29] & 0xff) << 16; - xop->dbl |= (desc[30] & 0xff) << 8; - xop->dbl |= desc[31] & 0xff; + xop->dbl = get_unaligned_be24(&desc[29]); pr_debug("XCOPY seg desc 0x02: DC=1 w/ dbl: %u\n", xop->dbl); } diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h index e475531565fd..b76071161cdc 100644 --- a/include/target/target_core_backend.h +++ b/include/target/target_core_backend.h @@ -2,6 +2,7 @@ #define TARGET_CORE_BACKEND_H #include +#include #include #define TRANSPORT_FLAG_PASSTHROUGH 0x1 @@ -109,4 +110,11 @@ sector_t target_to_linux_sector(struct se_device *dev, sector_t lb); bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib, struct request_queue *q); + +/* Only use get_unaligned_be24() if reading p - 1 is allowed. */ +static inline uint32_t get_unaligned_be24(const uint8_t *const p) +{ + return get_unaligned_be32(p - 1) & 0xffffffU; +} + #endif /* TARGET_CORE_BACKEND_H */