Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp973410pxk; Fri, 25 Sep 2020 02:52:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4eef70w0I8qU5/ItMnYunZoGJEZMuZs1pVfE0fFopLDz/Qk87EnEQiCcXLHvrYU+7UPxS X-Received: by 2002:a17:906:2818:: with SMTP id r24mr1978765ejc.100.1601027532108; Fri, 25 Sep 2020 02:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601027532; cv=none; d=google.com; s=arc-20160816; b=lbAfCUki9SY8JgspwW9QTCf8qnHvpnbimLc2NZHZv8wrR1xA4pIjsP5PXaETtFIex8 CdIIqRD1vMKLqDw73kj91KQBAQdpiBBIXi5BRztkhW+m5PuNIp2l/OLJgxRXVpb3PqkO EBG//LMnxS3yb6sUnl0qYnAQb8smm/1khgX0RzZmuqinpwJl/06RfHumQyIa8P6/4p5+ rBhAc6a7cViKSEKFUaPen2pSAJmi9FvxOV4a5CUJR6v6hS13AWAquDRZm19PZI//GSpC OeKtgoYhl0tCodhai69ypUlwY4WYiPm5LIDt+OvSBJnFvoCLXUDw575xB3dNHUm6PPw4 BdBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LZZgw+N+0uZC3jHwut6sPtyPqViOL0NE3WEuYPgaX/8=; b=VQeI9m3AOzSZY677V8rChMq1Jc8IZ9lPd+rsMe1XVj/qzZrNORl1sm65W75WVm+7CA eHnzJnBP7PQjvEinHS8G4xYmjiTOa+nWvd1DFl1IsodvPNVnFW17AAr0aDSjqEl+6wFu XcB+lzdt3cYLBVrhizWD0xxB4z1KzBp6e9cwWJVE4E3svugCWc/7YkuPXnhxywUxC3eF stFB4jHpMGhfQ2H9EJksJ3zE67+21Yt4W03QhshRWQIYZg2wgokUymAA0Yzl434+4Zww tMV3uolN7JT59YGnjgqZ5aPN6UQImp11EwAfptptRtjH/mvE22r3MLODEUKlxE2x0gfk r1TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="pawLkd/l"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt16si1406354ejb.314.2020.09.25.02.51.49; Fri, 25 Sep 2020 02:52:12 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="pawLkd/l"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727892AbgIYJuI (ORCPT + 99 others); Fri, 25 Sep 2020 05:50:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726255AbgIYJuI (ORCPT ); Fri, 25 Sep 2020 05:50:08 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58835C0613CE; Fri, 25 Sep 2020 02:50:08 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id d6so2641210pfn.9; Fri, 25 Sep 2020 02:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LZZgw+N+0uZC3jHwut6sPtyPqViOL0NE3WEuYPgaX/8=; b=pawLkd/lBuMBWO3j1Yl5tYxIkULtDrTFQkC07XwKu9z8vQPVF8b8XteMJjhkSeuFc6 PM4YCufiyZgrztbY4IUWt/3wpqwPNlZicqsz8cZh7VdFd75dHccBombrygrmC7PbLCyH VKsh892nzf0JTfwX4yC+IT4GOn2v9QrIM9hajuNpvKRjzAfv2wUEfXlWrD/J7SYGcWf2 a3a/vF4WUNmJxCTsraBZHVjO+U+A71aL8FyCzbjz5Yd1diZ8dRshpgPQ1PtTG0gfmm6f 3+B69A99/Kh2wV+n4k6XfIVkkhpefTUgGWXAorX9LOAuM53QA4DvzWkbSI3HjNI5eKvh jQJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LZZgw+N+0uZC3jHwut6sPtyPqViOL0NE3WEuYPgaX/8=; b=LxkSEEwQXMyyTesIkM3nBiRXEeD02cWCMwHLYbGeXf0B1qpFzfNpzbawneEkvmSqQt 53+avwSbF6DfWtxud2Fby+4EsQNN6jnnhs2iCXvVwbhvZGMgTGgEqhyvRsY3Fc7PLW3o OZSaB87HMJ1e9W5CEXJJGaDdWbD3ZlZlRoq8HuPO5WJHuD9xzuKqVFNYnTLNYcG6SoVk rqEkLdJ760UThtVCmgnVmaSLLi9m8wLU6mTu9yoDHa1TbsjxH/N6cWdqmVpEe4Dmukvu LF1mocloHT7iebGtwXaSsWfctT8dWw2IHqEXIQWPCxG4P4/i/WVZ9/+y0gPI4RDB0/i8 9PCA== X-Gm-Message-State: AOAM531G+UWfVoHa0zyhNou8WFdAjtXmyFCSPSa06mlokbDDWW9n4BRJ 8pBYb59zTS2TB6wG5ME7DMwJwG8YtgCP2Oi2Wdw= X-Received: by 2002:a17:902:d708:b029:d2:635f:6692 with SMTP id w8-20020a170902d708b02900d2635f6692mr2900886ply.17.1601027407841; Fri, 25 Sep 2020 02:50:07 -0700 (PDT) MIME-Version: 1.0 References: <20200922023151.387447-1-warthog618@gmail.com> <20200922023151.387447-11-warthog618@gmail.com> <20200924032414.GC11575@sol> <20200924092622.GB20188@sol> In-Reply-To: <20200924092622.GB20188@sol> From: Andy Shevchenko Date: Fri, 25 Sep 2020 12:49:49 +0300 Message-ID: Subject: Re: [PATCH v9 10/20] gpiolib: cdev: support GPIO_V2_LINE_SET_CONFIG_IOCTL To: Kent Gibson Cc: Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Linus Walleij , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 24, 2020 at 12:26 PM Kent Gibson wrote: > On Thu, Sep 24, 2020 at 11:26:49AM +0300, Andy Shevchenko wrote: > > On Thu, Sep 24, 2020 at 6:24 AM Kent Gibson wrote: > > > On Wed, Sep 23, 2020 at 07:15:46PM +0300, Andy Shevchenko wrote: > > > > On Wed, Sep 23, 2020 at 7:14 PM Andy Shevchenko > > > > wrote: > > > > > On Tue, Sep 22, 2020 at 5:35 AM Kent Gibson wrote: ... > > > > > > + polarity_change = > > > > > > + (test_bit(FLAG_ACTIVE_LOW, &desc->flags) != > > > > > > + ((flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW) != 0)); > > > > > > > > > > Comparison > > > > > > > > Comparison between int / long (not all archs are agreed on this) and > > > > boolean is not the best we can do. > > > > > > > > > > There is no bool to int comparision here. > > > > test_bit() returns int or long depending on arch... Then you compare > > it to bool (which is a product of != 0). > Really - I thought it returned bool. > It is a test - why would it return int or long? I assume due to arch relation. Some archs may convert test_bit() to a single assembly instruction that returns a register which definitely fits long or int depending on case. > Surely it is guaranteed to return 0 or 1? Not sure about this, it's all in arch/* and needs to be investigated. Would be nice to have it cleaned up if there is any inconsistency (and document if not yet). But It's out of scope of this series I believe. > > > There are two comparisons - the inner int vs int => bool and the > > > outer bool vs bool. The "!= 0" is effectively an implicit cast to > > > bool, as is your new_polarity initialisation below. > > > > > > > What about > > > > > > > > bool old_polarity = test_bit(FLAG_ACTIVE_LOW, &desc->flags); > > > > bool new_polarity = flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW; > > > > > > > > old_polarity ^ new_polarity > > > > > > So using bitwise operators on bools is ok?? > > > > XOR is special. There were never bitwise/boolean XORs. > > > > We must live in different universes, cos there has been a bitwise XOR in > mine since K&R. The logical XOR is '!='. Oops, you are right, It was never boolean XOR because it's the same as a simple comparison. ... > > > > and move this under INPUT conditional? > > > > > > It has to be before the gpio_v2_line_config_flags_to_desc_flags() call, > > > as that modifies the desc flags, including the new polarity, so > > > polarity_change would then always be false :-). > > > > I really don't see in the code how polarity_change value is used in > > FLAG_OUTPUT branch below. > > It isn't. But desc->flags is modified before both - and so the > polarity_change initialization has to go before both SINCE IT TESTS > THE FLAGS. I see now. Sorry for being too blind. -- With Best Regards, Andy Shevchenko