Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3285680rwr; Sat, 29 Apr 2023 04:37:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LXzhPOWmWoEUzYdeL4TaKD7o/5qKM2xganKuTGxlMJWHOeqV0hXwFTF5pQempBizhYUOF X-Received: by 2002:a05:6a20:3d85:b0:f6:d60d:dbfc with SMTP id s5-20020a056a203d8500b000f6d60ddbfcmr7584242pzi.5.1682768243421; Sat, 29 Apr 2023 04:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682768243; cv=none; d=google.com; s=arc-20160816; b=BWGLNa42/Ll/0Zhd1YD/ltwqFGyEEg015FoLIojQNHgCY/VhTbH3hFTHSS+oUzWkWD DmBNXd9++yer6gU7XYheHZiTZzwvl/rylP5dEsGmSH9bTZuH6dKOON8M+Qc4XMn+Z5/C COCzaIxtx5o6ak9/VJIS8wQN+bOJqNtHW++hLOX3m+98mfck3ysmTaCDp+/Oh9wFp8mY xsGyl5KdqcDk6tcUEZQ0+mluvq8OvCZyQucpfdh1Ol8Mqn49JhRF4m6Ek3EpjVsv9wiS Dw8XJO8v87ennv2Nie3ZYvSumxiKjp0DDUlMVhU28XYNwCVkGefJ3zUjFI/oa9F/9WRQ oSNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=HX1/EEyk9xXLvQqBe37n3RdcEO2pLurpeMiD17UTbTs=; b=a9YE54vJChK/Dln6Ey8lWmvXPkA93klOeEDLKio2QP59RkjzlRd1SPgdGvGN7pIVQi A43TVl1q1xH4OO0LVEYQdhdfHsSJqPNRdB3qQZykMbiCDsKEJjrI7S7KdD4mqVimBKu1 j45QZ6i1xlGlW9JjCj642h+/qjfX+BjykqIZkQx1OmPsNBr5ifUGdrYHsEppsz1w9Jxk /KmUX90AfoLQ3pm3YOeU24cjnmite6lCqVNcKBDZQ/XS+j+FfkgOfNTGsTJoWYZUeG8i LuCs/fLgi+2ZrU9QfT4xejQl5hsITp9qi3a+NrpqX/PJ3aBFDNj3rA4b7xqXJ+6iXqDa EZWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=A01Ejd9C; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot7-20020a17090b3b4700b00246f3cb3878si5011395pjb.86.2023.04.29.04.37.03; Sat, 29 Apr 2023 04:37:23 -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=pass header.i=@gmail.com header.s=20221208 header.b=A01Ejd9C; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbjD2LL2 (ORCPT + 99 others); Sat, 29 Apr 2023 07:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjD2LLZ (ORCPT ); Sat, 29 Apr 2023 07:11:25 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6D5C199D; Sat, 29 Apr 2023 04:11:24 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-3ef33f12995so3990511cf.3; Sat, 29 Apr 2023 04:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682766683; x=1685358683; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HX1/EEyk9xXLvQqBe37n3RdcEO2pLurpeMiD17UTbTs=; b=A01Ejd9CB4zCK/Va1s1K9Z4mLmriZnmXBjDLpKj6fIV4PrcL6274UsoTlx6tiGlo3J Tf8ZrKkwUyZCXZ2ib1e2f3OYLkJ9r1bd+2o8yCAfDrwa19X/A6SgRcDDvNafIplVUI/G wkcQuMEwF5/OA6DfXmguDm9+UCXSINPCaGX4RPhMltWMNVVkVdvwPDJ+yDc9q0sqMZl5 XCkQkEx0v+NuWenON0zkoehMeiiGB4JKtfNIdNskU5t8Rv0CImwPWaC9jsKQBpV7Yx6b etfBZszSLR8XTJj28tLU4QX3BbQ4GfLTv8SLy05D1P92vJ5bVuFhfufGXyAUWDQPxntV nkIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682766683; x=1685358683; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HX1/EEyk9xXLvQqBe37n3RdcEO2pLurpeMiD17UTbTs=; b=dhnYe1b2HIuy58vCOemkHR3I08mK5N7vvDwHs5TZieU7BczI9MbBThEnTTi7vVQK50 1R+4VDzvFxdB6ZcNsiGNAwnZPr2KqzAAmfeV5a5aNwFySeQsIQoi0dEwYen6gZ6C2jPa gTUdxDv/sOP4vMc5JZ2ueykrptQo4gqNqNgu8e5EhTu/krv9U7iAYRIqxqQa8woKATtY U40N18Mx70BYQCesCsNwr+ptB+hs2LDAXR5MsOuTQvm+hejmIfw7npn1QIFXM8x7OehX fh9dRrSrYq3HpLCt97m6jb8ol7cQTeOH1iLSx5Bn5uCDMyz496S3FMfcrZCjtavXt1ad mzpQ== X-Gm-Message-State: AC+VfDySn0tgF+pgvlO1w9Jv4iJy7DlYm3ilkjS4Iw6FEsbDP7SDK0zf VuCCtnuGtR26R5977460wt4f3W3FNHZ+cxW257g= X-Received: by 2002:ac8:57c4:0:b0:3f2:f11:76e0 with SMTP id w4-20020ac857c4000000b003f20f1176e0mr2451809qta.1.1682766683215; Sat, 29 Apr 2023 04:11:23 -0700 (PDT) MIME-Version: 1.0 References: <20230428194541.510674-1-andreas@kemnade.info> In-Reply-To: <20230428194541.510674-1-andreas@kemnade.info> From: Andy Shevchenko Date: Sat, 29 Apr 2023 14:10:46 +0300 Message-ID: Subject: Re: [PATCH v2] gpiolib: fix allocation of mixed dynamic/static GPIOs To: Andreas Kemnade Cc: linus.walleij@linaro.org, brgl@bgdev.pl, christophe.leroy@csgroup.eu, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Tony Lindgren , Aaro Koskinen , linux-omap@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 28, 2023 at 10:45=E2=80=AFPM Andreas Kemnade wrote: > > 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. Enforce > Seen on a GTA04 when omap-gpio (static) and twl-gpio (dynamic) > raced: > [some successful registrations of omap_gpio instances] > [ 2.553833] twl4030_gpio twl4030-gpio: gpio (irq 145) chaining IRQs 16= 1..178 > [ 2.561401] gpiochip_find_base: found new base at 160 > [ 2.564392] gpio gpiochip5: (twl4030): added GPIO chardev (254:5) > [ 2.564544] gpio gpiochip5: registered GPIOs 160 to 177 on twl4030 > [...] > [ 2.692169] omap-gpmc 6e000000.gpmc: GPMC revision 5.0 > [ 2.697357] gpmc_mem_init: disabling cs 0 mapped at 0x0-0x1000000 > [ 2.703643] gpiochip_find_base: found new base at 178 > [ 2.704376] gpio gpiochip6: (omap-gpmc): added GPIO chardev (254:6) > [ 2.704589] gpio gpiochip6: registered GPIOs 178 to 181 on omap-gpmc > [...] > [ 2.840393] gpio gpiochip7: Static allocation of GPIO base is deprecat= ed, use dynamic allocation. > [ 2.849365] gpio gpiochip7: (gpio-160-191): GPIO integer space overlap= , cannot add chip > [ 2.857513] gpiochip_add_data_with_key: GPIOs 160..191 (gpio-160-191) = failed to register, -16 > [ 2.866149] omap_gpio 48310000.gpio: error -EBUSY: Could not register = gpio chip > > 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 let's > a mixture of static and dynamic allocation. It might be that it can be optimized, but OK for now. Thanks for fixing it. Reviewed-by: Andy Shevchenko > Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") > Signed-off-by: Andreas Kemnade > --- > Changes in V2: > handle also the case of overlapping static allocation > across DYNAMIC_BASE > > drivers/gpio/gpiolib.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 19bd23044b017..4472214fcd43a 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -193,6 +193,8 @@ static int gpiochip_find_base(int ngpio) > break; > /* nope, check the space right after the chip */ > base =3D gdev->base + gdev->ngpio; > + if (base < GPIO_DYNAMIC_BASE) > + base =3D GPIO_DYNAMIC_BASE; > } > > if (gpio_is_valid(base)) { > -- > 2.39.2 > --=20 With Best Regards, Andy Shevchenko