From patchwork Mon May 14 21:05:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 10399235 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 4091E601F9 for ; Mon, 14 May 2018 21:06:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCD9B28518 for ; Mon, 14 May 2018 21:06:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1B5E28521; Mon, 14 May 2018 21:06:32 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 3C4DD28518 for ; Mon, 14 May 2018 21:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752206AbeENVGa (ORCPT ); Mon, 14 May 2018 17:06:30 -0400 Received: from mail-cys01nam02on0069.outbound.protection.outlook.com ([104.47.37.69]:21440 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752136AbeENVG1 (ORCPT ); Mon, 14 May 2018 17:06:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8aYPzEfKLjavM3djFU+ZVmUWeDXa6ZXKTTSXpoWB7nE=; b=SgGdEFWTKJGbkCUFCuWN0mczmNkQzOUy9UmyjgRc+0bPiSnUiEpg4zA5V0XIhKEsj2HSWnc1PYovZvjIEdapqJyzA43yj2cmblLUA60WnygiVK7dupJuIPIYZtLRiQWQb7CA6wP99bIIhL0t4kKJEUaTG5/rdTflCVxZVqpt2YE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=JManeyrol@invensense.com; Received: from frgnb-l-34296kv.invcorp.invensense.com (2a01:e35:87fd:c140:998d:db6c:4387:dfad) by MWHPR1201MB0191.namprd12.prod.outlook.com (2603:10b6:301:56::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Mon, 14 May 2018 21:06:25 +0000 From: Jean-Baptiste Maneyrol To: linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH 3/5] iio: imu: inv_mpu6050: fix fifo count reading Date: Mon, 14 May 2018 23:05:53 +0200 Message-Id: <1526331955-11869-3-git-send-email-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526331955-11869-1-git-send-email-jmaneyrol@invensense.com> References: <1526331955-11869-1-git-send-email-jmaneyrol@invensense.com> MIME-Version: 1.0 X-Originating-IP: [2a01:e35:87fd:c140:998d:db6c:4387:dfad] X-ClientProxiedBy: LO2P265CA0024.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:62::36) To MWHPR1201MB0191.namprd12.prod.outlook.com (2603:10b6:301:56::13) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MWHPR1201MB0191; X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0191; 3:iaAhkIvKsXrVlwJmWTkj2NMNvsLYO+n37BpDoWfSvxgP4u4YAmu3TQ2zg0y9lBPH1LJ75THzGUK/C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BpgvAhj9iwa8QSnb3JhTBJfc9dCMpAQUsi0J3uLPHI2uHJrKriKUOWJv7ZphLGSSmDiaiLYqf1+dIt+NOC4VO3Np9+BykUL3C058pyAESOl/O37ZtFRrmqKj3gaBa4JM/SoixYMTOFzCT7nQqe7sNLG2nyWtg8h92XL2F4yVfTbh8QZnEXd9IDJHCjX2mErweQg9L2YK2wbxFSE5X1xAF4n4YrfIMvoF+0CrOAjKBJT4E3HEx8A3eW0XIkreh9WMFqGP9n; 4:NBaoAOrFJkP2GAi6vrxfX1vPSingjENoJXtisXVJxuY9Ms4FsHwD8WsItSPKsxqCAQEXcwl0+pUGkOOgErG1ZRze9EdSvRA5wMPz8lldenZ/4C7a0IrcJUCLEAkqEedzrZbqHRfTkt4l9iIbxLBhhCQNqbBEQWq7+M9LQe60LWlxJSooW8rQzrJG1cUx9g1UxiWVOULefhfxBcKtkyQN6hfyHzmuZtxKSBCMOTGcpX4n171d5dVAz1IZbe3uUAlFWb5Ze3DWB89fC3jZSC86vmWtcP8tMvaZJOm9DeawZJwehW/sLwd2PqPgJKhIJ34a X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(257004950022427); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:MWHPR1201MB0191; BCL:0; PCL:0; RULEID:; SRVR:MWHPR1201MB0191; X-Forefront-PRVS: 067270ECAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(366004)(39380400002)(376002)(39850400004)(346002)(189003)(199004)(81156014)(186003)(7736002)(59450400001)(6666003)(4326008)(386003)(76176011)(48376002)(52396003)(50466002)(25786009)(80792005)(8936002)(68736007)(47776003)(6916009)(107886003)(8676002)(16526019)(36756003)(2906002)(53936002)(50226002)(6116002)(478600001)(305945005)(86362001)(72206003)(2351001)(46003)(6486002)(5660300001)(316002)(486006)(7696005)(52116002)(81166006)(11346002)(51416003)(97736004)(476003)(105586002)(106356001)(446003)(2361001)(16586007)(2616005); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0191; H:frgnb-l-34296kv.invcorp.invensense.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: invensense.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR1201MB0191; 23:wq+IsgdJUzp4MDjuU9DbLODrJHuUXL2PRcR54D7?= =?us-ascii?Q?bNFKYtI8dcd7Ik8Emd5T0FrN9G0Le99gElGGbivW8TWOM3NriCBHHYIl+t1k?= =?us-ascii?Q?Q6rebYwpRxChKGsF3R89kAmUxAW4HOCXDzSU3KaNSBYJRVPih5+RMzDjw9Rb?= =?us-ascii?Q?66zS9XN1a1dDNzGMjjOgQ8lI8XsPIXgfFangzX5QP1SfMkkFpdvppI9KrTy9?= =?us-ascii?Q?0VhWRLSSQGPnaQJPdwM+Iek/m79y0v8YHleNrot9gS2y9GcF0SNx3QDXimQL?= =?us-ascii?Q?b/ZjTKodDmHQtMFzD+qsdRTg2vidK59DA/9nx5qekhAqw0tsdidkn5nGfKvS?= =?us-ascii?Q?LOG4uLeEi5mmCEATFltLhvtBrpXz2HLWgX6hyNEFhAXiAQDeo8PzVythH6Qt?= =?us-ascii?Q?08VXDUgxv4SapAeFQ4GvP+T+WVwT3qqu+vJzR1nX4Q7ftctcMyRZadPUkcj+?= =?us-ascii?Q?p9hmGU1EaCNyXsh1LuxVBsOjnEaRrSUDORJHpXHHWoF792s3FLRsMXkPPEwa?= =?us-ascii?Q?YjGPMX2BPzY+SRrbPQVhi8fl2Dh3Xx2zq8SGAW6AeccSYB5dKWY/9blogEp+?= =?us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exchange-Diagnostics: 1; MWHPR1201MB0191; 6:WZcCnzJ6qE6agemkRHL+mSWsO7qqdx9Fbpi2Co12FAWtyJhbgiWzXoZKcvelZ1LL8o2DOQLwFJH7VM/HveqqOJJG1n1xxEacZoTVCAqEpJ+NuTM6UVON4wHecATrBrEOuvuA21Tot/gcbehVvk+DidDG07HJUFCiKxJt/bEt/xa/h4w52i0zGJrw0Xb5g87N75vT8Z1NfX6TZ/U322TRpQIrC5QWJca66uOHiokfoiIXhL9WbJ3Swaka7902vmrAnISA7MguHa86fxd7oeMEB+EMGIX/XE5oq669dG5TpW5asaXD6kgtjIiUQN6Wt6usXly52lVqFTNwhpOLJw+I4W98igv/+/HQgkc0kgU7Hg+AT2z8gmOsj0tauuPHjNrghiQG2p+l3jYHNzoPDWWv8YbcLq98UkJ4D9nTRefvW27pINuGc4EgNbcEcK5EkR+oDQZ3mNzuwFRjWHig+lvx8Q==; 5:FwhyFUNSKjuQcLcGkaa/5toF78voFpDC4VW9NpShtJ0GjjViuMz7T4wVzhHxZoBUXNA/1A0MrPUxkEGW/I3Oy+qzK18bDO9pqqHi+4t44j8groNZVLMVVyUdCmyB/UoBcu2ibfomue7YJKxEWHVMq/KIYP3Wty8ZlP7Z1zLI4Yc=; 24:D7nSOmkCHXdUNYFaPZFwihAoygpTeP2OPvmLtG1GCJznKvFmihAkmk5RAcGim0IE0/bLZmB9FGGaj3W9J+ji2muVe2lOpqt4EUmasM2VdlQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0191; 7:zuZLpObq7BR8surrRHh652OnwLQP95XjyKC8g0iS+/qOfCdsl5aS48b+MPTJuYDFvNw0pyJFzSy7ghZfpfPrHFDWZwaVrgFrcbtMETHJqfnSwpqWNrQVK/2yzm0bWpxpTDDd0JcrVNH8RH7qmcjLrln9t+pu+3SQg2os2QLtYdAZWJOzh1mC6HK/rEwO01yNiF0P1a6SslgF2zcGhgwG39cBKQ4zdhDIC5YowlZUU4fvmFIxTZaJzlrvL6S4zPnw X-MS-Office365-Filtering-Correlation-Id: 52ee5ffe-5161-4f9e-a0d2-08d5b9de8e07 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2018 21:06:25.1879 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 52ee5ffe-5161-4f9e-a0d2-08d5b9de8e07 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0191 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use unaligned access since buffer is a bytes table. Truncate fifo count to read only complete datum. Signed-off-by: Jean-Baptiste Maneyrol Reviewed-by: Martin Kelly --- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index 5436d18..7724888 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "inv_mpu_iio.h" int inv_reset_fifo(struct iio_dev *indio_dev) @@ -98,6 +99,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) u16 fifo_count; s64 timestamp = pf->timestamp; int int_status; + size_t i, nb; mutex_lock(&st->lock); @@ -132,27 +134,23 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) INV_MPU6050_FIFO_COUNT_BYTE); if (result) goto end_session; - fifo_count = be16_to_cpup((__be16 *)(&data[0])); - if (fifo_count < bytes_per_datum) - goto end_session; - /* fifo count can't be an odd number. If it is odd, reset the FIFO. */ - if (fifo_count & 1) - goto flush_fifo; + fifo_count = get_unaligned_be16(&data[0]); if (fifo_count > INV_MPU6050_FIFO_THRESHOLD) goto flush_fifo; - do { + /* compute and process all complete datum */ + nb = fifo_count / bytes_per_datum; + for (i = 0; i < nb; ++i) { result = regmap_bulk_read(st->map, st->reg->fifo_r_w, data, bytes_per_datum); if (result) goto flush_fifo; /* skip first samples if needed */ - if (st->skip_samples) + if (st->skip_samples) { st->skip_samples--; - else - iio_push_to_buffers_with_timestamp(indio_dev, data, - timestamp); - fifo_count -= bytes_per_datum; - } while (fifo_count >= bytes_per_datum); + continue; + } + iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp); + } end_session: mutex_unlock(&st->lock);