Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5636001pxb; Thu, 20 Jan 2022 01:10:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxuXK5i6cNoQ4LZxA8kndos/GjdLwe6EUd9T0l95azZCsgVriVPcV3GylfRldcq6x262O3X X-Received: by 2002:a17:902:b687:b0:149:90e2:8687 with SMTP id c7-20020a170902b68700b0014990e28687mr37927324pls.131.1642669840303; Thu, 20 Jan 2022 01:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642669840; cv=none; d=google.com; s=arc-20160816; b=BrdOxLHhCSvx0fxAk43fXDa9ObFfFal8g8t3eanp32BJ1QPIWwZwCKMLZhrJIfI3G3 SCsklKqfr+nfngoxrzc/wlgZlLEH+BUwLw+/4gQYMdiHnTcEMgDkuuhOc+eE+mj5g1RA kntzKqstjePpY/+abOzfHoiYIVVNCjCSScJUj3JPNeLs5XuYV1PghLiWQwKYftc4dQ3j ZC6CQe9GVffNm8xem663yo/C7Bx8C7pVfKt35YnYCmSOnX1Od2bL2blRe92ru2Ka2YIC Gy3dMaSoYngGhFX197R/LPyRV9BZy1eF6n/8M1yQbkUKWElNJwwNJirhXTR/XO8VdODp Ha+w== 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=i+RIDedsAjWRTYMYfuby2KPCcBtObXvQPLI+vSiEi4Y=; b=OxmjI+uk1n+CpTqxPjzkLrQwmpunL2Agc6d478XIxomumT3X4kbtTvKQtxSMRuNAX0 cnrv3d942HRT3xHwfInSQznBj/wl2Oenok7Re4bwQgee88irZZAvN3Z07KJxEonvw58h 32rScnOpFunZcRjbHYaLB82XK6rZKs1cqkZQ0VhPe2U5K66pwkk+KpSAboQA0N31CaC3 dCyW5IVPCiUw14kYyIrAUSLJBy9r9j+7pgD8VATLKjn7K3mv4b0KbvPWjQQamtYj0AtI Fj7sJvMiP4pR071dFI6GKN4Lxg7FCsbSjphrq1FNbWRBfq19DV1FpbTX91ypJCMFc1Md 9Y7w== 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 e29si2878352pge.123.2022.01.20.01.10.27; Thu, 20 Jan 2022 01:10:40 -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 S239868AbiARMtf convert rfc822-to-8bit (ORCPT + 99 others); Tue, 18 Jan 2022 07:49:35 -0500 Received: from mail-ua1-f49.google.com ([209.85.222.49]:35487 "EHLO mail-ua1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235104AbiARMtb (ORCPT ); Tue, 18 Jan 2022 07:49:31 -0500 Received: by mail-ua1-f49.google.com with SMTP id m90so36320088uam.2; Tue, 18 Jan 2022 04:49:29 -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=iDNGF1VjVomGlE1aVlmhPbvwByegTECQGcsrxubfQG0=; b=W/7+KwcQIFe8k9do6GnoupOVJaOKBdiP+MrAUzGwizq4jkG1DvOd/PQS8vg7vJJvPe 8C5XbpuNcDb8ZlT+gBIZGaYfLBDaASe9KEv2NsKpjpF2tRaZ+Zuud8NIJms2l4qkzLAx XMv9JWaVH9cGPKjKWYMq/5DePXPe+QcRDbfM7E/Ty5DHg2hX3jTvc+WkxeBZAwkUGvve QRei+gV7soYC+7p6+3G6d1wC+bgK5TkBu1QySj3AJkSRF2gvILWYsUQfNeBdCNFetwxb 1YNiYjF+yFkbraOPVF38W15G82u/rOkTNnSpQ0FS+TlAQ0nrg9CvT8YPJTzh++cG9Tv2 lZ5A== X-Gm-Message-State: AOAM531I+1ECNNQTj+97N5eGsVOavtQ4zTarjbORuoCQFkwudfNUGeEL ykKgZwG8KROlSfpcRJvFjxNtHdQQD6iLJ4YM X-Received: by 2002:a05:6102:ecf:: with SMTP id m15mr8610496vst.68.1642510169047; Tue, 18 Jan 2022 04:49:29 -0800 (PST) Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com. [209.85.222.46]) by smtp.gmail.com with ESMTPSA id p14sm3586095uad.20.2022.01.18.04.49.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jan 2022 04:49:27 -0800 (PST) Received: by mail-ua1-f46.google.com with SMTP id c36so36154877uae.13; Tue, 18 Jan 2022 04:49:27 -0800 (PST) X-Received: by 2002:a05:6102:3581:: with SMTP id h1mr9266907vsu.5.1642510166831; Tue, 18 Jan 2022 04:49:26 -0800 (PST) MIME-Version: 1.0 References: <20220117092444.opoedfcf5k5u6otq@pengutronix.de> <20220117114923.d5vajgitxneec7j7@pengutronix.de> <20220117170609.yxaamvqdkivs56ju@pengutronix.de> <20220118090913.pjumkq4zf4iqtlha@pengutronix.de> <20220118120806.pbjsat4ulg3vnhsh@pengutronix.de> In-Reply-To: <20220118120806.pbjsat4ulg3vnhsh@pengutronix.de> From: Geert Uytterhoeven Date: Tue, 18 Jan 2022 13:49:15 +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: 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 , Miquel Raynal , linux-phy@lists.infradead.org, linux-spi , Jiri Slaby , "David S. Miller" , Khuong Dinh , Florian Fainelli , Matthias Schiffer , Kamal Dasu , Greg Kroah-Hartman , 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 , netdev , "open list:GPIO SUBSYSTEM" , Cornelia Huck , Linux MMC List , Joakim Zhang , Linux Kernel Mailing List , Linux-Renesas , Sergey Shtylyov , Vinod Koul , James Morse , Zha Qipeng , Sebastian Reichel , =?UTF-8?Q?Niklas_S=C3=B6derlund?= , linux-mediatek@lists.infradead.org, Brian Norris , Yoshihiro Shimoda 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 Tue, Jan 18, 2022 at 1:08 PM Uwe Kleine-König wrote: > On Tue, Jan 18, 2022 at 10:37:25AM +0100, Geert Uytterhoeven wrote: > > On Tue, Jan 18, 2022 at 10:09 AM Uwe Kleine-König > > wrote: > > > For the (clk|gpiod|regulator)_get_optional() you don't have to check > > > against the magic not-found value (so no implementation detail magic > > > leaks into the caller code) and just pass it to the next API function. > > > (And my expectation would be that if you chose to represent not-found by > > > (void *)66 instead of NULL, you won't have to adapt any user, just the > > > framework internal checks. This is a good thing!) > > > > Ah, there is the wrong assumption: drivers sometimes do need to know > > if the resource was found, and thus do need to know about (void *)66, > > -ENODEV, or -ENXIO. I already gave examples for IRQ and clk before. > > I can imagine these exist for gpiod and regulator, too, as soon as > > you go beyond the trivial "enable" and "disable" use-cases. > > My premise is that every user who has to check for "not found" > explicitly should not use (clk|gpiod)_get_optional() but > (clk|gpiod)_get() and do proper (and explicit) error handling for > -ENODEV. (clk|gpiod)_get_optional() is only for these trivial use-cases. > > > And 0/NULL vs. > 0 is the natural check here: missing, but not > > an error. > > For me it it 100% irrelevant if "not found" is an error for the query > function or not. I just have to be able to check for "not found" and > react accordingly. > > And adding a function > > def platform_get_irq_opional(): > ret = platform_get_irq() > if ret == -ENXIO: > return 0 > return ret > > it's not a useful addition to the API if I cannot use 0 as a dummy > because it doesn't simplify the caller enough to justify the additional > function. > > The only thing I need to be able is to distinguish the cases "there is > an irq", "there is no irq" and anything else is "there is a problem I > cannot handle and so forward it to my caller". The semantic of > platform_get_irq() is able to satisfy this requirement[1], so why introduce > platform_get_irq_opional() for the small advantage that I can check for > not-found using > > if (!irq) > > instead of > > if (irq != -ENXIO) > > ? The semantic of platform_get_irq() is easier ("Either a usable > non-negative irq number or a negative error number") compared to > platform_get_irq_optional() ("Either a usable positive irq number or a > negative error number or 0 meaning not found"). Usage of > platform_get_irq() isn't harder or more expensive (neither for a human > reader nor for a maching running the resulting compiled code). > For a human reader > > if (irq != -ENXIO) > > is even easier to understand because for > > if (!irq) > > they have to check where the value comes from, see it's > platform_get_irq_optional() and understand that 0 means not-found. "vIRQ zero does not exist." > This function just adds overhead because as a irq framework user I have > to understand another function. For me the added benefit is too small to > justify the additional function. And you break out-of-tree drivers. > These are all no major counter arguments, but as the advantage isn't > major either, they still matter. > > Best regards > Uwe > > [1] the only annoying thing is the error message. So there's still a need for two functions. 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