Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp45272ybl; Tue, 10 Dec 2019 17:17:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzn0Yho2USd2GnivXApe/Jz5rOncWzDc+MPAkk+tOQoxPsxWgbQeTZNTfw6psNhjthzpPXi X-Received: by 2002:a05:6830:1689:: with SMTP id k9mr531866otr.311.1576027038496; Tue, 10 Dec 2019 17:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576027038; cv=none; d=google.com; s=arc-20160816; b=Ci9GLJvo4YCc5fSWP4ar9Q5MhdHH+/twiqCExyTRCIB8jGiC1s3GwPdGbgUlWHKAi+ M+gitgQVS6MGp2Clly4A5Q0HyKAZ+VAl4idc7z+VdJ2sApXllzDvMqi/QWbJkOfQXtTd 0lWYoYZX4jzjA0B+UXuG6YK84nJD28tlDqdGLjB+nUeZ4k2FJQ8RqCDDjcPjWE820xpE 2u5SbxZnhTGZtLKeMZKp69anHcgwrty6psT4Gs97BM+jqi+xi/xeliTlaAQzuilsa9tJ y4Ql+LZHHDW9rGhi7q2SZiUXtHwnVQbVKc4ViPTgbdXAVYUxKxxWn7YWdrPoHf5Q/LDr RU+A== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rCjmuwdX9VxfrJW96q0Pn6Kl1LaCaUN5yA+3sx0sci8=; b=KQhZcAN+us2ZWtq9ja7CFg2tRGpRZziwrewJxtAffBX6XLNDG7L/7I5d9I6VLCp02L 81bvotQfEGv8C/0i67Ckr0Zcu2w9dlYWzIsnVnoUztm4rrsp1Bc7XAtWf5II5A8zy8sI /Oeb024GRhmlNZv/WG1P0UxgvNRSzYIBGBo2aowBM2idyDZsM2i4r2Vp1HmDSYNl1EXM wuef34LxsBXiaEIveDJzrJn+ienfP7kvuKCQcJG+fJneB2U7M7q6GezXm+J7drpynIHP 26TQRxzsU8FIpzfRGQxsxdHI7jEHodgfwNQfQlB2DaqY4LTHcznbs1kSTlJwsA4QxgQ9 Tvgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q7KS2Oyj; 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 f19si122021oti.13.2019.12.10.17.17.00; Tue, 10 Dec 2019 17:17:18 -0800 (PST) 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=Q7KS2Oyj; 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 S1726913AbfLKBQW (ORCPT + 99 others); Tue, 10 Dec 2019 20:16:22 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:38067 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726364AbfLKBQW (ORCPT ); Tue, 10 Dec 2019 20:16:22 -0500 Received: by mail-pj1-f68.google.com with SMTP id l4so8218257pjt.5; Tue, 10 Dec 2019 17:16:21 -0800 (PST) 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:content-transfer-encoding:in-reply-to :user-agent; bh=rCjmuwdX9VxfrJW96q0Pn6Kl1LaCaUN5yA+3sx0sci8=; b=Q7KS2OyjSso0tnnM+Jg97xqNHVBE/99Bs8Z5BKAHSMdmJHa3MvRRoQ16QGfSU1k3SX BPtUdztm2lPhGwHZaBvOfQyOk58AN4b4T0u8sMjapWdsWnK67belDEW37UaEZaoHg5jY A80/WkRFlESBtM4uB7Z0AubHXydxAVSz07klbYoWkfn6Z680Q5CuhQCGLeSAHfETo9CW uT3gYX3B5pOUhM/wqqrcKOJkZCJfPXMQACHws5ZMHK81ELS3dcrKzYXf66vN5K8fkhXy mxhcpD4iKteTmjNpP7apwqf30KPslU0iTdcXSRHnsc2gKTmfxqlNEmodoXdwAx/czxHn fptw== 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:content-transfer-encoding :in-reply-to:user-agent; bh=rCjmuwdX9VxfrJW96q0Pn6Kl1LaCaUN5yA+3sx0sci8=; b=sTaUUSgcCquaGccqIE1uo04+ghIhc6x7HAoMYxxC5anITVcB7NPCB+kjgVw5VgpdM5 vsXGRFt9tktWH13+6aHVIHAf6us7np3V2QtXPHXjGeWj18PSIQL6jKHztwnCPcW/2JFG 3Xf2tcVZrPj9+D+5KA+EKqc6bqdqjFbgl7Ki8F2I7ADN2YZO4LLehxSkDpFPZP4SLKio CuMPAhKwJJuTWYFFQN0c5asjvW1/5CQjYyRlRUTjCb/niBS6Ac8YU7YOKY4zrDoAnv33 Bsy2cs3n+ulRzYb8alvlHv5Gh6KhfT6dPgXax1U1zhRzs7BHapS/c2OtrcrRLwWgbAuo JWaA== X-Gm-Message-State: APjAAAV+WcCva+Xp4un+fFB7kb1/djBQ00IWPTwxjTGnzXAghW83aiOZ /pItP2uiyQEekR4jc5PhPWQ= X-Received: by 2002:a17:90a:a4cb:: with SMTP id l11mr478116pjw.47.1576026981243; Tue, 10 Dec 2019 17:16:21 -0800 (PST) Received: from sol (220-235-124-2.dyn.iinet.net.au. [220.235.124.2]) by smtp.gmail.com with ESMTPSA id o12sm265495pfg.152.2019.12.10.17.16.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Dec 2019 17:16:20 -0800 (PST) Date: Wed, 11 Dec 2019 09:16:15 +0800 From: Kent Gibson To: Bartosz Golaszewski Cc: Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Linus Walleij , Bamvor Jian Zhang Subject: Re: [PATCH] gpio: gpio-mockup: Fix usage of new GPIO_LINE_DIRECTION Message-ID: <20191211011615.GA9373@sol> References: <20191210021525.13455-1-warthog618@gmail.com> <20191210145515.GB3509@sol> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191210145515.GB3509@sol> 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, Dec 10, 2019 at 10:55:15PM +0800, Kent Gibson wrote: > On Tue, Dec 10, 2019 at 03:11:12PM +0100, Bartosz Golaszewski wrote: > > wt., 10 gru 2019 o 03:15 Kent Gibson napisaƂ(a): > > > > > > Restore the external behavior of gpio-mockup to what it was prior to the > > > change to using GPIO_LINE_DIRECTION. > > > > > > Signed-off-by: Kent Gibson > > > --- > > > > > > Fix a regression introduced in v5.5-rc1. > > > > > > The change to GPIO_LINE_DIRECTION reversed the polarity of the > > > dir field within gpio-mockup.c, but overlooked inverting the value on > > > initialization and when returned by gpio_mockup_get_direction. > > > The latter is a bug. > > > The former is a problem for tests which assume initial conditions, > > > specifically the mockup used to initialize chips with all lines as inputs. > > > That superficially appeared to be the case after the previous patch due > > > to the bug in gpio_mockup_get_direction. > > > > > > drivers/gpio/gpio-mockup.c | 7 +++++-- > > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c > > > index 56d647a30e3e..c4fdc192ea4e 100644 > > > --- a/drivers/gpio/gpio-mockup.c > > > +++ b/drivers/gpio/gpio-mockup.c > > > @@ -226,7 +226,7 @@ static int gpio_mockup_get_direction(struct gpio_chip *gc, unsigned int offset) > > > int direction; > > > > > > mutex_lock(&chip->lock); > > > - direction = !chip->lines[offset].dir; > > > + direction = chip->lines[offset].dir; > > > mutex_unlock(&chip->lock); > > > > > > return direction; > > > @@ -395,7 +395,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) > > > struct gpio_chip *gc; > > > struct device *dev; > > > const char *name; > > > - int rv, base; > > > + int rv, base, i; > > > u16 ngpio; > > > > > > dev = &pdev->dev; > > > @@ -447,6 +447,9 @@ static int gpio_mockup_probe(struct platform_device *pdev) > > > if (!chip->lines) > > > return -ENOMEM; > > > > > > + for (i = 0; i < gc->ngpio; i++) > > > + chip->lines[i].dir = GPIO_LINE_DIRECTION_IN; > > > + > > > if (device_property_read_bool(dev, "named-gpio-lines")) { > > > rv = gpio_mockup_name_lines(dev, chip); > > > if (rv) > > > -- > > > 2.24.0 > > > > > > > Hi Kent, > > > > I was applying and testing your libgpiod series and noticed that the > > gpio-tools tests fail after applying patches 16 & 17 (with linux > > v5.5-rc1). Is this fix related to this? > > > > I don't think so. I've only been able to trip this problem with a > couple of corner cases in my Go uapi test suite. > I have been unable to reproduce it with the tools as it requires > multiple requests with the same chip fd, including an as-is, to trip. > It turns out that I can reproduce the bug with my gpiod tools: root@firefly:/home/kent/gpiod/cmd/gpiodctl# uname -a Linux firefly 5.5.0-rc1 #23 SMP Mon Dec 9 16:26:33 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux root@firefly:/home/kent/gpiod/cmd/gpiodctl# modprobe gpio-mockup gpio_mockup_ranges=-1,4 root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl get gpiochip0 1 0 root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl info gpiochip0 - 4 lines: line 0: unnamed unused input active-high line 1: unnamed unused input active-high line 2: unnamed unused input active-high line 3: unnamed unused input active-high root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl get --as-is gpiochip0 1 0 root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl info gpiochip0 - 4 lines: line 0: unnamed unused input active-high line 1: unnamed unused output active-high line 2: unnamed unused input active-high line 3: unnamed unused input active-high Note that the line 1 direction has flipped for no reason. With the patched kernel that doesn't happen: root@firefly:/home/kent/gpiod/cmd/gpiodctl# uname -a Linux firefly 5.5.0-rc1+ #27 SMP Tue Dec 10 01:07:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux root@firefly:/home/kent/gpiod/cmd/gpiodctl# modprobe gpio-mockup gpio_mockup_ranges=-1,4 root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl get gpiochip0 1 0 root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl info gpiochip0 - 4 lines: line 0: unnamed unused input active-high line 1: unnamed unused input active-high line 2: unnamed unused input active-high line 3: unnamed unused input active-high root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl get --as-is gpiochip0 1 0 root@firefly:/home/kent/gpiod/cmd/gpiodctl# ./gpiodctl info gpiochip0 - 4 lines: line 0: unnamed unused input active-high line 1: unnamed unused input active-high line 2: unnamed unused input active-high line 3: unnamed unused input active-high I would prefer to demonstrate this with the libgpiod tools, but they don't support as-is on gets. I recall suggesting adding it and you asking why - who would need it. This is a concrete example of my response at the time - so you can exercise the full API for testing. Cheers, Kent.