Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp333201rwb; Thu, 18 Aug 2022 04:51:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR49Sx9DuVAbUy02JNUL74RHBVfu8YxO7pcW34aSUbGzrTC0cFubLK2LILm1OLjpdcXmykbl X-Received: by 2002:a17:90b:38cb:b0:1f5:2321:63cb with SMTP id nn11-20020a17090b38cb00b001f5232163cbmr8671274pjb.110.1660823505165; Thu, 18 Aug 2022 04:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660823505; cv=none; d=google.com; s=arc-20160816; b=r6RqQvjGnVMC5Hf9VW4YfFQFHc8niXwCoVLu1qWWxkNp00PSM3fQVlprHfsRBJK+Pr eFvoSrm0OjaGRLN4x2mqtqjCFNDBVqtwD9wIO1v7nm/TfNnQYA0pwRwo3yTqEBKabgCa S/T8q2ti1hLD/Skx4zgckP792vB6/1WPdiYQrCdiB+ryfH+Ho6k8BfnmuhmEKZMxe1kp 7M/I96zAzLQjL6x3uCgqp18QgzmyyaCcYWu2dy4aCtNB9T/sAnqqxtc7z5Op1hik+hHb jIse79S60nBZi+ttlaDm4zOY4nPO0O4ihqlzgLCBp/HPuNUk5Xz2YizGzF0LlSiE8SPi Jm3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=w+4+2WtxvO1cqI4byafyu81xZCbJaUxCOsxyNdwBfJI=; b=qProeui3oOCmdb0bnv3oK+3Z2f4+910FJquFDeWcUiPG9Xz85jRsea/MxehPInvW0r Vp2yrWYpbsAxNRmtl2nbUmqRSl6hVwSfSmBWZQn+47VR+nPsYU3/qck86IVD/hxVCwDf IxZILzotl5zZfH9kaWCd9l4Nr9LK+ud4P/UiSFUPoUxa2A/wk7KGJPFlpLREHp5QKu9G zCtVTnSDjgGjayl03slVFHxi+7IcLr13rrWQKbtZht4bz4N4rzGiAdVeQUtHU4c/qzO1 veNZwkeEJW97jw+38piwibnRNhFGH5D2UKriOoJcfgXKHp+OdAjVj+sqgMUZQYJa3Y7p maAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ObRzc2BA; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p19-20020a170902b09300b0016eeb210483si1134437plr.321.2022.08.18.04.51.33; Thu, 18 Aug 2022 04:51:45 -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=@linaro.org header.s=google header.b=ObRzc2BA; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244143AbiHRLNs (ORCPT + 99 others); Thu, 18 Aug 2022 07:13:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244344AbiHRLNp (ORCPT ); Thu, 18 Aug 2022 07:13:45 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45A7DEBB for ; Thu, 18 Aug 2022 04:13:42 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id gb36so2576596ejc.10 for ; Thu, 18 Aug 2022 04:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=w+4+2WtxvO1cqI4byafyu81xZCbJaUxCOsxyNdwBfJI=; b=ObRzc2BAQc6+LGmzsb5py6+CSBSMikoI60uVFFy62jeF+aDW4APgEMWqYHsm7W5OP5 2Z7c9h5e24WRMP68wi6PFroY7Q3m7Wtc3l5ZZCy8xLko9Vwyp5xzoFRUJkuDgQVPp+E3 4YAtzSn44vk8sAdb1OXUoAjOqHf/wX7bWysuruUsigstR4S4U7H1A2761PZAKGJxkKE7 kwg9LFXUHMmx/y9rB0wQEdHRPq6b3KxLbxEmslolKyQckRD3WL2U8gbMuiYc8zil9fCk 2HXLEuH0YTozklKWAUoF2e5ng2cDru7fVp+1BBN0aSYvwIdKoNSqcc6w5+3iF7d2B8iL YTbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=w+4+2WtxvO1cqI4byafyu81xZCbJaUxCOsxyNdwBfJI=; b=fx2SJa+VPASaTzOOOXUORhW4wGQ8/6JajsXwamAEhlJhgXqmTMmLpsLAV5SamCZPES dk+BwIyBlOdOCYdtbQRJxJfr84SRzP3v24/BLry0fQwuDsFfPuowm8H4JbkNATT0D5Tx lHapToTRC5GJP1xTk9F8iCAzfMJGyeT92qSm/34xc0jtbI5KjImSH7ejuH86yKwoDsW1 x9D0OlJuxwLTT1QojRxDjExNpGsKxIIuy4v62qyGVUYa578Gycl2q6X/OdTretE+PKMm AB2rS01Xwtsw3ToFYrr0D0B5uEA9oB46U3Gyhwq7xaMy5ASa3VjnCt1cFclVna8SDYvp 33wA== X-Gm-Message-State: ACgBeo1drWkmc9H1dJkCdZtECvNAbATMgYgQP4q/19AlPrOS5k06zYai Hpim1dd20q5nGDFRbbvZG1klWrYGl6FdVjwJHLONPw== X-Received: by 2002:a17:907:a055:b0:730:a432:99d3 with SMTP id gz21-20020a170907a05500b00730a43299d3mr1473227ejc.690.1660821221116; Thu, 18 Aug 2022 04:13:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Walleij Date: Thu, 18 Aug 2022 13:13:30 +0200 Message-ID: Subject: Re: [PATCH] gpio: Allow user to customise maximum number of GPIOs To: Arnd Bergmann Cc: Christophe Leroy , Bartosz Golaszewski , Jonathan Corbet , Russell King , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:GPIO SUBSYSTEM" , "open list:DOCUMENTATION" , open list , "moderated list:ARM PORT" , "open list:GENERIC INCLUDE/ASM HEADER FILES" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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, Aug 18, 2022 at 11:48 AM Arnd Bergmann wrote: > As I understood, the problem that Christophe ran into is that the > dynamic registration of additional gpio chips is broken because > it unregisters the chip if the number space is exhausted: > > base = gpiochip_find_base(gc->ngpio); > if (base < 0) { > ret = base; > spin_unlock_irqrestore(&gpio_lock, flags); > goto err_free_label; > } > > From the git history, it looks like this error was never handled gracefully > even if the intention was to keep going without a number assignment, > so there are probably other bugs one runs into after changing this. Hm that should be possible to get rid of altogether? I suppose it is only there to satisfy static inline bool gpio_is_valid(int number) { return number >= 0 && number < ARCH_NR_GPIOS; } ? If using GPIO descriptors, any descriptor != NULL is valid, this one is just used with legacy GPIOs. Maybe we should just delete gpio_is_valid() everywhere and then drop the cap? I think there may be systems and users that still depend on GPIO base numbers being assigned from ARCH_NR_GPIOS and downwards (userspace GPIO numbers in sysfs will also change...) otherwise we could assign from 0 and up. Right now the safest would be: Assign from 512 and downwards until we hit 0 then assign from something high, like U32_MAX and downward. That requires dropping gpio_is_valid() everywhere. If we wanna be bold, just delete gpio_is_valid() and assign bases from 0 and see what happens. But I think that will lead to regressions. Yours, Linus Walleij