From patchwork Thu Feb 10 22:48:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12742558 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA7FCC433EF for ; Thu, 10 Feb 2022 23:00:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345076AbiBJXAn (ORCPT ); Thu, 10 Feb 2022 18:00:43 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344698AbiBJXAm (ORCPT ); Thu, 10 Feb 2022 18:00:42 -0500 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05AB21105; Thu, 10 Feb 2022 15:00:43 -0800 (PST) Received: by mail-il1-x134.google.com with SMTP id e8so5588189ilm.13; Thu, 10 Feb 2022 15:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=r7B1u3StVmNn+cEV4ztOlK7kYJWbJkFyeLauH29gYM8=; b=dzLBz2h9W3+P1fTFVwJCXjMzkDS/do2ayswvINxgwRV6LLNSkbDxlUQcxdk+LJZ5Gx vwqdX6D12rc1Yvd9fQaPcwN9sVvGOovH2iqr9zxZY7dauw3jnWm/j6Ep0mU30c80bSMn x0XJB822IsAmPLlczCETi3PVgDyd0smheFP2USkn/XObVyW1NxHYcT0aTPxrxtrBTRYb xBuWoEUXkdw3rPyD+c8jdwY2BMCXVdxzxFDgblYiKQjVEL6J813R1xNRtcpVL4OQ0a7u fhfqQFn9ElMVCLQ6Sq8p4ZBLU1HYI1JL0a8nEn94OxrS6Mh7CubSmLYNEUawMDPT+DL4 V42g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r7B1u3StVmNn+cEV4ztOlK7kYJWbJkFyeLauH29gYM8=; b=JYbrZX5/FO5si8lHPf+AzsAUwkBUJgaAl7Yn7PRPyZwtMwA2kk32CdCwLLyhEsMUf0 Eqmw3Hu03yJdf1M/HEaFivr7GdNAUETVnIB+CAYZEu/O6zPbrUOciCEw0gVhBH/6Hd14 wFoF5BWBvWIy6LJdNR0xK8leWG0d6ACLurnIjYNVog7lzu7086875h7k1fkRTsOC8nnR ZUTyViEiI3AT01R/lquqMVdPlUdKHPs1782F06GtYcv6Q8ZkzwKCGtK200lrtupWy08d fyL+WKJHW579cJKRT+ufO217XxkiyEGyT9IThPtbdUx6u7Hjt38JC+gnjMqKeg6t+l+g V4sw== X-Gm-Message-State: AOAM532gfznWk9reF0lj1jgrtS69IiyJ0w8O+vDQvAooN4w3QCTZM9sY andOPrXBKsmPxHFx4UV4CNI= X-Google-Smtp-Source: ABdhPJyDaHsNtIqicj2d5g0OLH9mju+tDwyc+D9hx93ef0eytT5AHJVFdIVfEcBuRUZkUUoFK32Fgg== X-Received: by 2002:a05:6e02:1d12:: with SMTP id i18mr4925637ila.323.1644534042346; Thu, 10 Feb 2022 15:00:42 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id y9sm7235385ilg.58.2022.02.10.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:00:41 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?utf-8?b?TWljaGHFgiBNaXJvc8WC?= =?utf-8?b?YXc=?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Alexandru Ardelean , Nathan Chancellor , linux-iio@vger.kernel.org Subject: [PATCH 04/49] iio: fix opencoded for_each_set_bit() Date: Thu, 10 Feb 2022 14:48:48 -0800 Message-Id: <20220210224933.379149-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org iio_simple_dummy_trigger_h() is mostly an opencoded for_each_set_bit(). Using for_each_set_bit() make code much cleaner, and more effective. Signed-off-by: Yury Norov Reviewed-by: Andy Shevchenko --- drivers/iio/dummy/iio_simple_dummy_buffer.c | 48 ++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c index d81c2b2dad82..3bc1b7529e2a 100644 --- a/drivers/iio/dummy/iio_simple_dummy_buffer.c +++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c @@ -45,41 +45,31 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; + int i = 0, j; u16 *data; data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); if (!data) goto done; - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) { - /* - * Three common options here: - * hardware scans: certain combinations of channels make - * up a fast read. The capture will consist of all of them. - * Hence we just call the grab data function and fill the - * buffer without processing. - * software scans: can be considered to be random access - * so efficient reading is just a case of minimal bus - * transactions. - * software culled hardware scans: - * occasionally a driver may process the nearest hardware - * scan to avoid storing elements that are not desired. This - * is the fiddliest option by far. - * Here let's pretend we have random access. And the values are - * in the constant table fakedata. - */ - int i, j; - - for (i = 0, j = 0; - i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); - i++, j++) { - j = find_next_bit(indio_dev->active_scan_mask, - indio_dev->masklength, j); - /* random access read from the 'device' */ - data[i] = fakedata[j]; - } - } + /* + * Three common options here: + * hardware scans: certain combinations of channels make + * up a fast read. The capture will consist of all of them. + * Hence we just call the grab data function and fill the + * buffer without processing. + * software scans: can be considered to be random access + * so efficient reading is just a case of minimal bus + * transactions. + * software culled hardware scans: + * occasionally a driver may process the nearest hardware + * scan to avoid storing elements that are not desired. This + * is the fiddliest option by far. + * Here let's pretend we have random access. And the values are + * in the constant table fakedata. + */ + for_each_set_bit(j, indio_dev->active_scan_mask, indio_dev->masklength) + data[i++] = fakedata[j]; iio_push_to_buffers_with_timestamp(indio_dev, data, iio_get_time_ns(indio_dev));