Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4641934ybl; Wed, 22 Jan 2020 01:53:02 -0800 (PST) X-Google-Smtp-Source: APXvYqw9kEyb0lGbGH4kz0b9rWxOHuMI3PZkhVGR+kvXmhvK+jluakSY7bxh6j05m7GvkkddLfsp X-Received: by 2002:a05:6830:9a:: with SMTP id a26mr6914929oto.131.1579686782727; Wed, 22 Jan 2020 01:53:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579686782; cv=none; d=google.com; s=arc-20160816; b=H5jUXn6O4VQxue40jHC6ooJ4bW1lCtHdsyN20vFzODhaokthHb280UeORQ/b1NePbp yHJCldCMhH79//lSm2scBzGUqEaxLE+PR0o/yCty83d6Womi47D2oOqPofvY1Oqqzae1 +EAe+SLUtVBOmX+RtmqpTaqUYSJye3x+fSullb1vZm+Q4ukD3UJfhaR5RUf8IYerklYT UTw/FXUm/GEKVUkIzdnsGzNaFjHuv07WOC6/O8u/b5k5CBimq4YPM8t4A9xvldyGiSl1 JLCrXPX0WpWUhRNdhlT4AE88yD/UgTQPDAbDcW+xGQ4z9CA6KVtT7PSsX/2CKCbreQYt f7Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Zm/U8rfpCiOPjot2SMjyOONS2IScN23P+MCNbfOHMyE=; b=F+fNqAMw/YwVdB/aIxEtAitExTKfjlghq2lzza7tF/+oes0X3B3pvadMu/BsYzYSGg 5EDsD00Bh90GOpBgXaj/MSCiI3eM8o36GOGiqzSPje3zbgK9wx0EeW+TAbTKpwjYXldM zFON10fMbjgFSLYHhGFxGW5Hc+FZzn119OnqxJnq7m4QvcBNaTTCah/8O3b/TcXCS5q5 r2aHLTN4KmHE3DoO3xDMQxB4D/WFGnlfvaf3+lSYAF18OyOSFbjMdebF9fjMd7GJiQjA Te/Qnm6wCH9b9oQOHFrDsxK2U+dkcQb8Byb4TmTO0KrmGkMMnGfe6M/yFaG6qIHeR7wy 5nsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CaHBeMvy; 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 i3si11611444otc.272.2020.01.22.01.52.51; Wed, 22 Jan 2020 01:53:02 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=CaHBeMvy; 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 S1730969AbgAVJhC (ORCPT + 99 others); Wed, 22 Jan 2020 04:37:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:52778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732274AbgAVJg7 (ORCPT ); Wed, 22 Jan 2020 04:36:59 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 80A3924687; Wed, 22 Jan 2020 09:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685819; bh=0oVE52zL6GJ9e+7w58+ti/f/AmU2UEGHs4+W8Fw55n0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CaHBeMvyrEkN65/lC4fcZKDZ6UkLcOy8dRTKRumsuCLqqV/XU33K67gDE1zzV2FuQ De3v2FpQj/CS/K0zx4Zk9Kba2lYuA9ZRCBj76twTY8n3gbmgiyYFSfspSaVBWAcZ7l E3Ul/SSFEnAjEovlqFdRQ2GhxAmcOAkQDBzvjJNo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Lars=20M=C3=B6llendorf?= , Lars-Peter Clausen , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.9 56/97] iio: buffer: align the size of scan bytes to size of the largest element Date: Wed, 22 Jan 2020 10:29:00 +0100 Message-Id: <20200122092805.443292933@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092755.678349497@linuxfoundation.org> References: <20200122092755.678349497@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lars Möllendorf commit 883f616530692d81cb70f8a32d85c0d2afc05f69 upstream. Previous versions of `iio_compute_scan_bytes` only aligned each element to its own length (i.e. its own natural alignment). Because multiple consecutive sets of scan elements are buffered this does not work in case the computed scan bytes do not align with the natural alignment of the first scan element in the set. This commit fixes this by aligning the scan bytes to the natural alignment of the largest scan element in the set. Fixes: 959d2952d124 ("staging:iio: make iio_sw_buffer_preenable much more general.") Signed-off-by: Lars Möllendorf Reviewed-by: Lars-Peter Clausen Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/industrialio-buffer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -546,7 +546,7 @@ static int iio_compute_scan_bytes(struct const unsigned long *mask, bool timestamp) { unsigned bytes = 0; - int length, i; + int length, i, largest = 0; /* How much space will the demuxed element take? */ for_each_set_bit(i, mask, @@ -554,13 +554,17 @@ static int iio_compute_scan_bytes(struct length = iio_storage_bytes_for_si(indio_dev, i); bytes = ALIGN(bytes, length); bytes += length; + largest = max(largest, length); } if (timestamp) { length = iio_storage_bytes_for_timestamp(indio_dev); bytes = ALIGN(bytes, length); bytes += length; + largest = max(largest, length); } + + bytes = ALIGN(bytes, largest); return bytes; }