From patchwork Thu May 4 06:04:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Kemnade X-Patchwork-Id: 89924 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp85011vqo; Wed, 3 May 2023 23:07:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kkGNy1NPDslU+fMtaQPUF3CMj7Y31kG0qNrAXFOT49IhF2E2QUstiCinM1DAGF0bR12Jj X-Received: by 2002:a05:6a00:1252:b0:63d:3aed:44fb with SMTP id u18-20020a056a00125200b0063d3aed44fbmr1432934pfi.21.1683180455715; Wed, 03 May 2023 23:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683180455; cv=none; d=google.com; s=arc-20160816; b=CTuoiia5hM45KyPYFJ3yAAFWS5USkw9b4aIW0o1303Rg0K7au7YoGITz+bezRqPedg JsEQaeIwXlgnkIHBsJRBHTfzQNEc0iQRJ5GrIMn1ofPa7LwVTUe1JZmnmeGZV7jJ65pU nRcNlJXbvjl8tepcycKALfj/w9QHfPqt0WzCEcXTHUae3RRihPNEI9uCWEBRlESJxAGi zIYOZMODGVKKcC5rTVR30qUmkwGAVSyzuKyWlIhwjrtfqpL/7FNDelNY5UhTo/Ioj2ee e5y5HyN4vce0ChiM+61rkHS2GV3w/ym5e6rlHkZhI06atGNdCEtxhy+utfuYdRhOoSZ0 EGpw== 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=yJ77h21arVzofepbkIoYut2Go9+A93qkebZbDt34MiQ=; b=OK5JUeIacc+oi9YTGUMv2Lg3nIdUAzZhsimV1W5Epd+64jyTO/Ts6LcD0v/4eCT+Q1 Y3XpLlK0ka0N/s7BIMMkw8GUu7EXGAkxtFmZsSOhFIf2yMhIieoXX6LA+PdtxSpP8zWv fJ3j+w6/5ii+x3nmADxTGhKf/Bgy+tE6CmGeSthBrFHD4A3skSFnqauiinHkjqpUsSDm m2np/jPPxnGC7M+asij0vmLy/VeKh1ENkiXGSgtYuhMrv2xE5b/+wEeAy5+XT6TXan8w qsIWObfyiu1lvllZWVoYOpvbBi2LCMZDE6FPWWLqI7qSZ7gi4ge8YhQvTpvyBAuO5X/h FamA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20220719 header.b=hALYOdPl; 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 f85-20020a623858000000b006437ddddd2asi1208094pfa.362.2023.05.03.23.07.22; Wed, 03 May 2023 23:07:35 -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=hALYOdPl; 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 S229696AbjEDGEw (ORCPT + 99 others); Thu, 4 May 2023 02:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjEDGEu (ORCPT ); Thu, 4 May 2023 02:04:50 -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 E59941FFB; Wed, 3 May 2023 23:04:46 -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=yJ77h21arVzofepbkIoYut2Go9+A93qkebZbDt34MiQ=; b=hALYOdPlt6C4E/QeA2BWscfwow OCdj2wlfQOSvVckJRoL+1OsIzTT8PYs9+9nFe7ZjyVLUU9dmXNhB3T68QS9GJjdYIA2MLuEHfUI3b WWQ8XSs2T+orWlezSk8ND+qIkaEukm4UE6tHvwiDw8vVHIm4VfGxRfNgAIAQCX2aAlR3BLnhQyzs8 XtLkzhN8ekZCY4WcR57PGqjdAKstrTKVsOWRg7VSWJ3nKvZOf3dTi3SYFILFE/0hC46QHLc59ZAQW Youo5E7ixgsq1+S4Hlk1vNXY6OUC1DWSWtQ88sEBfiXyohxKRJRkUWGusTaj6SZcaA145SOQolzD4 y+QCzWIg==; Received: from p200300ccff0d59001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:ff0d:5900: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 ) id 1puS4v-0008W0-Fm; Thu, 04 May 2023 08:04:33 +0200 Received: from andi by aktux with local (Exim 4.96) (envelope-from ) id 1puS4v-003NCf-09; Thu, 04 May 2023 08:04:33 +0200 From: Andreas Kemnade 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 , Aaro Koskinen , linux-omap@vger.kernel.org Cc: Andreas Kemnade Subject: [PATCH v3] gpiolib: fix allocation of mixed dynamic/static GPIOs Date: Thu, 4 May 2023 08:04:21 +0200 Message-Id: <20230504060421.804168-1-andreas@kemnade.info> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764942629372423191?= X-GMAIL-MSGID: =?utf-8?q?1764942629372423191?= 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 161..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 deprecated, 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 Reviewed-by: Linus Walleij --- 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 = gdev->base + gdev->ngpio; + if (base < GPIO_DYNAMIC_BASE) + base = GPIO_DYNAMIC_BASE; } if (gpio_is_valid(base)) {