Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2780975rdh; Wed, 27 Sep 2023 12:27:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+Px175w2XlTb0CY6v/f58xYF41qOE6EVljyFtyaysycm9IWLsop9usA+fHmJ9oU0gqu8V X-Received: by 2002:a05:6358:441e:b0:143:e3a:de5f with SMTP id z30-20020a056358441e00b001430e3ade5fmr3097353rwc.26.1695842859388; Wed, 27 Sep 2023 12:27:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695842859; cv=none; d=google.com; s=arc-20160816; b=HbASepEonfZmzvrtZdDgniN7REekuxwCaciL413PZ0MAnYie/ToMNp05fjctTtnAYG Hk2ZIo1E+dRYmq/Ueqq4GJKZ44wTQ9sB2Cc2gTnpQpFoGel7teq5Nawkq9adlJ6HFeMD tOKYpjbRWIVlN2oR828gFfk5kFXnNnk3gXuOc5B18F9O6MQd2D6qvNNOSRPkiHA3UZwW CKxhpQNQGumdjknNKi+gRApfQ7L1nLZZaiENMSAxdBZl5XJHHRdR0Yrp8tKL+4qpRFVc ZY+u0pgT05Ga1njsd8t3bFHIR/Coih7IQJFkG3/kELmz1RW60x9WONKM3ARlNZXj62H0 yvKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=OZqZ0i46ZbfB53UJOvUsR3ac/FK/L9kDlsccF+BQc6I=; fh=AcRUg8zTTWdT2+Hzm+hS+LG4BqytcUgqZDrbg2WmToc=; b=n3rTTDWtjTFo/6uhm3isEp9nq2pfPab/uEVP4MJxPQuXyDIdkf1VqVpPigqnV6Ohfz WCu6rvNoGQE7u5BnUfGm3udf0Qwq3c1avT6oKm34pq8q7xFooz8lbwmyA2a7ToIJh2Le DAxvi3OnGtANWf2GE5RkRcRO5y/T/bQ4oZVYkZqIEG4D5K/Zhyap/jCae5HVGspNx8Y3 Rx/jVJV4oqBF5GzZhtqi+uepf96tCgvV8P/LGQK0Zs4K0qSNk1DYdft9QfmiOTbu0Huz oDHpuPDM9Ox2IoEA3QsaPe9ZGKdH2dDqWh+J9aDe+N9TdIaRMnxRbr/LQEFrCDm7/9ZM ciIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=daChzakE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id k20-20020a637b54000000b0056959099f46si5869603pgn.856.2023.09.27.12.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 12:27:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=daChzakE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D3919829535D; Wed, 27 Sep 2023 05:32:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbjI0McW (ORCPT + 99 others); Wed, 27 Sep 2023 08:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjI0McU (ORCPT ); Wed, 27 Sep 2023 08:32:20 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D854C0; Wed, 27 Sep 2023 05:32:19 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c135cf2459so167166951fa.0; Wed, 27 Sep 2023 05:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695817938; x=1696422738; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=OZqZ0i46ZbfB53UJOvUsR3ac/FK/L9kDlsccF+BQc6I=; b=daChzakE3Kl4dT6g3EYRYyYN2SHfSk1a/Jo6J+nhh0ldLYXp3ziYHC5DNLDt4j+t5K KDU/QNEOF126owm0PdevY43q7f4fkE9LVJW2z7ilgtrcvRHqBeipQ9yMFbUZvspPTzm/ IRUbLr3bB8aX8iVSjc5tWfHMvS3id7zZezoUWXHPPgEtQ337uWWVqT3KTUKEqpwlPEdh SWfuTn4GOT5kNAwUipXUr0DscJzdosL8zuMYrZ6nIsYfl0wQkjpEJEiR+pX6AIYnkPzp CFLIJWlI0NFg5evk2AR8OgTuXfIoKYHRMsCg+14a5BSJmi32ZyIajME1B0sXJ5oVxnwi 0gGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695817938; x=1696422738; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OZqZ0i46ZbfB53UJOvUsR3ac/FK/L9kDlsccF+BQc6I=; b=a59xL6FeB4G/3BVsHlGSsfMyKCC7GDkVYd5inGu9SxNxPkjOLf1ZAWx+2cpuzGRnMX 7TGdmwPbDHOcRKYT8BCOxd+IjLLyPJTusDFURF3jBiTNCHZoCTmHPJ/YLvNh2tA292Ll YXtlYpBaRegI4CvaSlo1FQnvg8j/XGvxiFQxC65uj0jY/68mO1VZrJZxTjJIY4RPmn7x yq2lyLNudC4bia5Q5f1Wnjz1nG4RxswLO2SaEqj+H9SCll+g1Zo+8z+gf17Q2Mk2yk9n f3xMWVlI300Cnxi52FlG7keZGu6UDsinUtRjpEF85xwQ05DjMgn5VHyPlpgOY6M8UJ/5 Z/Ug== X-Gm-Message-State: AOJu0YzTAfxi9UhHAIpXBc8xfNnwv/imB2NKIASuQAiIWqUEcvRDB+6I 6vQ/xpNzufzj81QWexfoAh0= X-Received: by 2002:a2e:9a8e:0:b0:2bf:f84e:c1ec with SMTP id p14-20020a2e9a8e000000b002bff84ec1ecmr1939557lji.13.1695817937386; Wed, 27 Sep 2023 05:32:17 -0700 (PDT) Received: from [172.16.183.71] ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id p23-20020a2e8057000000b002c0d9d83f71sm3033259ljg.62.2023.09.27.05.32.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Sep 2023 05:32:16 -0700 (PDT) Message-ID: Date: Wed, 27 Sep 2023 15:32:15 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v4 1/5] tools: iio: iio_generic_buffer ensure alignment Content-Language: en-US, en-GB To: Andy Shevchenko Cc: Matti Vaittinen , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Angel Iglesias , Andreas Klinger , Benjamin Bara , Christophe JAILLET , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: From: Matti Vaittinen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 05:32:33 -0700 (PDT) On 9/27/23 15:27, Andy Shevchenko wrote: > On Wed, Sep 27, 2023 at 11:26:07AM +0300, Matti Vaittinen wrote: >> The iio_generic_buffer can return garbage values when the total size of >> scan data is not a multiple of the largest element in the scan. This can be >> demonstrated by reading a scan, consisting, for example of one 4-byte and >> one 2-byte element, where the 4-byte element is first in the buffer. >> >> The IIO generic buffer code does not take into account the last two >> padding bytes that are needed to ensure that the 4-byte data for next >> scan is correctly aligned. >> >> Add the padding bytes required to align the next sample with the scan size. > > ... > >> + /* >> + * We wan't the data in next sample to also be properly aligned so > > Pardon me, won't or want, I didn't get?.. Both :D Well, purpose was to say want, but as I try to explain we get what we want only in some case - in other cases we won't ;) Anyways, this is something that should be fixed - thanks :) > >> + * we'll add padding at the end if needed. >> + * >> + * Please note, this code does ensure alignment to maximum channel >> + * size. It works only as long as the channel sizes are 1, 2, 4 or 8 >> + * bytes. Also, on 32 bit platforms it might be enough to align also > > 32-bit > >> + * the 8 byte elements to 4 byte boundary - which this code is not > > 8-byte > 4-byte > >> + * doing. >> + */ > Thanks! Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~