Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2967404pxb; Mon, 17 Jan 2022 09:09:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxjicxLtGBrYSnWAxhQztvWXv2/ZuyxsPW6yikQKCjFCgXMymDn5YlQTCDNcWFqH1ae6p8 X-Received: by 2002:a17:90b:384d:: with SMTP id nl13mr26088345pjb.46.1642439351180; Mon, 17 Jan 2022 09:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642439351; cv=none; d=google.com; s=arc-20160816; b=yRYlAdQkG5wWz5JT2V5cHPp3mPnHxC0VYphdjXdjUL6zjjIC5L/No8TNh8tLyFKEH1 4c+/118Pfdt2hySD/utB8pv114uSWj7pOXS23UrNrOEuUG6TROoKllhAChORMQZVHn3+ bYbesn1OONTJ/MklIKx/NMs5oHU02SKhP5V2yj44vX6mpgFcZLnPWu9H+hoFjCDyruQh sXfm8hWw8lmDa+tbygH6Q5hNFW9jFY5NtTPMnAFXh/ItHnPi9beqGAkGhBjz7lCpKpDK 7nQ2r/QYHOshXjeXzdc2MqZoAiDaP6zAfNHT0IAAqsYaRwzpUuehvmhlwjONGeYzdRwf b1qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=H85s9THB2AknX6skJHxqyoj7lW+BvATNQc15EZZieLE=; b=EQrSpu2Wr91ZMpvWYL4JLzXPWw4N9AK7yNsyEDRXxMtgLR3E/9qFuTQAXK+7+jcvTL Kzr0J3wBeztQAoiI5txCSmscB9rTCj5SJ4prI+OkLW872ic+MrKYnA+WpDYoAXSzO6ks 9SlsnIridy/ooCaNdp73zexAvjr7RlJthISy1rsiLWaq5vzG2/wctSLR9MKkGygPzFUy UcH8PO9RVGETcFTN2gRRiL6ZS4vnZZ3RcCzClXoFuYzmM89ZxNkJAGFO69nf/WINggOe zlr1/hAh/z3X+LGvDd8F3PniqPkH74/T6WZY1n8/UWF+AGhYKHMt8qBGfrTK/0TFgdqr rKsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v9si15586750pgs.302.2022.01.17.09.08.58; Mon, 17 Jan 2022 09:09:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238642AbiAQKgK convert rfc822-to-8bit (ORCPT + 99 others); Mon, 17 Jan 2022 05:36:10 -0500 Received: from mail-vk1-f178.google.com ([209.85.221.178]:44866 "EHLO mail-vk1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235751AbiAQKgI (ORCPT ); Mon, 17 Jan 2022 05:36:08 -0500 Received: by mail-vk1-f178.google.com with SMTP id b77so10050961vka.11; Mon, 17 Jan 2022 02:36:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=8wbyaDOKHzyncR/a8atHHiwf57S6QrlnXekhvOqZ5Zc=; b=LSqfAKSEMaEAYGbunuoNsuAo80Rk3bWRnbog4vmP3JZLEh9uYSltN70uJc84BpJSr7 JJnirAVOJlzWKyDEIR2Diay0j4XTt0t62ENC9pifrHEO7FBWiHhHxuDK1WzAc8e6ELXR kQ9mlj4U0HJfB2+KW8z5oG8eumwZ7pBma/5Dw/MfcUBQY6urYwF8smbH7H3q2qCyOWnZ WMftrgtX96eKLAO99UHB4hY/TEZK/0NkFFeXjMqVUQZMRIBvb4IgC5k585TkQC90Pjjl OCO4TUh6V49qlC5LMsMRqBmcDWSn9b1oJydqBYMjT6BdgJQWG8UIu4fo3Rdo+xKpbYJ/ vCYw== X-Gm-Message-State: AOAM5305tSrFltxA7gBSd0tqguB9hBRHUBFEH4OLNLs0dzL4jrmjEiQD BXv/dJZDl/cDrQpuSMLa9PFd1Pet6ZxLZku3 X-Received: by 2002:a1f:2c54:: with SMTP id s81mr4062257vks.38.1642415766251; Mon, 17 Jan 2022 02:36:06 -0800 (PST) Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com. [209.85.222.45]) by smtp.gmail.com with ESMTPSA id b14sm3226412vkk.22.2022.01.17.02.36.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Jan 2022 02:36:04 -0800 (PST) Received: by mail-ua1-f45.google.com with SMTP id c36so29466451uae.13; Mon, 17 Jan 2022 02:36:04 -0800 (PST) X-Received: by 2002:ab0:4d42:: with SMTP id k2mr5738849uag.78.1642415764003; Mon, 17 Jan 2022 02:36:04 -0800 (PST) MIME-Version: 1.0 References: <20220112085009.dbasceh3obfok5dc@pengutronix.de> <20220112213121.5ruae5mxwj6t3qiy@pengutronix.de> <29f0c65d-77f2-e5b2-f6cc-422add8a707d@omp.ru> <20220114092557.jrkfx7ihg26ekzci@pengutronix.de> <61b80939-357d-14f5-df99-b8d102a4e1a1@omp.ru> <20220114202226.ugzklxv4wzr6egwj@pengutronix.de> <20220117092444.opoedfcf5k5u6otq@pengutronix.de> In-Reply-To: <20220117092444.opoedfcf5k5u6otq@pengutronix.de> From: Geert Uytterhoeven Date: Mon, 17 Jan 2022 11:35:52 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] platform: make platform_get_irq_optional() optional To: =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= Cc: Sergey Shtylyov , Andrew Lunn , Ulf Hansson , Vignesh Raghavendra , KVM list , "Rafael J. Wysocki" , linux-iio@vger.kernel.org, Linus Walleij , Amit Kucheria , ALSA Development Mailing List , Jaroslav Kysela , Guenter Roeck , Thierry Reding , MTD Maling List , Linux I2C , "open list:GPIO SUBSYSTEM" , Miquel Raynal , linux-phy@lists.infradead.org, netdev , linux-spi , Jiri Slaby , Khuong Dinh , Florian Fainelli , Matthias Schiffer , Kamal Dasu , Lee Jones , Bartosz Golaszewski , Daniel Lezcano , Kishon Vijay Abraham I , bcm-kernel-feedback-list , "open list:SERIAL DRIVERS" , Jakub Kicinski , Zhang Rui , platform-driver-x86@vger.kernel.org, Linux PWM List , Robert Richter , Saravanan Sekar , Corey Minyard , Linux PM list , Liam Girdwood , Mauro Carvalho Chehab , John Garry , Peter Korsgaard , William Breathitt Gray , Mark Gross , Hans de Goede , Alex Williamson , Mark Brown , Borislav Petkov , Takashi Iwai , Matthias Brugger , openipmi-developer@lists.sourceforge.net, Andy Shevchenko , Benson Leung , Pengutronix Kernel Team , Linux ARM , linux-edac@vger.kernel.org, Tony Luck , Richard Weinberger , Mun Yew Tham , Eric Auger , Greg Kroah-Hartman , Yoshihiro Shimoda , Cornelia Huck , Linux MMC List , Joakim Zhang , Linux Kernel Mailing List , Linux-Renesas , Vinod Koul , James Morse , Zha Qipeng , Sebastian Reichel , =?UTF-8?Q?Niklas_S=C3=B6derlund?= , linux-mediatek@lists.infradead.org, Brian Norris , "David S. Miller" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Uwe, On Mon, Jan 17, 2022 at 10:24 AM Uwe Kleine-König wrote: > On Mon, Jan 17, 2022 at 09:41:42AM +0100, Geert Uytterhoeven wrote: > > On Sat, Jan 15, 2022 at 9:22 PM Sergey Shtylyov wrote: > > > On 1/14/22 11:22 PM, Uwe Kleine-König wrote: > > > > You have to understand that for clk (and regulator and gpiod) NULL is a > > > > valid descriptor that can actually be used, it just has no effect. So > > > > this is a convenience value for the case "If the clk/regulator/gpiod in > > > > question isn't available, there is nothing to do". This is what makes > > > > clk_get_optional() and the others really useful and justifies their > > > > existence. This doesn't apply to platform_get_irq_optional(). > > > > > > I do understand that. However, IRQs are a different beast with their > > > own justifications... > > > > > > clk_get_optional() is sane and sensible for cases where the clk might be > > > > absent and it helps you because you don't have to differentiate between > > > > "not found" and "there is an actual resource". > > > > > > > > The reason for platform_get_irq_optional()'s existence is just that > > > > platform_get_irq() emits an error message which is wrong or suboptimal > > > > > > I think you are very wrong here. The real reason is to simplify the > > > callers. > > > > Indeed. > > The commit that introduced platform_get_irq_optional() said: > > Introduce a new platform_get_irq_optional() that works much like > platform_get_irq() but does not output an error on failure to > find the interrupt. > > So the author of 8973ea47901c81a1912bd05f1577bed9b5b52506 failed to > mention the real reason? Or look at > 31a8d8fa84c51d3ab00bf059158d5de6178cf890: > > [...] use platform_get_irq_optional() to get second/third IRQ > which are optional to avoid below error message during probe: > [...] > > Look through the output of > > git log -Splatform_get_irq_optional > > to find several more of these. Commit 8973ea47901c81a1 ("driver core: platform: Introduce platform_get_irq_optional()") and the various fixups fixed the ugly printing of error messages that were not applicable. In hindsight, probably commit 7723f4c5ecdb8d83 ("driver core: platform: Add an error message to platform_get_irq*()") should have been reverted instead, until a platform_get_irq_optional() with proper semantics was introduced. But as we were all in a hurry to kill the non-applicable error message, we went for the quick and dirty fix. > Also I fail to see how a caller of (today's) platform_get_irq_optional() > is simpler than a caller of platform_get_irq() given that there is no > semantic difference between the two. Please show me a single > conversion from platform_get_irq to platform_get_irq_optional that > yielded a simplification. That's exactly why we want to change the latter to return 0 ;-) > So you need some more effort to convince me of your POV. > > > Even for clocks, you cannot assume that you can always blindly use > > the returned dummy (actually a NULL pointer) to call into the clk > > API. While this works fine for simple use cases, where you just > > want to enable/disable an optional clock (clk_prepare_enable() and > > clk_disable_unprepare()), it does not work for more complex use cases. > > Agreed. But for clks and gpiods and regulators the simple case is quite > usual. For irqs it isn't. It is for devices that can have either separate interrupts, or a single multiplexed interrupt. The logic in e.g. drivers/tty/serial/sh-sci.c and drivers/spi/spi-rspi.c could be simplified and improved (currently it doesn't handle deferred probe) if platform_get_irq_optional() would return 0 instead of -ENXIO. > And if you cannot blindly use the dummy, then you're not the targetted > caller of *_get_optional() and should better use *_get() and handle > -ENODEV explicitly. No, because the janitors tend to consolidate error message handling, by moving the printing up, inside the *_get() methods. That's exactly what happened here. So there are three reasons: because the absence of an optional IRQ is not an error, and thus that should not cause (a) an error code to be returned, and (b) an error message to be printed, and (c) because it can simplify the logic in device drivers. Commit 8973ea47901c81a1 ("driver core: platform: Introduce platform_get_irq_optional()") fixed (b), but didn't address (a) and (c). Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds