From patchwork Tue May 22 14:18:20 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: 10418721 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 5944760224 for ; Tue, 22 May 2018 14:19:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48D2428C78 for ; Tue, 22 May 2018 14:19:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D63C28C7A; Tue, 22 May 2018 14:19:00 +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 C5B2C28C78 for ; Tue, 22 May 2018 14:18:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751516AbeEVOS7 (ORCPT ); Tue, 22 May 2018 10:18:59 -0400 Received: from mail-by2nam03on0073.outbound.protection.outlook.com ([104.47.42.73]:20271 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751294AbeEVOS4 (ORCPT ); Tue, 22 May 2018 10:18:56 -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:X-MS-Exchange-SenderADCheck; bh=q47t0EIsFcr0+dTG9/9yh8mJluztYgkQf/f5sejPQuE=; b=peL6EKJpsX8ujugA7IBxiKdGH6oBhfZYcvlJN+s/XU53DuTWO7dOt7YzY3K1QKy6b02K383Jefryl62RWis/vmfWXn92luwRqqhZGQ+iFrwgiJ6QLM9pAdmIK8SeoQX2tkvMWLTekewdg+QqgxSzISfYAQKu34SF8FvHLbj3oeA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=JManeyrol@invensense.com; Received: from frgnb-12nlpn2.invcorp.invensense.com (2a01:e35:87fd:c140:d9b1:749c:d974:2408) by DM5PR1201MB0187.namprd12.prod.outlook.com (2603:10b6:4:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Tue, 22 May 2018 14:18:53 +0000 From: Jean-Baptiste Maneyrol To: linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 3/5] iio: imu: inv_mpu6050: fix fifo count reading Date: Tue, 22 May 2018 16:18:20 +0200 Message-Id: <20180522141822.11598-3-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180522141822.11598-1-jmaneyrol@invensense.com> References: <20180522141822.11598-1-jmaneyrol@invensense.com> MIME-Version: 1.0 X-Originating-IP: [2a01:e35:87fd:c140:d9b1:749c:d974:2408] X-ClientProxiedBy: LNXP265CA0069.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::33) To DM5PR1201MB0187.namprd12.prod.outlook.com (2603:10b6:4:56::11) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DM5PR1201MB0187; X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0187; 3:Tuaod7n+oAvKAvvEglGJuDAWCvIJevje/2H+o24/VfPsRqfkzSjIbE0ptPkZ6unXq8WCU6Kl+wq/chG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ZFh7iYZyam/I6suOfmwwlZPo5fmlmvdXoc2ay0M/ym/WF+/BLbS16VXRXZjYHV+PaQnoCalI6AbEFmk7pzR7+tMjLxKEquIPYrVn4bRwWdwJLeTLyWoaO/DVpa9v9rn6YQfQYuz0GAOwhLIEKebEOXt6hARK82FfGJcWTR3H157jSIgCJ0nL5YKBJV0OJdWSuEia2Ca4UixwSEaWqQCGUNuxAYVJnivZgyAJCeRsnx8fydrVeZDPRH18UbistlYjwA/HC1kHSz9Z+tLiPvYanHKtc5; 4:+QJnuuuM++UW6QfoxXJjvPeYLm7FcYXG7Ue9MlyuvgqOFPrPmzcNBGfITC0rZ01MiEuLXnI7LNIb/arBQYY7lhbep4jk7Fi6TIWqq3ZyHx/J6IrC7spHyQTDKBXxJ4Y9d2CpxBg9kdMcXaeni7igkwnrqKFl0yTEgw453bT269C6n8s0P/0O4eFTgogEyv9jaTCUGtqdSWnz8kVv/HXX03XCM7pYDwM4U/GXqG5YUbwAh62qxbN5GwLLr9UNVkNnCCX0vzAP+IabBnkCKqvz/AuYKQF4g35SKMAy7ck+VRXwqSUBhb6SfwxqytdGkdK8 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)(93006095)(93001095)(10201501046)(3231254)(944501410)(52105095)(3002001)(149027)(150027)(6041310)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:DM5PR1201MB0187; BCL:0; PCL:0; RULEID:; SRVR:DM5PR1201MB0187; X-Forefront-PRVS: 0680FADD48 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(396003)(376002)(366004)(39850400004)(346002)(199004)(189003)(50226002)(8676002)(52396003)(81156014)(6116002)(5660300001)(107886003)(36756003)(316002)(80792005)(97736004)(7736002)(4326008)(52116002)(1076002)(8936002)(305945005)(81166006)(7696005)(6486002)(53936002)(51416003)(186003)(476003)(2616005)(59450400001)(50466002)(11346002)(48376002)(2361001)(16526019)(46003)(478600001)(106356001)(16586007)(386003)(68736007)(446003)(86362001)(2351001)(486006)(76176011)(6666003)(6916009)(72206003)(105586002)(2906002)(25786009)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR1201MB0187; H:frgnb-12nlpn2.invcorp.invensense.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: invensense.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR1201MB0187; 23:SdBdMVrnVZrK9lZOvJb+IzglD7qjVbGUDtDMUA7?= =?us-ascii?Q?mPFCOO6Qiovcg+roLix7UWiiHw0ZBBjyJTp5GNCZxbDCn9bANPKUDU+ZbPvQ?= =?us-ascii?Q?8SSN6TtbsgugKup2KPyc+DwbIhCDy6qShFtx9jjqwxIjprsl+uAoewg+1mD6?= =?us-ascii?Q?YJmfiZdTJTaRQRFpfjcZQWCe1W62S8jCgdraQ+FKl8pd3a3xug6WeR41PNfm?= =?us-ascii?Q?cJXe6BFGQRpN9visrmqpoyMINhs1qmXzmBXcJCNW98PHa8nAuS0J+WFegGSb?= =?us-ascii?Q?j6i6CBx1T1JUjMK9whBNAWvlKKccSWtKOjy/4/91XvNrGnYljwCX7FxVNpgC?= =?us-ascii?Q?oiLEumu0FxZpYjyIpQrPHhG89Tu+jSSw9ZKklCCpAMGq9fd+1+zWKgCOpeaI?= =?us-ascii?Q?wWAtnkC+gPWCnkYTa2jxAq/PdSe+GeCrku1L2j9/8A3CcZTsjBSkpKB6I3yr?= =?us-ascii?Q?ZYMGsokLwzSMCe9/lFggEp3O4bEWTwcj7xgAgXdKBvK+80RCpm+LBswUaeWF?= =?us-ascii?Q?hIgggok6t4sU0CVANYl+nNm8qoUQRnQDD042BSvUbND18ZiU5n+6rHYTjVu4?= =?us-ascii?Q?FSWGnPZuxdDaIFrpqjksmcYrjgujfgzds/UA0FCmMl4NnE582LKDrP9ZsN5P?= =?us-ascii?Q?xFxae10ajQ5vgju/9P8GxIfLSOaPE11gxcI+fD58XiQgvlR4jKamrYZB7chX?= =?us-ascii?Q?ZV7DDrGNrvzSJvsCqj55HFKJpltI5hb8QBMjU8El4Ikk0HZkSMMz/KoGCK96?= =?us-ascii?Q?5BOXJhvbUK0ZQwPyI5yNhY2h03sWqDjaxPmfLNZqxb0RAc30LI/kIc0ujV72?= =?us-ascii?Q?ArI34LqrNhthzycS9w7P2KMtaJgidxLen27KLuWNMnl3xBhK28sjp1+kwOzM?= =?us-ascii?Q?tUPGP7D3Q7aT9Er3phzyqCQyMOCVP2q1WBYDANgT5su/dBvk/49fMw/kbCLb?= =?us-ascii?Q?lvWvmVwoWZYCsMascKxo3+Pz+k3POolXTnswhLtrVHBNBVcBt3VakkV54I2k?= =?us-ascii?Q?IlrJczXCkrOMVPLyeRCUhSMmEJRyLp2ftefka99Agas2kQGMZP85wf7yFbns?= =?us-ascii?Q?XY1Gn4h6qiLWjtTRFZw1L+T1nuKWU93lMkZy3m2lQ0199UhHHpXK4t2/M5m6?= =?us-ascii?Q?yRYJEIrc7gOm5LQNWEZr8aANslHTN8pK/QAoHIJhARuIW5UgYW4l4I95KBnt?= =?us-ascii?Q?VpKYiI5E2vYP70IrIXZ9d/YVvj5P1twEDSU73cnG6vnLoRT6Gb+DnpgYOXKw?= =?us-ascii?Q?Eqmc0m6nIaWEkY/gaF3FqZjqjVL9ENLniohUp/bKZ?= X-Microsoft-Antispam-Message-Info: Z2uisePEXbuqGTGXC3Msqq5Pp4T15MQFziHwP9hFhOU7qAPOhTdWju7egC5ZW3d2JoieRRsYRlRt39seV0xJ0+t1a9mPSzQ8ghK71thj0PFoyhHAH+uCg2MIUdr4ANQrdIelVqD1vSrKpvJ+6WboSibGJ87sfz4iiqvXCFRd1j7nzzWFqLFNDFU80gjOKkLK X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0187; 6:bXRbD60rvBzHj1yOBH+PJ4/kGg8J+evL+wLKZNxKnwbf6qf29k8148qVUMSgHengVToKmcMWHFbGYYXlcaME3hGoXGHNPKAPtUaROL6Rb/9Po9yUEv95ueMyPtP3BuB6Q7huhCyauZ/RsKyiEHDieHH79GXh6fobfm6ZHASM4EMUSIpmXYinNo9fTyYcsWjpWwC9aAs7RbrF5yeL6qe8g3udRA7kfAKxQR72XkINgealOD+qusZEIJXie+hfzAH39hwcXD1jiEocur6nQfQf2d1Ihhq88ZytvcCmElwd1nCmqR/r7nuaMp6NFYa3MPQYVE22ip34oZyrZCCFhzJfOkOFGrF/lXGpCJfheFIMjJgEdJsf/PNi+Pjhj8MZRF34kwbgn9ONmqsOoVsxxFhcrADtGHc985vhmkAydXkklUG5coa0EzArcEI8Ne4/XnpYaDb/PoaGCT59zWre+vBpoA==; 5:OSok6yKjt12n9AEMcusM3APfShRBIkQkw2ztniaVwmTm7F0HM7HXgXLEfSANj+1mAxCDX5vMw1F79dWuA2gAHidoWR8Wwct5wIuU5FJKOJ/Q3GOUUS2sGhMjfdy5/sIPgnbBx3VsGpIHAFE7ZK2DLBSJbcd1v8kdFQp0XENi/tw=; 24:EDUMipxf44OKutaLiFBejzeuxZGYfpVvaQDKg/QfsFcEyul8J6bTjyN+fQFO5J96YuVbaiG8Zrm/d/fWuCeDBZXK8b6limzdATPXnEdS0Cw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0187; 7:rPpBi3K1UUPpFUfum1s5WI09/7IVAF3mJVnAHIsfANdVQQr6j0XEEVR4dPf5D78rjW2sjX9f4luLC59kMKfXKF+qyzojQOFCawmdwWupuf97DTFORTR/D3R+1GCFedTNO+Bc3d4eIN57Qs86c3o3eG+z6xPKdbDvj3OVl9/CuMaUoEh7fxrFYzJdCs5GQQVUkFhKVsp5VduR9Vu7LvkAZg/pj4UBBpuMwTWhUf27wcbHPNf9doW/yIcZV3d9a7oU; 20:DYdiKCtYfu0XnJ1T0xAmLPf3NzPqRbMkaH179cQuTK4fpJTWuAgMvQc3M/NWOUuRphm3lzwAp2WJK/fv+sxBu8bky+o8tPlwvQQLhMdp2MBFk75bgtv38qKHLxYr04ICMIJ7r+AmRvIJuqijZdIWo8O4W7WebwoEP3JWD3Bx9CY= X-MS-Office365-Filtering-Correlation-Id: 30c47aab-e9b6-40ff-5346-08d5bfeef31f X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2018 14:18:53.7800 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30c47aab-e9b6-40ff-5346-08d5bfeef31f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0187 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 --- 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 5436d181f2dc..7724888a4696 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);