Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp335979rwb; Thu, 18 Aug 2022 04:55:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR6amJOTujpZfJIoIFv9UspTu++Kj9ZOcRVl0AmIXXlHhWTZzMWCNuU+8X+YNIscOcDKEVtw X-Received: by 2002:a17:907:7212:b0:733:1ada:e413 with SMTP id dr18-20020a170907721200b007331adae413mr1710441ejc.309.1660823723106; Thu, 18 Aug 2022 04:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660823723; cv=none; d=google.com; s=arc-20160816; b=yQIgJYpn7w2YbPy5GYjVKehKhAnbbnVes9OYxVgYV1XqpwK3iz5uwXBduvxA8mXYWD vx9iKIYh60rndYed+XB/CZGKPPNcyuFoC5V3BISS3ZR90ZiUb2pTJRSyK2uq3ZeeJrV6 bn17khsScB/d0Sa7w5s+lwwdfEO2wel/iHqrIDmo/d0SgbU05Ms6c8DjH3gpDAWIWGvy OzMfS2NzXeDCWHmJIqCNTAGMGpEXoUWeMXSG5fKl6FXqFjfVvVhpc7Joed7NMHCC4OpI Z+zobv4Ho6xn0T0vqDlScXJUd8nlwHqDQPpqWXzi4hg87UwE2fd7Hida+bzljYjW5tpe zd+g== 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=4M9gODws8fJuPEKMDFm90JSf7f5fwyCLoTk1kkqtJUc=; b=d274Q0c/VEPofu6NGZSq7rS7JQJE1zDrL2P+dMGYLnrJXF2rPxtaf6zD+A+/YjcT2N 7q8xdU5cNVOQKAwYlY4YRzKXbc8XLqUvGCeGxNccQSL/ItXqS1ggv4p7e0BV+msvFn4i XrONV0Me/JcTDWHIUu3zn3+FRWABRvh6ZrZsY8Vq/o7qomYWlEht65ZBQY10/LuWDa49 WNgavFLWD+rJMMxy1YRVYB7ZA248/Tq5xhETFg9gr1/ykpb4GzU3L+zmwRfVzQ39kVNi TOgH0Hy/reXLfHYCjKAj5lq51XIvEwCdRZXkm5Rsaf3abDvC+PF0zDsTizqz2TMpwM59 h+pw== 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 di22-20020a170906731600b007385dfb42c7si1157593ejc.565.2022.08.18.04.54.56; Thu, 18 Aug 2022 04:55:23 -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 S243310AbiHRLdw (ORCPT + 99 others); Thu, 18 Aug 2022 07:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242812AbiHRLdt (ORCPT ); Thu, 18 Aug 2022 07:33:49 -0400 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DABE3056E; Thu, 18 Aug 2022 04:33:45 -0700 (PDT) Received: from mail-ed1-f45.google.com ([209.85.208.45]) by mrelayeu.kundenserver.de (mreue108 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MQ5jC-1o2jCy0J04-00M0Nd; Thu, 18 Aug 2022 13:33:44 +0200 Received: by mail-ed1-f45.google.com with SMTP id o22so1481947edc.10; Thu, 18 Aug 2022 04:33:43 -0700 (PDT) X-Gm-Message-State: ACgBeo0LA6OTlTOzwYBCT0zRZNxmc1I89GNc3t8Cn8bU+Aj2/PszAkRd BtojenxZIV9sHG2iyfnBiTQ6Rsn4RMhAYyPSD3I= X-Received: by 2002:a05:6402:100c:b0:43d:9009:c705 with SMTP id c12-20020a056402100c00b0043d9009c705mr1899100edu.49.1660822423668; Thu, 18 Aug 2022 04:33:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Arnd Bergmann Date: Thu, 18 Aug 2022 13:33:27 +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 , 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-Provags-ID: V03:K1:95I9ezHVKVDbn3HOR+SFddx176GWYmwMKPyfPS8w7IJt0Ovjonj vN9OR3ThzzhefCH/osd+Ew0A+/Lb3AcdGuNtdDfOTb0PhuPlRP5f1HBXRMMD+bvXppOal/e sLc87/riigluhRf/XH1VOe3duyHHdefjOhZ33kewQBQQ83/7cgk5ccIsI7e4BCp+u7NL+SK qDBDTgJnmQ129Ow/SzvOQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:LXImiQGnzd8=:z7yJnYGfeVJtVi47ei09eQ 0QfSniCCi3j/0Mf0DuhQxiSBctkH6LCPBmFsNCiNaTV9xRVkg/FOLVLdva6lIPtmIC+P5ZoYq RKAT9A0qek25xh287aTcyQG1pR3pOEC0WzyEyQhvAGbpDcBueNq4NiHBKOWtv9YNv/LMNrjrV yKrAfDwBoIcwGQwR4mzzQ4qQzUPuNM00Pm8O+8qi8OP1Z29ILoJkzpcV4du/wkQa30aAah8Y6 /imo9vY44OwhbDP6DcdiRZ1Jd41u9GH0reqy5aesbEaul0ndmlU0nJbDmAi+TXY1uZhfrSHUr 4r6ejOx0yhUF7KZ93GBoIKQRR5Q0bzPAFP46YBTy0kgw/XgZoTBBj3sc3RZC0CL0fHVaZiTUn n0thJ1uyS21e3Ds+HbDzJkdolHK7LJXCqfMQNjLTXCbXp/cakojR3oIXM2SPDdJUROsuudErk 3AxNqqZ2kbMy3XMCbh/C6QqNhZUQXUULr1INnCOI5I1XT4lkCU3iOzgrZhh+oaImNG4pTMkb9 dHIhTTZJBCNjpSzACWBx7xIPBUVbx97HQdQgS0camT4sgF/SY0g2xNlErz7PahW3dmNKVR90S 9WWU5P9rhBnD3NfzgixXCh+WhwsO39y2MH/SWkGjjmay6pcR1g2MCK2NyJ0mbUr1gifftnQOh F0LUCrUyPALHQkkRyOwvX8Yo6Ce3Ypu3LkakWNgshJJcrv919g3wevT2enpSQnG5Nh+cF4XJM tUKtW5HcwwSoax653kgzs2Bu5I/XVZiG2RRPBQ== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 1:13 PM Linus Walleij wrote: > > 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 it makes sense to keep gpio_is_valid() for as long as we support the numbers. > 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. Even for the sysfs interface, it is questionable to rely on specific numbers because at least in an arm multiplatform kernel the top number changes based on kernel configuration. > 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. What I could imagine as a next step would be to mark all consumer drivers and the sysfs interface that use gpio numbers as 'depends on GPIO_LEGACY' and then only provide the corresponding drivers if that option is set. After that, we could try to make sure we can run the defconfigs for modern architectures (arm64, riscv, x86-64, ...) without the option by converting the drivers that are most commonly used. Arnd