Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4819120ybl; Wed, 22 Jan 2020 05:21:28 -0800 (PST) X-Google-Smtp-Source: APXvYqyGHkJsVjFeXxCuzgcO2ia0nVm1NPiv3ekxDz4sfqFGPmuYTUDAxlAgNn/hUX4Pj2W64P1f X-Received: by 2002:a05:6808:a9c:: with SMTP id q28mr6831778oij.176.1579699288654; Wed, 22 Jan 2020 05:21:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699288; cv=none; d=google.com; s=arc-20160816; b=UF9qIGNKNnQrtZLFaz68sI5Au23Oaq8GMCV2mQRViFixoCa/lslYp93CU4FPX0iF2z Kjt3AwS/GM3LpGvBtJkkDKyHhRs+81NeavWxHlQiL4ppBRU/RG5E2mZIGUf+8+eXeXYc OXQbsabTK3PJ2Gepg0+eH5uA2cUUw1T2AQn2Cxiiz+boE/iryUGuEI0clQ4toNX8So/Z reJJ08lArdnWFSiWOKzy5IQ9ADzrTmAPuwBZa166vLJVhRwpvl4kM5bSCMBUPtaUm8nN mj/iiF/wJr84bbm/LLx1ucO8bthKKx8DjjTjopqTSrgFfImXVR0aXDHD63Mmb0DzcxiZ 6hfQ== 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=QF4M5Ft6pArh9K19c10LdCPav/t7K5+IWpRz/MFyy8k=; b=mQ8G539SwSU3W6e8rH3p43KLR5x7Xcc8UkEYK8vei3P7hjlKbF5JreHlU+/nlZHbmr TMFHICoWkmLaAML1f3T0XFcCISxO66cs9MicmzqXkg2Qnm5eUlWaOZalLdqjTAde/D6k oWApB733TzY0YBV2aBxJIWuvVFh7IBSkzuGniGQjwKIPnzraFUWNQJoI2SSHuWaPSu98 ZOXrwhyLh2kYLV+dBmcd6HJU1bqG/YcXj+DqfOIvew5HI6r0PWo+J+UrVKByNj3gkxFO ca2vLSHtWJqGBBxaYdKnp8AO041fnhY4eXd6+1m3ouvBc7yRKhUGuSLMySplhSPGcuQX LEWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YFRh8bdy; 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 f4si23500935oto.169.2020.01.22.05.21.16; Wed, 22 Jan 2020 05:21:28 -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=YFRh8bdy; 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 S1729305AbgAVNS0 (ORCPT + 99 others); Wed, 22 Jan 2020 08:18:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:34078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbgAVNSY (ORCPT ); Wed, 22 Jan 2020 08:18:24 -0500 Received: from localhost (unknown [84.241.205.26]) (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 8FAC22467A; Wed, 22 Jan 2020 13:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699104; bh=Yj4njHoWj/B5aj8+qbe4B/idZZAQf4tQeEEviiIzi90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YFRh8bdyuppFt/ZyjwjgGVasHlW1QfM8zwfiP+sU2PA4xPGygfmjrtTENjWe9cyc5 f51JzGy/ALZ0Z2qZAoD3jnSXpI8s3rQ4LmZGh7Vn0U6hSF1jIJzjgpbf+JoJh97gEg PP8UpKWNmWKXE1qr1BXKdIILsI614CBuTB/miVAM= 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 5.4 042/222] iio: buffer: align the size of scan bytes to size of the largest element Date: Wed, 22 Jan 2020 10:27:08 +0100 Message-Id: <20200122092836.558100671@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@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 @@ -566,7 +566,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, @@ -574,13 +574,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; }