Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4382108pxb; Sun, 14 Feb 2021 08:27:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuGXdzeWUEs2Kf6NcobWys4FSp6O19M8QS28xHXcsD187sQSrXxZzm9l6ETXTSbnAno4/+ X-Received: by 2002:a17:906:b0c2:: with SMTP id bk2mr12361126ejb.223.1613320046660; Sun, 14 Feb 2021 08:27:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613320046; cv=none; d=google.com; s=arc-20160816; b=i3KYlVe8JTlIPmvEIhm/NtynC/TY7gieYoQWnCidDNdRQToAJu2r4ew/BzWZh33nwS txPI3JIBnPpYObpWuuM1WAEhNWFGIahTJ+vlnlmC79fNASYAru/XkfIXgrsSBCZO110w 3hNgtkCWWZLZBgpgDi5P1Mu9o9DPmf5GU4YCN28JqSsYJtBK/kyQfyg/luwUHWjcBE8v yaaPF8NJM95dKR40Zu6zgqFW0OJXyIDxF6qLFCPjUtmSZkpdFU+GjZ0r7hp1RLP+bqAR xVhHcSN57paqxZMG3lnh4fN98BiOogc9U3Fh+Nygn6YsO8D83JEVtiOp6PgZoReSgMoL 7mPQ== 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; bh=eH9Y22JEyIVavpsx6o7aQh3x2rfnN4NRJqWS5LRFxJU=; b=Du4mPFnbe/AsXXHgRqPQdXUPWNism8wY6Pg6YoXqcuvY2gHDI7t3wi2E7sptVwEaA0 /RaZX/77sBB/BezJIbOaSraxZu2epr7NFMb9ynJQ1npTZ5/Su+V5eqjaWB/Owo0p65sp d8bYDogHzwDaSfxoEnjZp9yriMSS2LWiREW7f9Z8heFDGtX/qmAVazw2aaVB0Jz+NKwD nHXwtv2Jw5vVe5/T9CiuocJ9PW/PsVPmEXnBg+/0+73RDKi5Cu52c3fUhWugG2NgKrVR 1QQvJPiZ9xnMc0l4duc8CeY4lGdHtG5KBGgqT7A1z+L0+G/XIubC93czb9sNovaTSMa4 gKfA== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ka8si10673318ejc.675.2021.02.14.08.27.02; Sun, 14 Feb 2021 08:27:26 -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; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbhBNQYb (ORCPT + 99 others); Sun, 14 Feb 2021 11:24:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:40060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbhBNQYa (ORCPT ); Sun, 14 Feb 2021 11:24:30 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (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 F09B564E26; Sun, 14 Feb 2021 16:23:48 +0000 (UTC) Date: Sun, 14 Feb 2021 16:23:45 +0000 From: Jonathan Cameron To: Alexandru Ardelean Cc: , , , , , Subject: Re: [RFC PATCH 2/5] iio: kfifo-buffer: Add output buffer support Message-ID: <20210214162345.6f8f9ef0@archlinux> In-Reply-To: <20210212102021.47276-3-alexandru.ardelean@analog.com> References: <20210212102021.47276-1-alexandru.ardelean@analog.com> <20210212102021.47276-3-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 12 Feb 2021 12:20:18 +0200 Alexandru Ardelean wrote: > From: Lars-Peter Clausen > > Add output buffer support to the kfifo buffer implementation. > > The implementation is straight forward and mostly just wraps the kfifo > API to provide the required operations. > > Signed-off-by: Lars-Peter Clausen > Signed-off-by: Alexandru Ardelean Nice. For some reason I thought it would be more complex than this :) Jonathan > --- > drivers/iio/buffer/kfifo_buf.c | 50 ++++++++++++++++++++++++++++++++++ > 1 file changed, 50 insertions(+) > > diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c > index 1359abed3b31..6e055176f969 100644 > --- a/drivers/iio/buffer/kfifo_buf.c > +++ b/drivers/iio/buffer/kfifo_buf.c > @@ -138,10 +138,60 @@ static void iio_kfifo_buffer_release(struct iio_buffer *buffer) > kfree(kf); > } > > +static size_t iio_kfifo_buf_space_available(struct iio_buffer *r) > +{ > + struct iio_kfifo *kf = iio_to_kfifo(r); > + size_t avail; > + > + mutex_lock(&kf->user_lock); > + avail = kfifo_avail(&kf->kf); > + mutex_unlock(&kf->user_lock); > + > + return avail; > +} > + > +static int iio_kfifo_remove_from(struct iio_buffer *r, void *data) > +{ > + int ret; > + struct iio_kfifo *kf = iio_to_kfifo(r); > + > + if (kfifo_size(&kf->kf) < r->bytes_per_datum) > + return -EBUSY; > + > + ret = kfifo_out(&kf->kf, data, r->bytes_per_datum); > + if (ret != r->bytes_per_datum) > + return -EBUSY; > + > + wake_up_interruptible_poll(&r->pollq, POLLOUT | POLLWRNORM); > + > + return 0; > +} > + > +static int iio_kfifo_write(struct iio_buffer *r, size_t n, > + const char __user *buf) > +{ > + struct iio_kfifo *kf = iio_to_kfifo(r); > + int ret, copied; > + > + mutex_lock(&kf->user_lock); > + if (!kfifo_initialized(&kf->kf) || n < kfifo_esize(&kf->kf)) > + ret = -EINVAL; > + else > + ret = kfifo_from_user(&kf->kf, buf, n, &copied); > + mutex_unlock(&kf->user_lock); > + if (ret) > + return ret; > + > + return copied; > +} > + > static const struct iio_buffer_access_funcs kfifo_access_funcs = { > .store_to = &iio_store_to_kfifo, > .read = &iio_read_kfifo, > .data_available = iio_kfifo_buf_data_available, > + .remove_from = &iio_kfifo_remove_from, > + .write = &iio_kfifo_write, > + .space_available = &iio_kfifo_buf_space_available, > .request_update = &iio_request_update_kfifo, > .set_bytes_per_datum = &iio_set_bytes_per_datum_kfifo, > .set_length = &iio_set_length_kfifo,