Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1895271rwd; Wed, 17 May 2023 02:59:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/qoYni6ARmP4+M1r+QsLonUXazmydTwMvb5zSCxVIFYFMysiT9iLIsoHU+scXcjMO7ob/ X-Received: by 2002:a05:6a00:218e:b0:64b:7c1d:518e with SMTP id h14-20020a056a00218e00b0064b7c1d518emr197815pfi.31.1684317592893; Wed, 17 May 2023 02:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684317592; cv=none; d=google.com; s=arc-20160816; b=BtTliG94hnNfTM/DemMdqgT3DU2Db2Ca471pEB5eq/vAGGCja1lacy72oBc2/oCs27 kZwBvEl+bk1waI8nCyxrCIDEXh9J9d3+zJFSfXT7o69gI4OTzYgqxtXlby7zFxxulFZ/ 2NNgZ9deOKmmOOw33Zh3S9Koiw+PH7pJ8GtKLVTaDymrHVNh2VS5K+y6nV9+CMTGVsiW XQQ/EH/sNO6gJz6p50d1X/kQeRCZDx9z98eZv5t5ZmRwDwN3M/Y2p45ZmOG48N7pKkSr j2Z8ZQcdfQZ8VpkggaWFfZEzWkZNLEZ/1k6QtqSG9m7PFyPWULkqtQlpSSVb2dzPBxwQ Ev1w== 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=ukNjPAx9d0iOoRqrYjfOc+/Spp/uHfwiRW0HzoxFUwc=; b=fykIJCTOACj3Qr9a9a9ediq3ltlq1dO3ifg19xOwt13dS9zeeK0TbJ+HeOggHamSjO sdyVsE6VrthYZ1TMMCS0gRk7m0duI21nVMOXqKz5fsgd+F2LZWGs+rKBMWSjxzmB/l/6 fMDuhHGbdqZFGWWM/PlhcKoyD0EjluqH2mfTT0xBBs5vbebnYoVbxMmaXWJAZ8oG7qF1 NzUmFkkVAED0ba6g+G0T+cwPRozdwnx4k+i6tjG9kVKNx8ovzLyqx0kLQkexfXJPelnm Vzeisdjb0bALpzP+fTuhBevsMCzyznlcK9fWqkqRvKAn4SGfX9tRcC3yOtJJkThGSJgH elEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b=34eJpNlt; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020a63f20a000000b0053409545376si7940485pgh.686.2023.05.17.02.59.38; Wed, 17 May 2023 02:59:52 -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=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b=34eJpNlt; 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 S229712AbjEQJrs (ORCPT + 99 others); Wed, 17 May 2023 05:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjEQJrq (ORCPT ); Wed, 17 May 2023 05:47:46 -0400 Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8AF1B3 for ; Wed, 17 May 2023 02:47:45 -0700 (PDT) Received: by mail-ua1-x935.google.com with SMTP id a1e0cc1a2514c-783fb1d02dcso61291241.3 for ; Wed, 17 May 2023 02:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1684316864; x=1686908864; 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=ukNjPAx9d0iOoRqrYjfOc+/Spp/uHfwiRW0HzoxFUwc=; b=34eJpNltFy5r3j7xyweF0m9LhAkBWwY8hKf978OR6oUwTfvXcjvpqgnZ2Ur2j8pthq nstsK4huk4yP8jVdO5Rk82lW8hrHBGAkj2Ecq+dliFLMEc8OUrgZ91GV50Fkup3eH70m dWi0OCdMMmRiNC3qNtARc2n13Uh70kzKexmsSmsVi2u1ZhGE/pf25PWTzF5ISGAXHj61 H9PHh3qFoIjIlCwTs/UbeFGzSzJY1V6QorsWRyO6MxLaXqS8mO4L60K9RiH+O1zNpUGB D0Mx3mEEnVq/yjnGU89BXJHNdVyW3QWP1meUsYALrec4o93fLRD4CU/4Qwwjt2fPtUgy I8fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684316864; x=1686908864; 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=ukNjPAx9d0iOoRqrYjfOc+/Spp/uHfwiRW0HzoxFUwc=; b=dhfSqnIGeDs2AOCNQnUyZ9R8H9NqiYRnosng7PGEkIsu6j8nw6azkwYKnsF327vHrK RQNR5LhI9iJ+l4Olk9+Ef84369y/dyPB8F6ZNK9QzxqbqNiLhST9hVIzPkgwZTnMCx4H hN2/ylMBtxD1xlYYbD65f6hUGcbg9GacVAlBvkDXTxyWgLYoS6mCaQh0/xqgvVdDujMq J/fOzxWJDL0TUyq50Yw8OmI5wUrxuDf1NecNZAAXI2Pelj2qK28K8UwrnH4gWVs8QFD3 L8DeIXoyVi+1KcDrfX4Zd2UvbXAdYuLyzOl8FRJ0AdoAcEM82aV2KQRwv91mDpP7EPdi 4uqQ== X-Gm-Message-State: AC+VfDzT2CSYTvEyy5apS7NiCCQLKidMrAXneNIK7J2had1ZZciuxfie 7jv1YDqLc1s+bf5Av0m9Q7Utk0uGEolREoTRvYl/vA== X-Received: by 2002:a05:6102:519:b0:430:9bc:e82 with SMTP id l25-20020a056102051900b0043009bc0e82mr14914119vsa.34.1684316864120; Wed, 17 May 2023 02:47:44 -0700 (PDT) MIME-Version: 1.0 References: <20230504060421.804168-1-andreas@kemnade.info> In-Reply-To: <20230504060421.804168-1-andreas@kemnade.info> From: Bartosz Golaszewski Date: Wed, 17 May 2023 11:47:33 +0200 Message-ID: Subject: Re: [PATCH v3] gpiolib: fix allocation of mixed dynamic/static GPIOs To: Andreas Kemnade Cc: linus.walleij@linaro.org, christophe.leroy@csgroup.eu, andy.shevchenko@gmail.com, 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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, 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 Thu, May 4, 2023 at 8:04=E2=80=AFAM 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. > Enforce dynamic allocation above GPIO_DYNAMIC_BASE. > > 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 let's 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") > Signed-off-by: Andreas Kemnade > Reviewed-by: > Reviewed-by: Andy Shevchenko > --- > Changes in V3: > typos > > 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 > Queued for fixes, thanks! Bart