Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp232295pxb; Thu, 12 Nov 2020 02:17:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6EkpIFKy0lBmKVkNpPbyiFuTt511NFPiMolW0Cxh1Ypi8dzT00XJamYBDLvRJIpnth0TZ X-Received: by 2002:a17:906:d7b7:: with SMTP id pk23mr30784755ejb.214.1605176220312; Thu, 12 Nov 2020 02:17:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605176220; cv=none; d=google.com; s=arc-20160816; b=ytjnWDMp35tfC4NK9XTRhXU+sJvplce+5qwKcJux0RWxQdKu1qcKVKMqC2RrMrdFpe +x6C9NFxDr31hhnVqBMiwn0ZsNFvtRuWfYwnkAC19utbb/JZpS17FEG+VgCSsQKIrNTe NDoMrIRNdR1Eqpkx/NnjOGiIUkG9B3vTH4bQ6/CETCU/67eXNvZJQe366/G3czsXDL/m /Qayts5K9bhSimoWoE0dp21Io7se0i0P6AbOSPQxQZNjL9fejYsQNDFUEouZQdM2kGy9 USDOEYXPcPooihUKmsLWOHo9YFJZ/44ti0FgkLB8mtGbnhkaTUT2CzoUxuyoYoIQSP7u ndCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7CyQ0uQ0w9dS+uyDjnnUPPq2ywGCJWQupqJd0QKx2Jk=; b=mjL/bXm8oEAO2PUjCqbWwI5hQPAV37xC7+HsQkmETIFZlV3IkNRBh+gsGVgC1icM8U P/hqhWwETxzUI2TdxrfxkD1M3toOKfWtbaUdJCkKiXrhjKfse5Tp+nblPHSi0XUlD425 q8oHgpJ+70D1DSur30vp5h8V58jGOHH19ZAMgPGI3r/7bQIakV2mgc+OipsfUVKO831H 18rvFT7hxAFpJYhX6y66k+H2NiSwNX1iIL0yZklqXCmPqUaPUblYekN6cM3ytgzgiB0f iHUzyODHBTQVbQNm0ZCk5xbYfzNKDy/i+Vp18N80c9Tfm7NADux3Bil3iONzZoWK+aHp xGwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T3Yf8CTM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oz16si3425062ejb.415.2020.11.12.02.16.31; Thu, 12 Nov 2020 02:17:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T3Yf8CTM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727147AbgKLKPJ (ORCPT + 99 others); Thu, 12 Nov 2020 05:15:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgKLKPI (ORCPT ); Thu, 12 Nov 2020 05:15:08 -0500 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A53F0C0613D1; Thu, 12 Nov 2020 02:15:06 -0800 (PST) Received: by mail-oi1-x242.google.com with SMTP id c80so5795875oib.2; Thu, 12 Nov 2020 02:15:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7CyQ0uQ0w9dS+uyDjnnUPPq2ywGCJWQupqJd0QKx2Jk=; b=T3Yf8CTM/8OJgdJBdFg9/QHXAhF/LvM5Ds2Ek/AlhyesdxE5q9+/Vh7EqQ8jAYn7oS i9q+JMykbW2WrP9L64e16OkdpU2cs/Utpg6tjrnB18EpAWYQeWz/BmOGy0KPdOG0NTAT TGZyWkzXmT/8Dyc+NvDTCI4RsKCrTCEnGqrMP5Y+gF42fIZ5h8TW23ITvMTkM0jB1jaC VgBKYRKq608sI5Q5wjFgpNvlN1U4sauWxXDmiOmRrSnUVS1POaG0s/hUS3u404qjI/PO xtf+HdfXDnlFc2JKfBC4QSYVCB6poYa4gjEFGiD74s3Ow3ckzYZ0djptMOuKqkoMnryh 52yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7CyQ0uQ0w9dS+uyDjnnUPPq2ywGCJWQupqJd0QKx2Jk=; b=dxClFtdhE+G2p8eOH+xS17bHJ/ErFlF/426Hduf6RMxeQxZAzSdiGEHgaM8Cy0+Vlo hKJh56JLKoG+jjyBGlStdX9twunvVHOkibspGd621tNyGVMJyuTGudZGf55LJjTPFLqY Xb9fw7CmR5cL+HOkfUZXfzU9gAmvY65R5pC7Nm+4Ie1FEIdn39lM/BY0lq94/L+edndq HQyhUM08xjHkdr90cizeupkLKePWKDJz2QR29AWpaxuVg1Vqm5xYV0a8pMxMESk9MTfW 6urIa9Bucco6Nuh0QZ+hlnp9yBNZDYe7k386jAv+dr1ZfMu1H5hCp96V2lqINEggcmJ2 vyBw== X-Gm-Message-State: AOAM531kaSY2wV2D7C/ZCWYPPokSPGH4Ja5/pfTygtHrIRpBBXCtqQMX l7bVd4ivk321X4yPg2lMdLiy6o8RkVnpWPS14MU= X-Received: by 2002:aca:420a:: with SMTP id p10mr4804532oia.117.1605176106010; Thu, 12 Nov 2020 02:15:06 -0800 (PST) MIME-Version: 1.0 References: <20201112091050.84991-1-alexandru.ardelean@analog.com> <49aea6de-9084-d5a2-a6be-967196570830@metafoo.de> In-Reply-To: <49aea6de-9084-d5a2-a6be-967196570830@metafoo.de> From: Alexandru Ardelean Date: Thu, 12 Nov 2020 12:14:55 +0200 Message-ID: Subject: Re: [PATCH] iio: ad_sigma_delta: Don't put SPI transfer buffer on the stack To: Lars-Peter Clausen Cc: Alexandru Ardelean , linux-iio , LKML , Jonathan Cameron Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 12, 2020 at 11:55 AM Lars-Peter Clausen wrote: > > On 11/12/20 10:10 AM, Alexandru Ardelean wrote: > > From: Lars-Peter Clausen > > > > Use a heap allocated memory for the SPI transfer buffer. Using stack memory > > can corrupt stack memory when using DMA on some systems. > > > > This change adds 4 bytes at the end of the current DMA buffer, which will > > be used by the trigger handler. > > This is required because the first 4 bytes are reserved for register data. > > > > Fixes: af3008485ea03 ("iio:adc: Add common code for ADI Sigma Delta devices") > > Signed-off-by: Lars-Peter Clausen > > Signed-off-by: Alexandru Ardelean > > --- > > drivers/iio/adc/ad_sigma_delta.c | 4 ++-- > > include/linux/iio/adc/ad_sigma_delta.h | 2 +- > > 2 files changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c > > index 86039e9ecaca..33297f26508a 100644 > > --- a/drivers/iio/adc/ad_sigma_delta.c > > +++ b/drivers/iio/adc/ad_sigma_delta.c > > @@ -395,11 +395,11 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) > > struct iio_poll_func *pf = p; > > struct iio_dev *indio_dev = pf->indio_dev; > > struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); > > + uint8_t *data = &sigma_delta->data[4]; > > unsigned int reg_size; > > unsigned int data_reg; > > - uint8_t data[16]; > > > > - memset(data, 0x00, 16); > > + memset(data, 0x00, 4); > > Younger me didn't know what he was doing, this is wrong. We need the > extra space for the padding and timestamp. > > We also can't put the beginning of the buffer at an 4 byte offset since > it needs to be 8 byte aligned for the timestamp. I'll correct this. I was re-spinning this out of some old patches and discussions on this that I have. So, then this becomes 24 bytes? Or 16? Something like: uint8_t data[24] ____cacheline_aligned; uint8_t *data = &sigma_delta->data[8]; > > > > > reg_size = indio_dev->channels[0].scan_type.realbits + > > indio_dev->channels[0].scan_type.shift; > > diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h > > index a3a838dcf8e4..ac4ac4752c62 100644 > > --- a/include/linux/iio/adc/ad_sigma_delta.h > > +++ b/include/linux/iio/adc/ad_sigma_delta.h > > @@ -80,7 +80,7 @@ struct ad_sigma_delta { > > * DMA (thus cache coherency maintenance) requires the > > * transfer buffers to live in their own cache lines. > > */ > > - uint8_t data[4] ____cacheline_aligned; > > + uint8_t data[8] ____cacheline_aligned; > > }; > > > > static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd, > >