Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3058908imm; Sun, 1 Jul 2018 11:16:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKsZFVZisOHS8o/w7Yh0Tvk3ZvH7XYNxnrNVbc76DNEm95eopDE1HwOW5ozKMkzkzYGAZPV X-Received: by 2002:a65:6491:: with SMTP id e17-v6mr19215468pgv.44.1530468992156; Sun, 01 Jul 2018 11:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468992; cv=none; d=google.com; s=arc-20160816; b=IdQkDM9/rmelmtM5UPCb4bHtB2Yp2XLhy859+66OYMYA4AeS6SGkOS8lcwow2XDk3X DF9g1PVBI2YWkh248px6LHAnzCM96LvqO0pPgVRXKh9BiRbHbdhOjzqLtEmCG5Psd2Bs flpTe4qcFxhz8H+KmDHCHWkC5jzudS1AUWU0TVrnmdQJHB36pragN1fO6KveUaSgH0K9 HYfHdnAFmLpb73u/w4rAqtzfRqa7RNcu8ORuuwf1MSM3ku2u9zE136E2vs3UXiDTyDv+ BO0Lh2p1oBmZzbN1io2CE4gdPFD8u6iT2DhFm4t4rM1rqRzB0Kf+3lWxKoTc7jNObTUN IWrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ubSiyBgby08boA/PBYKVWXwaX9mhZiLZySbxcIU9gmM=; b=iuuVdiiz5GNTypr4G3PmNb9XvRYhWvlFa9uPMcw7brjayYm4T4wWqHlZvkTugSPhHd u5Zow6kEtoZy3ibFMGpauOd3tgNTWz/irA7oaNIB+m5p54ZdBc2tJwp8vOGV/+21h+KD N3A8M3xmtmPzYGe86ANRJWwxkaukWXUNGFCV7HvaVqqhNQHbqWRe0tlQDPWjO+E/oDNO pt2AV/mHWT4gWZIGpddJ/00j+7qEHYZo7eZi3DkkcRtUELO/ytBC8BFybjFYt0T6bXfc 4fFQ4HmYxeWpjcRBfQ/hD9S7t0gGbPpkJnAVm9Z9FK+JeLqjRRFRROy0saTGzgGbUkIF wzWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d35-v6si15046786pla.116.2018.07.01.11.16.17; Sun, 01 Jul 2018 11:16:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965381AbeGAQ0t (ORCPT + 99 others); Sun, 1 Jul 2018 12:26:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33934 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933572AbeGAQ0i (ORCPT ); Sun, 1 Jul 2018 12:26:38 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 02347ACD; Sun, 1 Jul 2018 16:26:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Kelly , Stable@vger.kernel.org, Jonathan Cameron , Ben Hutchings Subject: [PATCH 4.9 055/101] iio:buffer: make length types match kfifo types Date: Sun, 1 Jul 2018 18:21:41 +0200 Message-Id: <20180701160759.341694677@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin Kelly commit c043ec1ca5baae63726aae32abbe003192bc6eec upstream. 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 Cc: Signed-off-by: Jonathan Cameron [bwh: Backported to 4.9: - Drop change to iio_dma_buffer_set_length() - Adjust filename, context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- drivers/iio/buffer/kfifo_buf.c | 4 ++-- include/linux/iio/buffer.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) --- a/drivers/iio/buffer/kfifo_buf.c +++ b/drivers/iio/buffer/kfifo_buf.c @@ -19,7 +19,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; @@ -71,7 +71,7 @@ static int iio_set_bytes_per_datum_kfifo 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) --- a/include/linux/iio/buffer.h +++ b/include/linux/iio/buffer.h @@ -61,7 +61,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); @@ -96,8 +96,8 @@ struct iio_buffer_access_funcs { * @watermark: [INTERN] number of datums to wait for poll/read. */ struct iio_buffer { - int length; - int bytes_per_datum; + unsigned int length; + size_t bytes_per_datum; struct attribute_group *scan_el_attrs; long *scan_mask; bool scan_timestamp;