From patchwork Mon Mar 26 21:27:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10308783 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 4322D60212 for ; Mon, 26 Mar 2018 21:29:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C177298BC for ; Mon, 26 Mar 2018 21:29:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30D09298BF; Mon, 26 Mar 2018 21:29:12 +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 84F84298BC for ; Mon, 26 Mar 2018 21:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751674AbeCZV3K (ORCPT ); Mon, 26 Mar 2018 17:29:10 -0400 Received: from mail-cys01nam02on0043.outbound.protection.outlook.com ([104.47.37.43]:27063 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750983AbeCZV3J (ORCPT ); Mon, 26 Mar 2018 17:29:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uievolution.onmicrosoft.com; s=selector1-xevo-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=GqE7NUomPdkM3tS/NP2faqJefmfkMKIZOM1U/06yppA=; b=1HcrJAyniPuQ7+qUZm6/Hbql42gOgFSJf6MVO7cxeD44rBM3ZtnFYbrnJV1mXA8obKaeR2prCRbkUskXw6raXVMXp0KS7YVaMuJacnLgdqko1kbeDvNIdS3XpIN7hlNG4HN5Is4GSn7RdZGTrvLNadXjGs2xlnUPh/09QEo6v4w= Received: from columbia.corp.xevo.com (65.122.179.226) by MW2PR0102MB3419.prod.exchangelabs.com (2603:10b6:302:3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.609.10; Mon, 26 Mar 2018 21:29:07 +0000 From: Martin Kelly To: linux-iio@vger.kernel.org Cc: Jonathan Cameron , Martin Kelly Subject: [PATCH 1/2] iio:buffer: make length types match kfifo types Date: Mon, 26 Mar 2018 14:27:51 -0700 Message-Id: <20180326212752.7321-1-mkelly@xevo.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [65.122.179.226] X-ClientProxiedBy: CY4PR21CA0026.namprd21.prod.outlook.com (2603:10b6:903:12b::12) To MW2PR0102MB3419.prod.exchangelabs.com (2603:10b6:302:3::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f4fb8336-2f2d-4617-da10-08d593609b73 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MW2PR0102MB3419; X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3419; 3:JVnfyHttQ2Vnqv6Zpa6YIh7CAbqT4hhmz2kAAnFcvjVIscj7aAOmu+BFGcdRuQjuYzVO8iQfN/DhsMgXYQQ9keqGZZETpyScycmCeYe+gBZZMkYuDqgxPr6IqXnG8sH4iYZ8+rGBU1N2DloZCiK+1/Ze4HsEPWEaNaAfbOnE+0JojtZbHiZxqaYxM0ySZcouf42ckmxlv8pT7/v8v6vlqaaG/oQHF18C9hiIY/89fORbMY4MmtVTfibLWT2so9c4; 25:zreWbBILs3iHmTHWkyO3X860WTfXcF3kxjxHFxFj6KQlUC7H8TRlApAGeXRYFPKHfcimNNL5BhsIzGfqBS5KILlykEOdtnrRtabNSodbHaQMP8I8l/nRb0BLg5eEMy49CUqlJotFj1Js1oZ/hoMuzJgfdad9poylZwZF333twAr1snVcGIRrGHICdJhYh+1MaKqzAz5gDGGXBxP+87tQGdK797LW08hQLiec68e+sOWpo2GJWHM8HAfMORZh28zY+6AGvNKhczdujDxT5KlEWq+LZ3HYtj6ybFvg3PKBShvFtOBt9cEi1NnANDwTbP2/2KXVnwc+j+ojPcDZ4Lj4aw==; 31:2Ol6Y+2sL5mIBjDATec1mOmo9N7CcwkOQuSGF3YegK2ipRYikBj97297+t0nnn8PMp9ixqsVgBHU/ZNE58TWesFS4gODDwSMHdt+mndoXaR0AxEfdtojsnAF8gpzxHx65clx1FjYlTpDmYUluqINvd+KddUYl2aU/jwP7iEpdfvkihogaEkANQ/9utYRwV730pNJnKuUb0V29NzSLBBy1a7MGvq6dSbFY3JIbYipkPM= X-MS-TrafficTypeDiagnostic: MW2PR0102MB3419: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=mkelly@xevo.com; X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3419; 20:FstmLOHsftM/uKf7bsM1BorbKjYP/ZGzCHnr0ipabTDcO/F1L4vzh49QB2/bd/d2EQOWXG6S4nmKN6z4oHbWSoz4X1WJoBAZAtIHf+3JHcfZ4vuel16Q01RAJ3LwW8+/WVXhGGm9Z7gAa/W6hzBUK/rLwXoOLUh+7mwfdWrki1JKkekmD9hQA3qmJr+v20BMV2zvW5iKhqet7GTTlnBlI6uHV6dy5OOQoKa9h9D4ApcITsNp15ihp8scrfqsqoiM3UsLvb0QyxSr0pMONZgCpzmOIALM8Yzz6Rbvro8E+1xLE2sOLoedV+qoZf7p1w5Jk2u+5QKZ1H4NTxZoORI+U+9Uvbax4fFmrJtc8OUzvcRx7PAeXusuA4jE5xzLhiJXqVI8GWPO+Ywy50MeDol5VpQbXEsCsLv4w18DKfzUpRH632uo6pi8reLNAaz2blJ/exWzcrrlOPM7f2u4eKsT+VZYEPS9B39v8JlbJqHTgAqMn/UVoIL0MQ7xFjyyhdFR; 4:w/7bRm6TObKla0uaazEG72Ug4bO+an6Heh/C68fNjTmDBj4wMRZQEnx6n1Xwmht0q+OfFG+BVbtpqel90FXh1S8KwnThc8TTeWQ7L1tFsbaCJMwbBv90H5pXa9iC3ogXo6xxFe8lu5ONnY1mP6w03R7l8Hlzf0LOM7vCd5fTRkaa+vvcBfpQJu3g2ag3LRG/xneqfybMJKDBVhZPEhjzS3/gkSm0+/MdLCDIXck3MCEnQO3nvLf43VRE+fuyINu6r9cKnzfh+keJht8Lw1X2JA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6041310)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:MW2PR0102MB3419; BCL:0; PCL:0; RULEID:; SRVR:MW2PR0102MB3419; X-Forefront-PRVS: 06237E4555 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39840400004)(396003)(39380400002)(366004)(346002)(376002)(189003)(199004)(16526019)(54906003)(6486002)(186003)(956004)(7696005)(2616005)(53936002)(36756003)(476003)(486005)(486005)(5660300001)(305945005)(68736007)(52116002)(51416003)(7736002)(8936002)(107886003)(59450400001)(81166006)(81156014)(50226002)(2351001)(2361001)(97736004)(1076002)(478600001)(86362001)(16586007)(8676002)(2906002)(575784001)(6916009)(316002)(4326008)(105586002)(48376002)(25786009)(66066001)(26005)(50466002)(6666003)(386003)(106356001)(47776003)(6116002)(3846002); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR0102MB3419; H:columbia.corp.xevo.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: xevo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MW2PR0102MB3419; 23:eb8o4W3KxB9/1PBvlPRrWBZfWS/PhWb5Pg2S///?= =?us-ascii?Q?atplkRXwPgvbtsGcqU0mzH6UJJwsZP3JcBU451bAWg5bGa1tb+dOQDNcVWN6?= =?us-ascii?Q?Y4P5TuRDEsmwUshlmMU8lFD1VHHq45JyK9kAtFfR9Sawsh+R2cnsnGjfgDmn?= =?us-ascii?Q?Y9BuPA/wnBC6uP1jbCp9ACK1ihYSM/W82VSBJWbo8pqI/9tvK3W9+wURdhV0?= =?us-ascii?Q?GEWk9zuF8xzfMbPsjZ1vBHoojDsXTVRScbC1H7Yz3yAmK9txRFgSVsFu5Wld?= =?us-ascii?Q?JymkzG/62wNouhkBRJHibfkNiIgolxCtceqlR8xwYWg63DOuVytUMDHcrcdx?= =?us-ascii?Q?hDGu7OjIHWBvcKgIGQr8QMYLwIKqz1v/1iECE0ZRQUhtM1y1vVZOkXNgGnNf?= =?us-ascii?Q?44tokMx+yGve0nCo9fszW6Vrh5Un7TXa3n+98KVoeNZnkBsfEoepult0NSvt?= =?us-ascii?Q?tGHKuPzZUlo+ZsrHAkCRpUH0RtTPbEIW+t1Zz9U1i4wQeCRIU5ryIX6H9Jfm?= =?us-ascii?Q?nXFhiO/fzp4QK+Na5MkS3y6gmDKK231avzMZfMZ39huScbRF2RLu64H+GwDP?= =?us-ascii?Q?nGGhRoJUGRa9YdySCFXySMkg0qQuUhN46gRHSc0UtVuc76C7E7x3I+1XTuiw?= =?us-ascii?Q?K2swNpWx47dY2Kl8t6+a+T1UZ+bw4zokUkfMAMM9/x2jfj2OsnEI0ZyYRagW?= =?us-ascii?Q?dXpJnCJi/Co6BqJ1pEiJxjNVek8JLTKsXOAr22exlp5Jzs7M+JKr/+BBlXrA?= =?us-ascii?Q?jToUSJmssZxkmDadikU6EfAUI0ZazDClPuS2h60FdLlhsTlf0MXX6IJtKno4?= =?us-ascii?Q?zjwkCcQx+XMOXswrag1tgasxPYHfcqHJUvmzm9J7jwZPvnsPVD0XwTs1XUEZ?= =?us-ascii?Q?7cL+orfTXtHP+0cEOPu+/iD977o422BFObXAIBQxwq10ftybY2acZsuMpKip?= =?us-ascii?Q?SO7vd87hi5bqT1taSDNumsVov5YZS2i1hN3g926l1vm6dWazTndVDAMm7zJf?= =?us-ascii?Q?U9D6L3SH3ReARd6prVrxR/pU3TE/d8uTh1H4EAjHFwxKSchLtciGbu+u+yFQ?= =?us-ascii?Q?hl3UZ66AVq06SrGwM1ZmO4QiF6maBYW9RpWFCm5OZMmSD7FDboD/W0zeMveO?= =?us-ascii?Q?MMZcJ+YjEN9Y1N9H887wBocL/H4tKQMvIgam+UrLOZHjSOgFJFqusASzn4aq?= =?us-ascii?Q?AyQKgMwwtdEwdGPc7GFIin/u0KbhOf1yRuiVDhhLf+rjMp21gqrrW8cbJ+Yh?= =?us-ascii?Q?CyPWo5Vv5VZAf66k5ZY9b9kEo1/xMz4sDK2i1fKra?= X-Microsoft-Antispam-Message-Info: ep3M/9n0sp8fEPp/Hhxu6im4BoJ9m8TyKRVPveoRpbqEOhgY5Byjv8dKD3NBHN8g8IVywtYxSGBrFq14RITT5NRblJbLzxI4hQ/5/RsP+4fzHlQlKDeClDi3TiA+xKsUmBHc9zIhqC2FSZhdzexQ+ZjrSo8tvKOdTwxEEwkgavE/YwvmOjt460m+wy8PSanY X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3419; 6:rAy59NVm6mRnL8pizS7LLTCtJeZec4DY+RBTSFXOxjpTt5odN/Q7eHzkuEV9BmM+cv1zOk+EbwUvifhSvpt6yvwOQM2bDOZVtvIoqUVjPnN1rUD8BamtkknqGXFHxqGrpBVfSvtSecMOoJTKaU0sx0E0+O1PajNUyO70xKBAaoj7q5lDW3jaaf6qkeMt1bR4MMy3ycaHpG/IPlm7mLsstIsmsK7xu/KkGfQf00TESaY8g1Ib2SSJybZwcjblEEuI2WO+QwhSohr9GJ+DvSlGaMKwQFk6JPxcE07ynzknMSuqlYUwVI9JkXjgh0dkH/oIg3kX5XCbfBWlo85h8RBoQ3mQHEdI5A5pws1Hv8F8h94KINUBxfA7/Z3nazzCWyFyHqCmm9VNrXGMgLdlPFxju0xPNaFv32PATssUChEoQ/im9NrqMJxbzWG/H+OyoZYj3mNOg5eBJ12B+rV4RqkZ4g==; 5:lz6WewrUbKb3ELXgpSTuNCxcOmeR8Z8ruM9GdnHSAsxrh4U32ldsSSL9BmNg1X/bKs+G1DHmBdtqwaud9H0lPy9mr+l7fNMiFCxWE/3R2zHeilxzFEEJlOv4Iszz70w+6KrsZcgL4mMDTb7x2OCKRrtq6HyH1Kg+u1CHP5V/QZk=; 24:e6jlZFCD5eqUvC90Y1VLsPHFjb4cP3zBpNuj/LRVUCEqAy+fjdu7jMpb9jJC9F7g3bywyh7DPciHKB07nAr62NrfZU5caO+d3y7FwTFaz3Y= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3419; 7:nTQCXPpwAQwYFb9f0Q8DZ+lq1NRqdKhogjPg6O+leoTyRPtvCvu+Yf7ECRwimjly3t2d/+hmtujRlHfzoZELar/IxgMkV8jl22bJqW+EwiUlSeuSbQdb+jQLSESba5T7VXJ2tADfgNSFbVoWnOMCZ62OmQe0cIZJFCDAzmzzclPl8moURy+SUXVraWrbC+ONbpFAqRtZr1CVlBraiSMlpL0apm8H4bq1kOTpdHpUuWFltaJa7T4FyJsFPLILvrUH X-OriginatorOrg: xevo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2018 21:29:07.4497 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f4fb8336-2f2d-4617-da10-08d593609b73 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e0a7ca1f-2458-4cd6-a7c7-d733c07495ab X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR0102MB3419 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 Currently, we use int for buffer length and bytes_per_datum. However, kfifo uses unsigned int for length and size_t for element size. We need to make sure these matches or we will have bugs related to overflow (in the range between INT_MAX and UINT_MAX for length, for example). In addition, set_bytes_per_datum uses size_t while bytes_per_datum is an int, which would cause bugs for large values of bytes_per_datum. Change buffer length to use unsigned int and bytes_per_datum to use size_t. Signed-off-by: Martin Kelly --- drivers/iio/buffer/industrialio-buffer-dma.c | 2 +- drivers/iio/buffer/kfifo_buf.c | 4 ++-- include/linux/iio/buffer_impl.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c index 05e0c353e089..b32bf57910ca 100644 --- a/drivers/iio/buffer/industrialio-buffer-dma.c +++ b/drivers/iio/buffer/industrialio-buffer-dma.c @@ -587,7 +587,7 @@ EXPORT_SYMBOL_GPL(iio_dma_buffer_set_bytes_per_datum); * Should be used as the set_length callback for iio_buffer_access_ops * struct for DMA buffers. */ -int iio_dma_buffer_set_length(struct iio_buffer *buffer, int length) +int iio_dma_buffer_set_length(struct iio_buffer *buffer, unsigned int length) { /* Avoid an invalid state */ if (length < 2) diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c index 047fe757ab97..ac622edf2486 100644 --- a/drivers/iio/buffer/kfifo_buf.c +++ b/drivers/iio/buffer/kfifo_buf.c @@ -22,7 +22,7 @@ struct iio_kfifo { #define iio_to_kfifo(r) container_of(r, struct iio_kfifo, buffer) static inline int __iio_allocate_kfifo(struct iio_kfifo *buf, - int bytes_per_datum, int length) + size_t bytes_per_datum, unsigned int length) { if ((length == 0) || (bytes_per_datum == 0)) return -EINVAL; @@ -67,7 +67,7 @@ static int iio_set_bytes_per_datum_kfifo(struct iio_buffer *r, size_t bpd) return 0; } -static int iio_set_length_kfifo(struct iio_buffer *r, int length) +static int iio_set_length_kfifo(struct iio_buffer *r, unsigned int length) { /* Avoid an invalid state */ if (length < 2) diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h index b9e22b7e2f28..d1171db23742 100644 --- a/include/linux/iio/buffer_impl.h +++ b/include/linux/iio/buffer_impl.h @@ -53,7 +53,7 @@ struct iio_buffer_access_funcs { int (*request_update)(struct iio_buffer *buffer); int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); - int (*set_length)(struct iio_buffer *buffer, int length); + int (*set_length)(struct iio_buffer *buffer, unsigned int length); int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); @@ -72,10 +72,10 @@ struct iio_buffer_access_funcs { */ struct iio_buffer { /** @length: Number of datums in buffer. */ - int length; + unsigned int length; /** @bytes_per_datum: Size of individual datum including timestamp. */ - int bytes_per_datum; + size_t bytes_per_datum; /** * @access: Buffer access functions associated with the