Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2183774rwd; Sun, 28 May 2023 09:45:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lExKrEI7wjz8sESIf7Qcn1B8cgbXZQKJGXF9ubshmTfp4hkubyDspHVMNNLCyka/unJNq X-Received: by 2002:a05:6a21:6da1:b0:10f:6529:5442 with SMTP id wl33-20020a056a216da100b0010f65295442mr7183755pzb.49.1685292306400; Sun, 28 May 2023 09:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685292306; cv=none; d=google.com; s=arc-20160816; b=lDcoWWHZeK0I1rLuLhhJx3611gNsCnJlCzRDVsh+BL8HXz1R7aBP7sAYW0kVX54lip ISB+WM7RU1A5m/mcNJAESSV9vc+9ncEwVzWOfKU6f0GYgKvYTEKaQFOqBNmX2SIL+/fe gl+1/5Lvj3LeKp6oVgRlTX07NbMV1enZfq1Yauff8XDxVaPdBSwXHc4ZOkBlXL30xCCo SO5FzBTBx6DFhjHgBt1ccQaTI1zbtbs4AwlA3SeN8l+7UgbzDOav9tVSYcbrjpcdy2FT gI8KEdlWCyCZn8P09jehiy83bMEvLWUgkSq73X/7GdnDNA5W7jliDcQp7efqV2xnlE1H QfnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=bJP45RJOh6lsIGdZbjksu5Nk7X6orljzLBz9PdM6UQ4=; b=nxrvPS1SWC+dlP95hFli9CaT2In91K5kRQ1UfiKyBBAvs0TXUKnh6D60v9yqCrCgag kHYPegHrYCiOzh+x9QlJk6LUqr7IgTW0w1hGc6Iw7kCuGyUwwb8ESJ6UaojZ3baDJVAk hKzKTrUnv/BLtQKircmgudpUDCSyqvPddzwhXv2m8+EK1cEVeR5e4mgC6Px0NbF3mRbP F8Joo+2NM4WOY0Y9gRJrvT2dXN9xUgVP3v2RFMKB9ZeDEH269EdlIG7Fz7A6MEi/HQTk NDSndSJ7Y7D20GOTuT3FE5+OXJQmaSM5GTsdCdL7YeHl8gzhsrSL/lkiRmhgQs1RDPnG nHpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rVIVkMiR; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g192-20020a636bc9000000b0053eee173733si7726773pgc.227.2023.05.28.09.44.54; Sun, 28 May 2023 09:45:06 -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=@kernel.org header.s=k20201202 header.b=rVIVkMiR; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjE1Qcs (ORCPT + 99 others); Sun, 28 May 2023 12:32:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjE1Qcq (ORCPT ); Sun, 28 May 2023 12:32:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A73AA7; Sun, 28 May 2023 09:32:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E39EE60EAB; Sun, 28 May 2023 16:32:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B81DAC433D2; Sun, 28 May 2023 16:32:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685291564; bh=jfZ3hykkOZ0SU4PcgvnvJdy4PZrWwwVhDVQNGCS+xlc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rVIVkMiRdL+FKfQsKdL9k1zOefcA0mufm8J0I6XzvF18Soc3AoTihcWDfTBzApW67 yvqIs0oAGTQcqNMr1G6JjQONGxfPDrYReWOjDhJ4SFB9s0M/lrAroiCDqSuwtSFiaI 8viPBDwceK9vbTunyKryFVyJcSO59LvXRwaPPadjvE6gWswxy2Ln9El4I5zDZApslV Z40o/6f6GF0mV4ovag4WX9IUSp85kBD4qsBeC26flUKf5uyOHjV3cdXaVdZ/xbJXYo j4lnfqjWn2twcimnWXZp2oQ6pCfGrRdlVqVlMcy+DJePuGUFA7Wr31HR/rzRFCF007 5bAhEmIKRtZJw== Date: Sun, 28 May 2023 17:49:03 +0100 From: Jonathan Cameron To: Matti Vaittinen Cc: Mehdi Djait , 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 Subject: Re: [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Message-ID: <20230528174903.6a9c2533@jic23-huawei> In-Reply-To: <682e84b6-9912-ecb9-9ca2-9d96f511c22d@gmail.com> References: <682e84b6-9912-ecb9-9ca2-9d96f511c22d@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 ... > > @@ -762,6 +763,8 @@ static int kx022a_fifo_disable(struct kx022a_data *data) > > { > > int ret = 0; > > > > + kfree(data->fifo_buffer); > > Should we have the kfree only after the sensor is disabled? I wonder if > we in theory have here a time window where the buffer is freed but the > measurement is still running and - with a lots of bad luck - can result > measurement being written to a freed buffer? Perhaps move the kfree to > be done only after the measurement has been stopped? > > Other than that, this is looking good to me. > Agreed. Even if it's not a bug as such, it is better to keep the order of this function as close as possible to the reverse of what happens in *_fifo_enabled() as easier to reason about if that's the case. > > + > > ret = kx022a_turn_off_lock(data); > > if (ret) > > return ret; > > @@ -770,7 +773,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data) > > if (ret) > > goto unlock_out; > > > > - ret = regmap_clear_bits(data->regmap, KX022A_REG_BUF_CNTL2, > > + ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2, > > KX022A_MASK_BUF_EN); > > if (ret) > > goto unlock_out; > > @@ -801,6 +804,12 @@ static int kx022a_fifo_enable(struct kx022a_data *data) > > { > > int ret; > > > > + data->fifo_buffer = kmalloc(data->chip_info->fifo_length * > > + KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL); > > + > > + if (!data->fifo_buffer) > > + return -ENOMEM; > > + > > ret = kx022a_turn_off_lock(data); > > if (ret) > > return ret; > > @@ -811,7 +820,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data) > > goto unlock_out; > > > > /* Enable buffer */ > > - ret = regmap_set_bits(data->regmap, KX022A_REG_BUF_CNTL2, > > + ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2, > > KX022A_MASK_BUF_EN); > > if (ret) > > goto unlock_out; ...