Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2974393pxb; Mon, 17 Jan 2022 09:16:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyADRSxxpqtm8dTjloel4lI/S5bq95vAfmWeiolkdOXGovQDn2XtHOewU2kluUhI+6jzuQO X-Received: by 2002:a05:6a00:1946:b0:44d:8136:a4a4 with SMTP id s6-20020a056a00194600b0044d8136a4a4mr22211124pfk.46.1642439783929; Mon, 17 Jan 2022 09:16:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642439783; cv=none; d=google.com; s=arc-20160816; b=VQ4ixfsMahfyI4OE5Z5VUUt5gqyEZOjHUDnwRXyj8D1YsqOZFtE/YxpoaMiadwWdjq 0v5LEZUvI87nhEMHL75s2HlE+fJlD/1L1pdF92AmpeFzCSK2A7l8Rqwkue+V60EzQDir PQijdoQlM4lN1n/Udk1nCH2ZfK1VDX8eahTgiADwmEszR2z2Tb1xzYU3muNjYYbHaqPR Oy9Tub8Pf9D/No97FJpBJAPQAhnF3F+F8wlmIgYEcjZDUKZJBu9St+k6AD0VltUk3s80 kUu/02OaunIgoxI0luDJzhgiCO2RsDx3zO04CqKeCcviJFQvLBTQg0hH1wnR9rht+kNj sgEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :references:cc:to:from:subject:dkim-filter; bh=pWpvLqA4BttbG6rhALhTw2tCeQeWwMbIlUpLhQ1GMEc=; b=IvUK7N0uft+Akqlxb6aBMoVTVVtj/eFVOKVX8c0Q4t5FPsM4CQObAXjsDJ49+7llRG LdscT+eGYY4RNHs71eatwUOjI48JwxGMwrfQ7bkx8D0y36Q60hdwciP0CLlMA9B2kspz sKL+XnWGJ/XQjZPIXvyhKUiFjiakuUw+DguVri4+kgkD2Uh3m0suE5drFtj74kR8r/R9 atoY7Iw0ZN3Uy1DZ4bgvCfPjchHJz8B0bOrIYClKl/Wrr00gHa1dh28bFVnUug1DEBY5 MF4rYoWches4IVH1PfkhHieE9qvAJ6mXdD1lFeq7NKOKTOKLxPgHL0cTeBn96svgUIio N4QA== 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 y9si14111939pgh.275.2022.01.17.09.16.11; Mon, 17 Jan 2022 09:16:23 -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 S235700AbiAQL5o (ORCPT + 99 others); Mon, 17 Jan 2022 06:57:44 -0500 Received: from mxout01.lancloud.ru ([45.84.86.81]:47210 "EHLO mxout01.lancloud.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231510AbiAQL5l (ORCPT ); Mon, 17 Jan 2022 06:57:41 -0500 Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout01.lancloud.ru 2ADB220E0F3B Received: from LanCloud Received: from LanCloud Received: from LanCloud Subject: Re: [PATCH 1/2] platform: make platform_get_irq_optional() optional From: Sergey Shtylyov To: Greg Kroah-Hartman , "Rafael J. Wysocki" , CC: Andy Shevchenko , Corey Minyard , Pengutronix Kernel Team , "William Breathitt Gray" , Khuong Dinh , Borislav Petkov , "Mauro Carvalho Chehab" , Tony Luck , "James Morse" , Robert Richter , Mun Yew Tham , Linus Walleij , "Bartosz Golaszewski" , Thierry Reding , =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , Lee Jones , Kamal Dasu , Florian Fainelli , , "Peter Korsgaard" , Andrew Lunn , Ulf Hansson , Brian Norris , "Miquel Raynal" , Richard Weinberger , Vignesh Raghavendra , "David S. Miller" , Jakub Kicinski , Joakim Zhang , Yoshihiro Shimoda , Kishon Vijay Abraham I , Vinod Koul , Benson Leung , "Guenter Roeck" , Zha Qipeng , Hans de Goede , Mark Gross , Saravanan Sekar , Sebastian Reichel , John Garry , Mark Brown , Matthias Brugger , =?UTF-8?Q?Niklas_S=c3=b6derlund?= , Daniel Lezcano , Amit Kucheria , Zhang Rui , Jiri Slaby , Eric Auger , Alex Williamson , Cornelia Huck , "Liam Girdwood" , Jaroslav Kysela , "Takashi Iwai" , , , , , , , , , , , , , , , , , , , , Matthias Schiffer References: <20220110195449.12448-1-s.shtylyov@omp.ru> <20220110195449.12448-2-s.shtylyov@omp.ru> Organization: Open Mobile Platform Message-ID: <770fb569-03c8-78f9-c174-94b31e866017@omp.ru> Date: Mon, 17 Jan 2022 14:57:32 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20220110195449.12448-2-s.shtylyov@omp.ru> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT02.lancloud.ru (fd00:f066::142) To LFEX1907.lancloud.ru (fd00:f066::207) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/10/22 10:54 PM, Sergey Shtylyov wrote: > This patch is based on the former Andy Shevchenko's patch: > > https://lore.kernel.org/lkml/20210331144526.19439-1-andriy.shevchenko@linux.intel.com/ > > Currently platform_get_irq_optional() returns an error code even if IRQ > resource simply has not been found. It prevents the callers from being > error code agnostic in their error handling: > > ret = platform_get_irq_optional(...); > if (ret < 0 && ret != -ENXIO) > return ret; // respect deferred probe > if (ret > 0) > ...we get an IRQ... > > All other *_optional() APIs seem to return 0 or NULL in case an optional > resource is not available. Let's follow this good example, so that the > callers would look like: > > ret = platform_get_irq_optional(...); > if (ret < 0) > return ret; > if (ret > 0) > ...we get an IRQ... > > Reported-by: Matthias Schiffer > Signed-off-by: Sergey Shtylyov [...] Please don't merge this as yet, I'm going thru this patch once again and have already found some sloppy code. :-/ > diff --git a/drivers/char/ipmi/bt-bmc.c b/drivers/char/ipmi/bt-bmc.c > index 7450904e330a..fdc63bfa5be4 100644 > --- a/drivers/char/ipmi/bt-bmc.c > +++ b/drivers/char/ipmi/bt-bmc.c > @@ -382,12 +382,14 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc, > bt_bmc->irq = platform_get_irq_optional(pdev, 0); > if (bt_bmc->irq < 0) > return bt_bmc->irq; > + if (!bt_bmc->irq) > + return 0; Hm, this is sloppy. Will recast and rebase to the -next branch. > > rc = devm_request_irq(dev, bt_bmc->irq, bt_bmc_irq, IRQF_SHARED, > DEVICE_NAME, bt_bmc); > if (rc < 0) { > dev_warn(dev, "Unable to request IRQ %d\n", bt_bmc->irq); > - bt_bmc->irq = rc; > + bt_bmc->irq = 0; This change isn't needed... > return rc; > } > [...] > diff --git a/drivers/edac/xgene_edac.c b/drivers/edac/xgene_edac.c > index 2ccd1db5e98f..0d1bdd27cd78 100644 > --- a/drivers/edac/xgene_edac.c > +++ b/drivers/edac/xgene_edac.c > @@ -1917,7 +1917,7 @@ static int xgene_edac_probe(struct platform_device *pdev) > > for (i = 0; i < 3; i++) { > irq = platform_get_irq_optional(pdev, i); Is *_optinal() even correct here? > - if (irq < 0) { > + if (irq <= 0) { > dev_err(&pdev->dev, "No IRQ resource\n"); > rc = -EINVAL; > goto out_err; [...] > diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c > index f75929783b94..ac222985efde 100644 > --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c > +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c > @@ -1521,7 +1521,7 @@ static irqreturn_t brcmnand_ctlrdy_irq(int irq, void *data) > > /* check if you need to piggy back on the ctrlrdy irq */ > if (ctrl->edu_pending) { > - if (irq == ctrl->irq && ((int)ctrl->edu_irq >= 0)) > + if (irq == ctrl->irq && ((int)ctrl->edu_irq > 0)) Note to self: the cast to *int* isn't needed, the edu_irq field is *int* already... [...] > diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/mp2629_charger.c > index bdf924b73e47..51289700a7ac 100644 > --- a/drivers/power/supply/mp2629_charger.c > +++ b/drivers/power/supply/mp2629_charger.c > @@ -581,9 +581,9 @@ static int mp2629_charger_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, charger); > > irq = platform_get_irq_optional(to_platform_device(dev->parent), 0); Again, is *_optional() even correct here? > - if (irq < 0) { > + if (irq <= 0) { > dev_err(dev, "get irq fail: %d\n", irq); > - return irq; > + return irq < 0 ? irq : -ENXIO; > } > > for (i = 0; i < MP2629_MAX_FIELD; i++) { [...] > diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c > index 43eb25b167bc..776cfed4339c 100644 > --- a/drivers/thermal/rcar_gen3_thermal.c > +++ b/drivers/thermal/rcar_gen3_thermal.c > @@ -430,7 +430,7 @@ static int rcar_gen3_thermal_request_irqs(struct rcar_gen3_thermal_priv *priv, > > for (i = 0; i < 2; i++) { > irq = platform_get_irq_optional(pdev, i); > - if (irq < 0) > + if (irq <= 0) > return irq; Sloppy code again? We shouldn't return 0... [...] > diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c > index 68a1c87066d7..cd7494933563 100644 > --- a/drivers/vfio/platform/vfio_platform.c > +++ b/drivers/vfio/platform/vfio_platform.c > @@ -32,8 +32,12 @@ static struct resource *get_platform_resource(struct vfio_platform_device *vdev, > static int get_platform_irq(struct vfio_platform_device *vdev, int i) > { > struct platform_device *pdev = (struct platform_device *) vdev->opaque; > + int ret; > > - return platform_get_irq_optional(pdev, i); > + ret = platform_get_irq_optional(pdev, i); > + if (ret < 0) > + return ret; > + return ret > 0 ? ret : -ENXIO; Could be expressed more concisely: return ret ? : -ENXIO; just like vfio_amba.c does it... [...] MBR, Sergey