Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3454848rwr; Sat, 29 Apr 2023 07:30:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Z9n12Mc3bzADOeXSm5bPikLlGZTj8Fv9wzpRLRTXLbshDzYfyC4gA53Fw6sCoWwAOGpWN X-Received: by 2002:a17:902:f688:b0:1a6:e00b:c3e5 with SMTP id l8-20020a170902f68800b001a6e00bc3e5mr10284227plg.4.1682778600050; Sat, 29 Apr 2023 07:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682778600; cv=none; d=google.com; s=arc-20160816; b=TWxYwh0mCsWlWQYYTOXRDUyNbLu2UflaB1rgAW9CNAoyKyIlrwYQklMJ1QB98aYYu3 RdF2S9tWj8IrcuiqyEp+Gk+MK1LaC5R6bXqLvOZ+juPaOcSumYFJjyPCL0MALmrH7Frj 6+CC8847sHGOQwveyivM1XI0IxD87PPo/QEobWN89BnLyMnhrsxdGpxm7BWEi2JSei+h UyNtCIKAOUcDkMNCW+MAxnlILanoA/F87ISGH1sIkInx0Qsc+Iii8AtkINfW8J+08sUe v8cLd4LXEkrOjOsNFgF44m+xSXewfDNbGk8vg2DS/SR9p4/crwOQrUbv0bgw5Yc+Lrhx /ncQ== 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=wD2Tv7VWgOu34ooZ9hAAE411z3zX6PYGvJ3ivxoCyk0=; b=bWTW1y4ZqIdh0CjZ5ZH6GYvpPwC7caVo5iK7kmSRfx5q8/HQ0kxomaA6rRSx6EmsnF 0CByCsRNZIaqsxUNQ76UIadZb8d7Tb+Bl7nrylxpqt9PVKZ83boKHUo6p0w5O7MII4un tejNLWVsYNOdoDkRg0jud2DsFVO9o7xBYDgGtEWJhUGoCFC31me56JRoDuUOIp+92D/V dtcCo14RE1o/NNqk9otUJG4I0GRMvxug6RGPuDKvHGpXlXyyOKnhvOhffD7hOR2D/iix 705s0e5D6bL9e0jBfcOvd8s72AuY4u0IH99wO+93qT1cbzrNErUZZiGUsfGAbCNI7Res qGCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=A0Bk4V0f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a170902ce0500b0019a95ab6b66si20080105plg.33.2023.04.29.07.29.41; Sat, 29 Apr 2023 07:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=A0Bk4V0f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231142AbjD2N4q (ORCPT + 99 others); Sat, 29 Apr 2023 09:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbjD2N4o (ORCPT ); Sat, 29 Apr 2023 09:56:44 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F203E1BC2; Sat, 29 Apr 2023 06:56:41 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4efe8991bafso1218314e87.0; Sat, 29 Apr 2023 06:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682776600; x=1685368600; 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=wD2Tv7VWgOu34ooZ9hAAE411z3zX6PYGvJ3ivxoCyk0=; b=A0Bk4V0f2efpYuP8tu8Oq4MufoTU1x0gdYa3/2HTZDWdQ2OYONCba0VQRyJD4QjK4u QsrN3gDEfwtE//Xktnjl4jkFpI+BlsUtUxdTmkAedPE8Lr36Pm5cCO+gX0a5qWwGnl12 7ddQcRrO//BrFPFhD+ufWdNWUU/WqJg1eRbib/pe8Op2cEsiNBtEtqw+3S0NWM4ZwA9O t/c0RbpG1eGbIEuGw57VuQkp+Q1COSlsILeqtyF7XU+Z0+3eGOrvPhUOrRDv0t57K84Q RUJoeg6uBtsq53uKY+aA2Wwp+4dqfRX1OEmmzKukytffkxuEzvzWwpOzOIbxJ2umcODF CHwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682776600; x=1685368600; 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=wD2Tv7VWgOu34ooZ9hAAE411z3zX6PYGvJ3ivxoCyk0=; b=j9u5vtWwAOHnaTBmf+Qd9YJBmFPv7t6+doqUDXrOIaIA4qhchODngincgQRiTCeFbp 1ptAEOoDWqkfzgHWn4vTf1T7zWevRcHwPzzc+srOQ7xQ3q9BujGQFAJX1PNhOVfB6x1F Bi8mQQ5wKjmIxNSHo9BkGiR5JpwrOwsSy3/1BfKB94cQqDKJ+GeJZQCZwhdOvtVPSwm2 RQWYgnEOPQP1yxoWWYcnvDa5b4+pUxh5O70iw4+nBCw6IXdivDR2hsIf8xxhqbDdpDI6 xBdTe651r+pv8Jl9jg1HpCQKR/loz3iGBlCspKV2pqcG1A5xPQoXFQONw4V6H8DGMuAx tVAg== X-Gm-Message-State: AC+VfDx/08i4geLAXO8SGJzThT5JxGMToHDKy1pn4CjuXiehQ6vM0VqT 1fMud8OI+JpZw/2To4Di/3HZQ2s7HRM= X-Received: by 2002:ac2:4895:0:b0:4ec:9f24:3e5f with SMTP id x21-20020ac24895000000b004ec9f243e5fmr2474852lfc.0.1682776599998; Sat, 29 Apr 2023 06:56:39 -0700 (PDT) Received: from [192.168.1.111] (62-78-225-252.bb.dnainternet.fi. [62.78.225.252]) by smtp.gmail.com with ESMTPSA id q6-20020a19a406000000b004edb8fac1cesm3800590lfc.215.2023.04.29.06.56.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Apr 2023 06:56:39 -0700 (PDT) Message-ID: <64728e90-48a7-43d0-b3d3-bfceb94884d7@gmail.com> Date: Sat, 29 Apr 2023 16:56:38 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v3 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Content-Language: en-US, en-GB To: Mehdi Djait Cc: jic23@kernel.org, krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org References: <867ac7b4-b666-854f-69f7-2d7d7d92c94e@gmail.com> From: Matti Vaittinen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/29/23 15:59, Mehdi Djait wrote: > Hi Matti, > > On Tue, Apr 25, 2023 at 11:12:11AM +0300, Matti Vaittinen wrote: >> On 4/25/23 10:24, Mehdi Djait wrote: >>> Hi Matti, >>> >>> On Tue, Apr 25, 2023 at 09:50:11AM +0300, Matti Vaittinen wrote: >>>> On 4/25/23 01:22, Mehdi Djait wrote: >>>>> Add the chip_info structure to the driver's private data to hold all >>>>> the device specific infos. >>>>> Refactor the kx022a driver implementation to make it more generic and >>>>> extensible. >>>>> >>>>> Signed-off-by: Mehdi Djait >>>>> --- >>>>> v3: >>>>> - added the change of the buffer's allocation in the __kx022a_fifo_flush >>>>> to this patch >>>>> - added the chip_info to the struct kx022a_data >>>>> >>>>> v2: >>>>> - mentioned the introduction of the i2c_device_id table in the commit >>>>> - get i2c_/spi_get_device_id only when device get match fails >>>>> - removed the generic KX_define >>>>> - removed the kx022a_device_type enum >>>>> - added comments for the chip_info struct elements >>>>> - fixed errors pointed out by the kernel test robot >>>>> >>>>> drivers/iio/accel/kionix-kx022a-i2c.c | 15 +++- >>>>> drivers/iio/accel/kionix-kx022a-spi.c | 15 +++- >>>>> drivers/iio/accel/kionix-kx022a.c | 114 +++++++++++++++++--------- >>>>> drivers/iio/accel/kionix-kx022a.h | 54 +++++++++++- >>>>> 4 files changed, 147 insertions(+), 51 deletions(-) >>>>> >>>>> diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c >>>>> index 8f23631a1fd3..ce299d0446f7 100644 >>>>> --- a/drivers/iio/accel/kionix-kx022a-i2c.c >>>>> +++ b/drivers/iio/accel/kionix-kx022a-i2c.c >>>>> @@ -15,6 +15,7 @@ >>>> >>>> ... >>>> >>>> >>>>> static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, >>>>> @@ -600,13 +600,17 @@ static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples, >>>>> { >>>>> struct kx022a_data *data = iio_priv(idev); >>>>> struct device *dev = regmap_get_device(data->regmap); >>>>> - __le16 buffer[KX022A_FIFO_LENGTH * 3]; >>>>> + __le16 *buffer; >>>>> uint64_t sample_period; >>>>> int count, fifo_bytes; >>>>> bool renable = false; >>>>> int64_t tstamp; >>>>> int ret, i; >>>>> + buffer = kmalloc(data->chip_info->fifo_length * KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL); >>>>> + if (!buffer) >>>>> + return -ENOMEM; >>>> >>>> Do you think we could get rid of allocating and freeing the buffer for each >>>> flush? I feel it is a bit wasteful, and with high sampling frequencies this >>>> function can be called quite often. Do you think there would be a way to >>>> either use stack (always reserve big enough buffer no matter which chip we >>>> have - or is the buffer too big to be safely taken from the stack?), or a >>>> buffer stored in private data and allocated at probe or buffer enable? >>> >>> I tried using the same allocation as before but a device like the KX127 >>> has a fifo_length of 342 (compared to 86 for kx132, and 43 for kx022a). >>> Allocating this much using the stack will result in a Warning. >>> >> >> Right. Maybe you could then have the buffer in private-data and allocate it >> in buffer pre-enable? Do you think that would work? > > Do you mean add a new function kx022a_buffer_preenable to iio_buffer_setup_ops ? Sorry. I thought the kx022a already implemented the pre-enable callback but it was the postenable. I was mistaken. > Would adding the allocation to kx022a_fifo_enable and the free to > kx022a_fifo_disable be a good option also ? Yes. I think that should work! Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~