Message ID | 20230426220338.430638-1-andreas@kemnade.info |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp540976vqo; Wed, 26 Apr 2023 15:31:16 -0700 (PDT) X-Google-Smtp-Source: AKy350YVOk4if862Fwlg2OMRNXfEPW66L+VGm3VpnHawi0PBuRwd++evKI4xiK5L0WkpetD+yxXz X-Received: by 2002:a17:902:f707:b0:1a4:fe07:49e9 with SMTP id h7-20020a170902f70700b001a4fe0749e9mr21305955plo.63.1682548275803; Wed, 26 Apr 2023 15:31:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682548275; cv=none; d=google.com; s=arc-20160816; b=pQnAIJLdxOc+X2HSBOJii5e9XP1JtX7xndxls3WAJuMWz2ckovLSn0dM0wDE6i69Md oAe5wIfLOqWaW9LQ8n/b/N1Rp9XLBpzMPGvcvGZuR7PH8QH3ZN2uh7bySrnPMUkkfFGH Rtjdqs/Uu+ScAdexytjnVVOVkuTO3UeLACDeSa4wcVgyneWZdPEchXaPIQlDVTn7blE2 S8tNm9poVyBP5xfbdem/P1yv6rQ+rwmyB0BM+6QG1fS1O1LrxjuD91VvqVX0jg/18ro/ SKWN9eF/vaQ5zeNmReiLsGH6f7wNNXvdXOvDLvlnZOUEC3DGeEQNsfnEsCoFi46+4puW tYWw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=86/z7JpBpTFJ3jh7x1UT3ZNWieULbXEuuoLuCk5wHYw=; b=mfice6FREVl+GTbd7+ltqPo/f2tv/I4GCTOVx4/fn9b2O0fKRPD1/u1tmBvZeFGAe1 YeVv3q3EdEcituL06EOrDERaKOCWd8ZqiEG56q7qm9YJrwbVPS3wsPaTsMvl+DTg7+H4 TJ6gADkdqaroWHJbQaOEOVrMRb6ALTZ1XOtNYE7E22r88o5QGAKT1ANHkoYPcAW0B0Gy NxmYvC93NBeEvhq1rUX2Cg0zpHBc9/nPv7PXBy0G3fKEufc2n2fP7fMddpXNzyRTSLNU hXf9HrSCavEFKLEKalDkZlCeCIqRVcbmWXS541dwibjGYl4gdH1pdaAFz72XtBSSMo81 c0yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20220719 header.b="64SS/vsf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a170902ef4600b001a63e4ff6fbsi18028949plx.178.2023.04.26.15.31.03; Wed, 26 Apr 2023 15:31:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20220719 header.b="64SS/vsf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239857AbjDZWEZ (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Wed, 26 Apr 2023 18:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231915AbjDZWEY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Apr 2023 18:04:24 -0400 Received: from mail.andi.de1.cc (mail.andi.de1.cc [IPv6:2a01:238:4321:8900:456f:ecd6:43e:202c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BCF6F2; Wed, 26 Apr 2023 15:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20220719; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=86/z7JpBpTFJ3jh7x1UT3ZNWieULbXEuuoLuCk5wHYw=; b=64SS/vsfibe+zAHrgDLhZlAsXj U8+gqmgFqWYI1epMZKCjf9D22GK6u+mxEoiG9Pr+SDEdrhQQi9iXAkmX/w54J1ivTyqeXzzLnwAnT BfdKNXmlJTB6xLSus6ywuS7nTCOGClKPvRfOFfCWZz4f1/KDT6pFlxycF9S1ZhKjUDCxShEnMZr0k RM4fWp2iHBuHQWewNdXIvJckrf2zYnOupyQs7/ZfDcSwHcSZAWuv3pl3AG163JTiLd2xRoYKZ1ft8 tA6hFYdoJUWbXPPjHFZ+kNpqTMnAKfIDezroJPiG1Jl8+o/7qgHRJUSs/jVSIbAuiD93iinx5TUnf cpVqBOgw==; Received: from p200300ccff09c2001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:ff09:c200:1a3d:a2ff:febf:d33a] helo=aktux) by mail.andi.de1.cc with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from <andreas@kemnade.info>) id 1prnFE-0008HC-AR; Thu, 27 Apr 2023 00:04:12 +0200 Received: from andi by aktux with local (Exim 4.96) (envelope-from <andreas@kemnade.info>) id 1prnFD-001o20-2v; Thu, 27 Apr 2023 00:04:11 +0200 From: Andreas Kemnade <andreas@kemnade.info> To: linus.walleij@linaro.org, brgl@bgdev.pl, christophe.leroy@csgroup.eu, andy.shevchenko@gmail.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, ": Tony Lindgren" <tony@atomide.com>, Aaro Koskinen <aaro.koskinen@iki.fi>, linux-omap@vger.kernel.org Cc: Andreas Kemnade <andreas@kemnade.info> Subject: [PATCH] gpiolib: fix allocation of mixed dynamic/static GPIOs Date: Thu, 27 Apr 2023 00:03:38 +0200 Message-Id: <20230426220338.430638-1-andreas@kemnade.info> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit X-Spam-Score: -1.0 (-) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764279741002160367?= X-GMAIL-MSGID: =?utf-8?q?1764279741002160367?= |
Series |
gpiolib: fix allocation of mixed dynamic/static GPIOs
|
|
Commit Message
Andreas Kemnade
April 26, 2023, 10:03 p.m. UTC
If static allocation and dynamic allocation GPIOs are present,
dynamic allocation pollutes the numberspace for static allocation,
causing static allocation to fail.
Enfore dynamic allocation above GPIO_DYNAMIC_BASE.
Seen on a GTA04 when omap-gpio (static) and twl-gpio (dynamic)
raced.
On that device it is fixed invasively by
commit 92bf78b33b0b4 ("gpio: omap: use dynamic allocation of base")
but lets also fix that for devices where there is still
a mixture of static and dynamic allocation.
Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS")
Suggested-by: andy.shevchenko@gmail.com
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
drivers/gpio/gpiolib.c | 4 ++++
1 file changed, 4 insertions(+)
Comments
Le 27/04/2023 à 00:03, Andreas Kemnade a écrit : > [Vous ne recevez pas souvent de courriers de andreas@kemnade.info. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] > > If static allocation and dynamic allocation GPIOs are present, > dynamic allocation pollutes the numberspace for static allocation, > causing static allocation to fail. > Enfore dynamic allocation above GPIO_DYNAMIC_BASE. Hum .... Commit 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") was supposed to enforce dynamic allocation above GPIO_DYNAMIC_BASE already. Can you describe what is going wrong exactly with the above commit ? Thanks Christophe > > Seen on a GTA04 when omap-gpio (static) and twl-gpio (dynamic) > raced. > On that device it is fixed invasively by > commit 92bf78b33b0b4 ("gpio: omap: use dynamic allocation of base") > but lets also fix that for devices where there is still > a mixture of static and dynamic allocation. > > Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") > Suggested-by: andy.shevchenko@gmail.com > Signed-off-by: Andreas Kemnade <andreas@kemnade.info> > --- > drivers/gpio/gpiolib.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 19bd23044b017..18b68d0aec7db 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -188,6 +188,10 @@ static int gpiochip_find_base(int ngpio) > int base = GPIO_DYNAMIC_BASE; > > list_for_each_entry(gdev, &gpio_devices, list) { > + /* do not pollute area for static allocation */ > + if (gdev->base < GPIO_DYNAMIC_BASE) > + continue; > + > /* found a free space? */ > if (gdev->base >= base + ngpio) > break; > -- > 2.39.2 >
On Thu, Apr 27, 2023 at 8:40 AM Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > > > > Le 27/04/2023 à 00:03, Andreas Kemnade a écrit : > > [Vous ne recevez pas souvent de courriers de andreas@kemnade.info. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] > > > > If static allocation and dynamic allocation GPIOs are present, > > dynamic allocation pollutes the numberspace for static allocation, > > causing static allocation to fail. > > Enfore dynamic allocation above GPIO_DYNAMIC_BASE. > > Hum .... > > Commit 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") was supposed > to enforce dynamic allocation above GPIO_DYNAMIC_BASE already. > > Can you describe what is going wrong exactly with the above commit ? Above commit only works to the first dynamic allocation, if you need more than one with static ones present it mistakenly will give you a base _below_ DYNAMIC_BASE. However, this change is just PoC I proposed, the conditional and action should be slightly different to cover a corner case, when statically allocated chip overlaps the DYNAMIC_BASE, i.e. gdev->base < DYNAMIC_BASE, while gdev->base + gdev->ngpio >= DYNAMIC_BASE.
Le 27/04/2023 à 08:00, Andy Shevchenko a écrit : > On Thu, Apr 27, 2023 at 8:40 AM Christophe Leroy > <christophe.leroy@csgroup.eu> wrote: >> >> >> >> Le 27/04/2023 à 00:03, Andreas Kemnade a écrit : >>> [Vous ne recevez pas souvent de courriers de andreas@kemnade.info. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] >>> >>> If static allocation and dynamic allocation GPIOs are present, >>> dynamic allocation pollutes the numberspace for static allocation, >>> causing static allocation to fail. >>> Enfore dynamic allocation above GPIO_DYNAMIC_BASE. >> >> Hum .... >> >> Commit 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") was supposed >> to enforce dynamic allocation above GPIO_DYNAMIC_BASE already. >> >> Can you describe what is going wrong exactly with the above commit ? > > Above commit only works to the first dynamic allocation, if you need > more than one with static ones present it mistakenly will give you a > base _below_ DYNAMIC_BASE. Ah right, that needs to be fixed. > > However, this change is just PoC I proposed, the conditional and > action should be slightly different to cover a corner case, when > statically allocated chip overlaps the DYNAMIC_BASE, i.e. gdev->base < > DYNAMIC_BASE, while gdev->base + gdev->ngpio >= DYNAMIC_BASE. > Yes you are right, that's gdev->base + gdev->ngpio that should be checked. Christophe
On Thu, 27 Apr 2023 06:20:34 +0000 Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > Le 27/04/2023 à 08:00, Andy Shevchenko a écrit : > > On Thu, Apr 27, 2023 at 8:40 AM Christophe Leroy > > <christophe.leroy@csgroup.eu> wrote: > >> > >> > >> > >> Le 27/04/2023 à 00:03, Andreas Kemnade a écrit : > >>> [Vous ne recevez pas souvent de courriers de andreas@kemnade.info. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] > >>> > >>> If static allocation and dynamic allocation GPIOs are present, > >>> dynamic allocation pollutes the numberspace for static allocation, > >>> causing static allocation to fail. > >>> Enfore dynamic allocation above GPIO_DYNAMIC_BASE. > >> > >> Hum .... > >> > >> Commit 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") was supposed > >> to enforce dynamic allocation above GPIO_DYNAMIC_BASE already. > >> > >> Can you describe what is going wrong exactly with the above commit ? > > > > Above commit only works to the first dynamic allocation, if you need > > more than one with static ones present it mistakenly will give you a > > base _below_ DYNAMIC_BASE. > > Ah right, that needs to be fixed. > > > > > However, this change is just PoC I proposed, the conditional and > > action should be slightly different to cover a corner case, when > > statically allocated chip overlaps the DYNAMIC_BASE, i.e. gdev->base < > > DYNAMIC_BASE, while gdev->base + gdev->ngpio >= DYNAMIC_BASE. > > > > Yes you are right, that's gdev->base + gdev->ngpio that should be checked. > and that not with simple continue or base might simply stay at DYNAMIC_BASE. I will send a v2 of this patch with refined logic. Regards, Andreas
On Thu, Apr 27, 2023 at 1:37 PM Andreas Kemnade <andreas@kemnade.info> wrote: > > On Thu, 27 Apr 2023 06:20:34 +0000 > Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > > > Le 27/04/2023 à 08:00, Andy Shevchenko a écrit : > > > On Thu, Apr 27, 2023 at 8:40 AM Christophe Leroy > > > <christophe.leroy@csgroup.eu> wrote: > > >> > > >> > > >> > > >> Le 27/04/2023 à 00:03, Andreas Kemnade a écrit : > > >>> [Vous ne recevez pas souvent de courriers de andreas@kemnade.info. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] > > >>> > > >>> If static allocation and dynamic allocation GPIOs are present, > > >>> dynamic allocation pollutes the numberspace for static allocation, > > >>> causing static allocation to fail. > > >>> Enfore dynamic allocation above GPIO_DYNAMIC_BASE. > > >> > > >> Hum .... > > >> > > >> Commit 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") was supposed > > >> to enforce dynamic allocation above GPIO_DYNAMIC_BASE already. > > >> > > >> Can you describe what is going wrong exactly with the above commit ? > > > > > > Above commit only works to the first dynamic allocation, if you need > > > more than one with static ones present it mistakenly will give you a > > > base _below_ DYNAMIC_BASE. > > > > Ah right, that needs to be fixed. > > > > > > > > However, this change is just PoC I proposed, the conditional and > > > action should be slightly different to cover a corner case, when > > > statically allocated chip overlaps the DYNAMIC_BASE, i.e. gdev->base < > > > DYNAMIC_BASE, while gdev->base + gdev->ngpio >= DYNAMIC_BASE. > > > > > > > Yes you are right, that's gdev->base + gdev->ngpio that should be checked. > > > and that not with simple continue or base might simply stay at DYNAMIC_BASE. > > I will send a v2 of this patch with refined logic. Actually it would be nice to integrate a warning (if we don't have it yet) when adding a GPIO chip with a static allocation and which will overlap the dynamic base. Can you add that into your v2?
Le 27/04/2023 à 12:46, Andy Shevchenko a écrit : > On Thu, Apr 27, 2023 at 1:37 PM Andreas Kemnade <andreas@kemnade.info> wrote: >> >> On Thu, 27 Apr 2023 06:20:34 +0000 >> Christophe Leroy <christophe.leroy@csgroup.eu> wrote: >> >>> Le 27/04/2023 à 08:00, Andy Shevchenko a écrit : >>>> On Thu, Apr 27, 2023 at 8:40 AM Christophe Leroy >>>> <christophe.leroy@csgroup.eu> wrote: >>>>> >>>>> >>>>> >>>>> Le 27/04/2023 à 00:03, Andreas Kemnade a écrit : >>>>>> [Vous ne recevez pas souvent de courriers de andreas@kemnade.info. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] >>>>>> >>>>>> If static allocation and dynamic allocation GPIOs are present, >>>>>> dynamic allocation pollutes the numberspace for static allocation, >>>>>> causing static allocation to fail. >>>>>> Enfore dynamic allocation above GPIO_DYNAMIC_BASE. >>>>> >>>>> Hum .... >>>>> >>>>> Commit 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") was supposed >>>>> to enforce dynamic allocation above GPIO_DYNAMIC_BASE already. >>>>> >>>>> Can you describe what is going wrong exactly with the above commit ? >>>> >>>> Above commit only works to the first dynamic allocation, if you need >>>> more than one with static ones present it mistakenly will give you a >>>> base _below_ DYNAMIC_BASE. >>> >>> Ah right, that needs to be fixed. >>> >>>> >>>> However, this change is just PoC I proposed, the conditional and >>>> action should be slightly different to cover a corner case, when >>>> statically allocated chip overlaps the DYNAMIC_BASE, i.e. gdev->base < >>>> DYNAMIC_BASE, while gdev->base + gdev->ngpio >= DYNAMIC_BASE. >>>> >>> >>> Yes you are right, that's gdev->base + gdev->ngpio that should be checked. >>> >> and that not with simple continue or base might simply stay at DYNAMIC_BASE. >> >> I will send a v2 of this patch with refined logic. > > Actually it would be nice to integrate a warning (if we don't have it > yet) when adding a GPIO chip with a static allocation and which will > overlap the dynamic base. Can you add that into your v2? > At the time being we have a warning for all static allocations, allthough their has been some discussion about reverting it, see commit 502df79b8605 ("gpiolib: Warn on drivers still using static gpiobase allocation") Christophe
On Thu, Apr 27, 2023 at 1:55 PM Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > Le 27/04/2023 à 12:46, Andy Shevchenko a écrit : > > On Thu, Apr 27, 2023 at 1:37 PM Andreas Kemnade <andreas@kemnade.info> wrote: > >> On Thu, 27 Apr 2023 06:20:34 +0000 > >> Christophe Leroy <christophe.leroy@csgroup.eu> wrote: ... > >> I will send a v2 of this patch with refined logic. > > > > Actually it would be nice to integrate a warning (if we don't have it > > yet) when adding a GPIO chip with a static allocation and which will > > overlap the dynamic base. Can you add that into your v2? > > > > At the time being we have a warning for all static allocations, > allthough their has been some discussion about reverting it, see commit > 502df79b8605 ("gpiolib: Warn on drivers still using static gpiobase > allocation") Ah, even better! Then no need to have a specific one, thanks!
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 19bd23044b017..18b68d0aec7db 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -188,6 +188,10 @@ static int gpiochip_find_base(int ngpio) int base = GPIO_DYNAMIC_BASE; list_for_each_entry(gdev, &gpio_devices, list) { + /* do not pollute area for static allocation */ + if (gdev->base < GPIO_DYNAMIC_BASE) + continue; + /* found a free space? */ if (gdev->base >= base + ngpio) break;