Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp401725rwb; Thu, 18 Aug 2022 06:02:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR59bvLO59YFrTvEs7lETUMeh4VvV443+6426BtKEf7S91GxTsmk/UAieYWO/8XgjzXhSprV X-Received: by 2002:a17:90b:3502:b0:1f3:550:5f6f with SMTP id ls2-20020a17090b350200b001f305505f6fmr3065651pjb.49.1660827763032; Thu, 18 Aug 2022 06:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660827763; cv=none; d=google.com; s=arc-20160816; b=s6RJb5Y+riuIhWhVIUMAEbGpmd+hkIhfWLEilR7PTgUyXKOpIDzFoUz5HjcntDE4oh nIbV0xLNbLdVxq1mPhFUuMCLlqBCC35r4fVT2OuSJ2MU7ym9FPVQ0nI8/aHJvi7hBQot Rx7mftIbj3hAf4X0bbpgXgpMI80wtk40HbzA3pSn1j0d3LnsAgIoujXgutQUDfTajHTr cGBoBc+27awXxCsTBA2XrwBR0/9YB7RCCDg7G/f7RIbblJzrmPPl55ExGxDDKxRGWupQ qOue3PH72JnPbaVq0qtB1WqcafM8Op8b/SHdUfTbWho08s+e3yb9qtzb2xoYJ+frxl8J BPwA== 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; bh=YyvXFOUbByvgmVSH1DuLiSDanNp7d0xnsFOUPcCaU6s=; b=Kd/9Rt8SQ5e4jdxREZSUrdBxlyOuIsk2o9thZ/LJqH5z/bXHLBJiqe8THLYMhpxkp5 WZRP24MaHqb31s2nMFfS0EVHxcTfQ2U4mhuYt2FGU9DrOoZ/RIwxEtT9T4zQgpFyIQeD 5VojaUiNay+IcZD9LxQajvEMNpJmxyk3pkjAgykUWPwQJlRNRJ8oygb0fmzV8w9nHGUq OYYk2e1dHQW5aqEGuGy8xLJ5hIaVUdpiKDlP3D/zkG1RJzJ7t32bIzH8ugLtf3YLSsaK m/PPFNKQIfe9oV72X7i9dU9D56uVeF8WfIDENjU72xPxIMunyu3uLxEYMdn37PNGHygA ridQ== ARC-Authentication-Results: i=1; mx.google.com; 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 c5-20020a170902c1c500b0016f063c3ea1si1227140plc.30.2022.08.18.06.02.28; Thu, 18 Aug 2022 06:02:43 -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; 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 S244722AbiHRMqq (ORCPT + 99 others); Thu, 18 Aug 2022 08:46:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234545AbiHRMqn (ORCPT ); Thu, 18 Aug 2022 08:46:43 -0400 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B86863F1C; Thu, 18 Aug 2022 05:46:41 -0700 (PDT) Received: from mail-ej1-f43.google.com ([209.85.218.43]) by mrelayeu.kundenserver.de (mreue009 [213.165.67.97]) with ESMTPSA (Nemesis) id 1MjSHa-1ne1cT2zaE-00ktfs; Thu, 18 Aug 2022 14:46:39 +0200 Received: by mail-ej1-f43.google.com with SMTP id k26so3032059ejx.5; Thu, 18 Aug 2022 05:46:39 -0700 (PDT) X-Gm-Message-State: ACgBeo1ybL2Q4+wz0EbQeEvpfRQdylmlOBKKOPovtWxDQ6FbRkmT/eyn OT6ydmJ1Za/ntTFwOxBk4MkixivpAm0S4NabdOg= X-Received: by 2002:a17:906:9b08:b0:730:5d3c:4b1b with SMTP id eo8-20020a1709069b0800b007305d3c4b1bmr1815183ejc.606.1660826799268; Thu, 18 Aug 2022 05:46:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Arnd Bergmann Date: Thu, 18 Aug 2022 14:46:23 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] gpio: Allow user to customise maximum number of GPIOs To: Linus Walleij Cc: Arnd Bergmann , Alexandre Courbot , Alexandre Courbot , Bartosz Golaszewski , Christophe Leroy , 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-Provags-ID: V03:K1:OvzLXBF3uV/pdjl/yQRKrMC60QpaRL30ffyZ7v9t+Egjlgirm6n t2fRgwr6EWZR33HevfB9Opi3AmARtAgu2YIZ+G3RmLZcPwEPMQmuWpt+byxUkn3Y9QwhCgF UYg6GLcuUEneD9jtQ09bHlGlpnSKbvxUAGT1+en8znfkNYUoUxSPa2+Sm2TnJ5/CNEz/54Z QK2I8HKoEZX6vkXJ7jeTw== X-UI-Out-Filterresults: notjunk:1;V03:K0:U5E2Uc/ZWZQ=:3vRPqZW5tIpN4aAjeBi9Y3 9q8cK7HQktqAtjGrxOdrTJpWjLU4WZf/naR/M3NlFZ2H69cc2ihTem45VFN1Nl+AYf0soHKwR zu/H179lXz+SqNolxViGPemc/YG36PamQ/qV+iqXrJImJb5DogPAg6g0e5qe9EJc6M3Rr6iCC gNE8lfOs4S9qmuaFUxwVzVMEYwjPp1CZru5wwkEUI6avWM6QHZCdpIGQ/IIW3Lcm7L1KOM5fE s1ovxp8917i91advl1fYt1vH632tnNEBESofhPuQOZQRsY4N12PGuJZ8nQ/2FA42PCSRhp9ia iOFQP2h4kYzPSqCulP8bzlRaCAjSraG/86KENAVO+K5bH1naRrSOidKg4eLboXlDae5g0qBSN 1pbin1or/k87a4bZ6fIc4BAARapIWLNQMakAmPpW3jq1FkMqIbLngHxiS7lc9PJZweg884pJj +fi8WsxwBvazRX6wYpamq9PrvNGaxJxAvjw9B3wfIATgjfsZHRkbfBluQmbnQEsVjIT3B2Oil yeicBP8DqNPB/4QtKu2qChpQLth3m6w6MrL1+xylkVDRXVVsarwjqRcqr5Zr03T3qnU8ZM5V6 EYvDWZDA4nDoF/zyuLiGMAX/Jo/JZ615ufvcCMqJS3nX0G+hzHGKxDmDRvppQ3LBWEiEGswXk 4rmJk8lNAiS25ORd4wRrs5Oza0DJzmpfWYlqB3H7xTd6CxvYDydhD6jZXTlwQOkldbu37Ku6U 5ijnDjFNfFxXTz/QlhSs6UZ6Oig4IX7nRqGtONrE2ppBIsTQjKaXnNOd1i+dWjGwa0hS2OJmb tTcUheDooJDjiXAhQRSUt+1oAsq5AOKjnZYp9GGOSl+HOHFwkk79C3asPdCAnM8QJEsHLtJ61 wrRlWR+g+2Uwi0xmcfYdxwbjSbjS1HsKwU++xfz6OT06XmvdvjUJIKZAjBm0xA8NMmre8OtTR MFn4z/vVdng8lkp40jW9ay8cu6WegD7l+D9KsJ6c877PNm+7T1YGv X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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, Aug 18, 2022 at 2:25 PM Linus Walleij wrote: > On Thu, Aug 18, 2022 at 1:33 PM Arnd Bergmann wrote: > > On Thu, Aug 18, 2022 at 1:13 PM Linus Walleij wrote: > > > 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. > > > > Is it possible to find in-kernel users that depend on well-known > > numbers for dynamically assigned gpios? I would argue > > that those are always broken. > > Most in-kernel users hard-code the base to something like > 0 etc it's only the ones that code -1 into .base that are in > trouble because that will activate dynamic assignment for the > base. > > git grep 'base = -1' yields these suspects: > > arch/arm/common/sa1111.c: sachip->gc.base = -1; > arch/arm/common/scoop.c: devptr->gpio.base = -1; > arch/powerpc/platforms/52xx/mpc52xx_gpt.c: gpt->gc.base = -1; > arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c: gc->base = -1; > > That's all! We could just calculate these to 512-ngpios and > hardcode that instead. How do the consumers find the numbers for these four? > > > 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. > > > > I'm still unsure how removing gpio_is_valid() would help. > > If we allow GPIO base all the way to U32_MAX > this function becomes: > > static inline bool gpio_is_valid(int number) > { > return number >= 0 && number < U32_MAX; > } > > and we can then just > > #define gpio_is_valid true > > and in that case it is better to delete the use of this function > altogether since it can not fail. S32_MAX might be a better upper bound. That allows to just have no number assigned to a gpio chip. Any driver code calling desc_to_gpio() could then get back -1 or a negative error code. Making the ones that are invalid today valid sounds like a step backwards to me if the goal is to stop using gpio numbers and most consumers no longer need them. Arnd