Received: by 10.213.65.68 with SMTP id h4csp568456imn; Tue, 13 Mar 2018 13:21:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELsNhYiUuwob77ZevqNeCdhOqr+3o1vDxS38MR77EkwXbWGuXiJ5h5FWHyPCzjiRt58Eo+z1 X-Received: by 10.98.37.132 with SMTP id l126mr1841567pfl.102.1520972515875; Tue, 13 Mar 2018 13:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520972515; cv=none; d=google.com; s=arc-20160816; b=FKxZhQuIIpTvcyHHiLYgkj3dxwy3TMbxXV9381shYQFi3Z/qSOcDCHYoPc25gxpM2S EpQbLI6ntmmTHyiwdyt4danjpBDxUOHufkSl6UhUFn4brynRMm0xcvU1qtpiaeelkSp6 phYEYhigoTCKpz8BkLqf9HGeTW2j+8xpx/S/2eZo43X3NwsK90MK3EjAHKtlnUp8xy5B Cv6rZyAdP2QJ8qtpbs+iEofqrnUYOJHA6dVsTzOJEzOf2Kb14ItcjWNXOwsTdKNYGZ0Z NWkiw4A8BH13OtcNOvz8u9yzJOku0IVEy7YjNc6lRkj4dONn6+Q5woSPLD2mtG+onxVc 7ZfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=L8H2oFkQ8j2UJryjh41CQqZIvi0M6kBuJUdzDqxIqyI=; b=zHg1j+PdViPVVvl4hBgOLs8CT0kLN/PkyAUJvsbL3EvbyZJg2IRPvFHytS9u8z/UZJ 63r3TfISTF4YBratXzTJ2tX+JtzE7aAbf9bFwtE6zablmieWzUd0NCoE3g5AswQqvMGq 5bNJBGlzJkG/tdL8qHQ9j2UtoTfB4n+xkIG4quKWAwKA9ev1yeJSa4/5tY6W4z+t4Fhr v6mqygMzInJeIgaUmYwFX/MbM7aNl2pL4WHShPHSvIlOdpbA9EfpWRChVzP6wkKWqsh3 40U9XDdo+A4kF1Xd1YV5X0dxPsm9K/Ov/HUz5rmrjhOtz/TPo2c6orsaIEJOwqpf9h3L veAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gHUx+ZiW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id r26si611307pgd.654.2018.03.13.13.21.41; Tue, 13 Mar 2018 13:21:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gHUx+ZiW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1753106AbeCMUUh (ORCPT + 99 others); Tue, 13 Mar 2018 16:20:37 -0400 Received: from mail-yw0-f196.google.com ([209.85.161.196]:34163 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751984AbeCMUUe (ORCPT ); Tue, 13 Mar 2018 16:20:34 -0400 Received: by mail-yw0-f196.google.com with SMTP id x17so665603ywj.1; Tue, 13 Mar 2018 13:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=L8H2oFkQ8j2UJryjh41CQqZIvi0M6kBuJUdzDqxIqyI=; b=gHUx+ZiWal8Iam9hIs31StJ6lDOwLntPMXpgN51R0BRRbeAvnXFR2m2Nawpj3v1dG2 GbICPj6GO2sVeNbYZplwcCKLoaHYQgXCVmGapFtq3atOHZ2Tl4l8FW3tdK0cZDGYfeDC 3NNnXpQ4tDipcfzsrJFelX4arxfZr/vSNhJSgF8+BZE6ZiaOg2ZT+CV8i7Pibr9xvpij wFV96eXq05Kh6NDifVI43E3F3O1Y2RbUnju7R7I/19CeGj+GU7Ih4n7hGv271OpBkTwW 5BW0hH8hZZ6neBf2bi67LqSX85GXtkHogcYwuX8AIWXDARTQQn3U3PQp/MI4HQMq/TUu 7lIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=L8H2oFkQ8j2UJryjh41CQqZIvi0M6kBuJUdzDqxIqyI=; b=Z3c4kNj4bGEN3/pMQ1t5clWCoeU/XFPMXlh6yg1r0v4ryMdGL1OVjVPpMvIyDKPia4 EKqYZHOpqfmm1+9/QNxarVHbdq7k3UiVGOYLLPpKoCuHUKzKuPjJ2OMLZRSyosC+QWya BJVhsPhIwUb0mi7d1dOrFoA/O06NnIRFqZvsW0wSruUJMZyCqTlDvwgxPrB7BMI6lcdZ 74NnRaJ62MPilib9zg82xdGJfbFPR9OwKFOHLEJsYws+TbJXJngoD31NxRkLNdI/Ozsx LV0vJ15iXXYXxv0F8m4gd14V1ec5axEnNmcqv9otdKLyILXzAqAie0EFZae5Mz+SI5zF ZEvA== X-Gm-Message-State: AElRT7FfP1Jj6kbKaGnKRQawYN6eulOGS8D+Ciu1tbyPif++i29ZHATA KRUv7wrY1XwA0N2b9MgguUHXRw== X-Received: by 10.13.236.7 with SMTP id v7mr1620311ywe.452.1520972433910; Tue, 13 Mar 2018 13:20:33 -0700 (PDT) Received: from sophia ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id u126sm378552ywd.48.2018.03.13.13.20.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 13:20:33 -0700 (PDT) Date: Tue, 13 Mar 2018 16:20:27 -0400 From: William Breathitt Gray To: Andy Shevchenko Cc: Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , linux-iio@vger.kernel.org Subject: Re: [PATCH 3/8] gpio: pci-idio-16: Implement get_multiple callback Message-ID: <20180313202027.GA14944@sophia> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 13, 2018 at 06:04:33PM +0200, Andy Shevchenko wrote: >On Mon, Mar 12, 2018 at 10:49 PM, William Breathitt Gray > wrote: > >> +static int idio_16_gpio_get_multiple(struct gpio_chip *chip, >> + unsigned long *mask, unsigned long *bits) >> +{ > > >> + /* clear bits array to a clean slate */ >> + for (i = 0; i < chip->ngpio; i += BITS_PER_LONG) >> + bits[i / BITS_PER_LONG] = 0; > >bitmap_clear() or bitmap_zero() bitmap_zero() would be perfect for this situation. I'll submit a version 2 of this patchset with this change for the various drivers herein. > >> + /* get bits are evaluated a gpio register size at a time */ >> + for (i = 0; i < chip->ngpio; i += gpio_reg_size) { >> + bit_word_offset = i % BITS_PER_LONG; >> + bits_mask = mask[BIT_WORD(i)] & (reg_mask << bit_word_offset); >> + if (!bits_mask) { >> + /* no get bits in this register so skip to next one */ >> + continue; >> + } > >for_each_set_bit() ? > >> + /* store acquired bits */ >> + bits[BIT_WORD(i)] |= port_state << bit_word_offset; > >__set_bit() >__clear_bit() I'm not sure for_each_set_bit() and __set_bit()/__clear_bit() would be good for this particular situation since I'm working with the entire register word (8 bits for this specific device) at a time. Since I know each register word is 8-bits, I can make 8-bit jumps and skips rather than evaluating each bit individually. Similarly, it seems more efficient to store the input 8 bits at a time rather than breaking it up to individual bits. However, I do see how all these inline bitwise operations could make it difficult to follow the code, so perhaps I can break it up across more lines so that the logic of the loop becomes easier to read. William Breathitt Gray > >We have bitmap API for *ages*. Is it too hard to check? > >-- >With Best Regards, >Andy Shevchenko