Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1427500rwr; Wed, 26 Apr 2023 15:08:01 -0700 (PDT) X-Google-Smtp-Source: AKy350Ys+reAI33FuFosHlxYybGIFGIKvIuCu2OzNPb6Ir1oyIOvpwrJh+t3BPt+LU2qMF+CKF/9 X-Received: by 2002:a17:903:2305:b0:1a6:6d1d:bbf4 with SMTP id d5-20020a170903230500b001a66d1dbbf4mr27936366plh.11.1682546881526; Wed, 26 Apr 2023 15:08:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682546881; cv=none; d=google.com; s=arc-20160816; b=pNCukwSubhQv10w4VrjGnnc3UksRB0JfgTi6n7M57V4UQ+/l/s+Llp0mlgzkcDvpiZ 0vG/tF0uXAKOWC26cRo2zdyyrPrytN0PMFQTqAvhf+ba8F/uX1MNohfpwHrVXXamJtjI 7OqGWgSkItBhPWruSR76d8SPd0px07VnNwUJiHuBdggZXqqDjw9ZGhnXPwizEFslxNcw +4KNMsjHC1r4Q16o9PipmJnLRxxMfc7RnDzQ0M/rlbL9rTxHNwpl2iNTrz+6dPP5j8n6 H0UPV8ytLwc9HoZlPPz0e0ay4J2vGpf8je1IBpmNyywFlX3/JFmxl/rzOrPhM33nzAHr sbfA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a170902c9cc00b001a661053de9si16305204pld.293.2023.04.26.15.07.44; Wed, 26 Apr 2023 15:08:01 -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 S239848AbjDZWEZ (ORCPT + 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 ); 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 ) id 1prnFE-0008HC-AR; Thu, 27 Apr 2023 00:04:12 +0200 Received: from andi by aktux with local (Exim 4.96) (envelope-from ) id 1prnFD-001o20-2v; Thu, 27 Apr 2023 00:04:11 +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] 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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