@@ -500,14 +500,25 @@ EXPORT_SYMBOL_GPL(platform_get_irq_byname);
* @name: IRQ name
*
* Get an optional IRQ by name like platform_get_irq_byname(). Except that it
- * does not print an error message if an IRQ can not be obtained.
+ * does not print an error message if an IRQ can not be obtained and returns
+ * 0 when IRQ resource has not been found.
*
- * Return: non-zero IRQ number on success, negative error number on failure.
+ * Return: non-zero IRQ number on success, 0 if IRQ wasn't found, negative error
+ * number on failure.
*/
int platform_get_irq_byname_optional(struct platform_device *dev,
const char *name)
{
- return __platform_get_irq_byname(dev, name);
+ int ret;
+
+ ret = __platform_get_irq_byname(dev, name);
+ if (ret == -ENXIO)
+ return 0;
+ if (ret < 0)
+ return dev_err_probe(&dev->dev, ret, "IRQ %s not found\n",
+ name);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(platform_get_irq_byname_optional);
@@ -224,7 +224,7 @@ static int lima_init_ip(struct lima_device *dev, int index)
if (irq_name) {
err = must ? platform_get_irq_byname(pdev, irq_name) :
platform_get_irq_byname_optional(pdev, irq_name);
- if (err < 0)
+ if (err <= 0)
goto out;
ip->irq = err;
}
@@ -667,7 +667,7 @@ static int tegra_hsp_probe(struct platform_device *pdev)
hsp->num_si = (value >> HSP_nSI_SHIFT) & HSP_nINT_MASK;
err = platform_get_irq_byname_optional(pdev, "doorbell");
- if (err >= 0)
+ if (err > 0)
hsp->doorbell_irq = err;
if (hsp->num_si > 0) {
@@ -687,7 +687,7 @@ static int tegra_hsp_probe(struct platform_device *pdev)
return -ENOMEM;
err = platform_get_irq_byname_optional(pdev, name);
- if (err >= 0) {
+ if (err > 0) {
hsp->shared_irqs[i] = err;
count++;
}
@@ -1772,7 +1772,7 @@ static int rcar_canfd_probe(struct platform_device *pdev)
if (chip_id == RENESAS_RCAR_GEN3) {
ch_irq = platform_get_irq_byname_optional(pdev, "ch_int");
- if (ch_irq < 0) {
+ if (ch_irq <= 0) {
/* For backward compatibility get irq by index */
ch_irq = platform_get_irq(pdev, 0);
if (ch_irq < 0)
@@ -1780,7 +1780,7 @@ static int rcar_canfd_probe(struct platform_device *pdev)
}
g_irq = platform_get_irq_byname_optional(pdev, "g_int");
- if (g_irq < 0) {
+ if (g_irq <= 0) {
/* For backward compatibility get irq by index */
g_irq = platform_get_irq(pdev, 1);
if (g_irq < 0)
@@ -420,7 +420,7 @@ static int b53_srab_irq_enable(struct b53_device *dev, int port)
/* Interrupt is optional and was not specified, do not make
* this fatal
*/
- if (p->irq == -ENXIO)
+ if (!p->irq)
return ret;
ret = request_threaded_irq(p->irq, b53_srab_port_isr,
@@ -3941,7 +3941,7 @@ fec_probe(struct platform_device *pdev)
for (i = 0; i < irq_cnt; i++) {
snprintf(irq_name, sizeof(irq_name), "int%d", i);
irq = platform_get_irq_byname_optional(pdev, irq_name);
- if (irq < 0)
+ if (irq <= 0)
irq = platform_get_irq(pdev, i);
if (irq < 0) {
ret = irq;
@@ -611,7 +611,7 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx)
INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep);
irq = platform_get_irq_byname_optional(pdev, "pps");
- if (irq < 0)
+ if (irq <= 0)
irq = platform_get_irq_optional(pdev, irq_idx);
/* Failure to get an irq is not fatal,
* only the PTP_CLOCK_PPS clock events should stop
@@ -342,7 +342,7 @@ static int stm32mp1_parse_data(struct stm32_dwmac *dwmac,
if (dwmac->irq_pwr_wakeup == -EPROBE_DEFER)
return -EPROBE_DEFER;
- if (!dwmac->clk_eth_ck && dwmac->irq_pwr_wakeup >= 0) {
+ if (!dwmac->clk_eth_ck && dwmac->irq_pwr_wakeup > 0) {
err = device_init_wakeup(&pdev->dev, true);
if (err) {
dev_err(&pdev->dev, "Failed to init wake up irq\n");
@@ -426,7 +426,7 @@ static int stm32_dwmac_remove(struct platform_device *pdev)
stm32_dwmac_clk_disable(priv->plat->bsp_priv);
- if (dwmac->irq_pwr_wakeup >= 0) {
+ if (dwmac->irq_pwr_wakeup > 0) {
dev_pm_clear_wake_irq(&pdev->dev);
device_init_wakeup(&pdev->dev, false);
}
@@ -679,7 +679,7 @@ int stmmac_get_platform_resources(struct platform_device *pdev,
*/
stmmac_res->wol_irq =
platform_get_irq_byname_optional(pdev, "eth_wake_irq");
- if (stmmac_res->wol_irq < 0) {
+ if (stmmac_res->wol_irq <= 0) {
if (stmmac_res->wol_irq == -EPROBE_DEFER)
return -EPROBE_DEFER;
dev_info(&pdev->dev, "IRQ eth_wake_irq not found\n");
@@ -688,7 +688,7 @@ int stmmac_get_platform_resources(struct platform_device *pdev,
stmmac_res->lpi_irq =
platform_get_irq_byname_optional(pdev, "eth_lpi");
- if (stmmac_res->lpi_irq < 0) {
+ if (stmmac_res->lpi_irq <= 0) {
if (stmmac_res->lpi_irq == -EPROBE_DEFER)
return -EPROBE_DEFER;
dev_info(&pdev->dev, "IRQ eth_lpi not found\n");
@@ -364,7 +364,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
} else if (pp->has_msi_ctrl) {
if (!pp->msi_irq) {
pp->msi_irq = platform_get_irq_byname_optional(pdev, "msi");
- if (pp->msi_irq < 0) {
+ if (pp->msi_irq <= 0) {
pp->msi_irq = platform_get_irq(pdev, 0);
if (pp->msi_irq < 0)
return pp->msi_irq;
@@ -1627,7 +1627,7 @@ int bcm_qspi_probe(struct platform_device *pdev,
irq = platform_get_irq(pdev, 0);
}
- if (irq >= 0) {
+ if (irq > 0) {
ret = devm_request_irq(&pdev->dev, irq,
qspi_irq_tab[val].irq_handler, 0,
name,
@@ -1355,16 +1355,16 @@ static int rspi_probe(struct platform_device *pdev)
ctlr->max_native_cs = rspi->ops->num_hw_ss;
ret = platform_get_irq_byname_optional(pdev, "rx");
- if (ret < 0) {
+ if (ret <= 0) {
ret = platform_get_irq_byname_optional(pdev, "mux");
- if (ret < 0)
+ if (ret <= 0)
ret = platform_get_irq(pdev, 0);
- if (ret >= 0)
+ if (ret > 0)
rspi->rx_irq = rspi->tx_irq = ret;
} else {
rspi->rx_irq = ret;
ret = platform_get_irq_byname(pdev, "tx");
- if (ret >= 0)
+ if (ret > 0)
rspi->tx_irq = ret;
}
@@ -110,10 +110,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
if (cdns->wakeup_irq == -EPROBE_DEFER)
return cdns->wakeup_irq;
- else if (cdns->wakeup_irq == 0)
- return -EINVAL;
-
- if (cdns->wakeup_irq < 0) {
+ if (cdns->wakeup_irq <= 0) {
dev_dbg(dev, "couldn't get wakeup irq\n");
cdns->wakeup_irq = 0x0;
}
@@ -493,7 +493,7 @@ static int xhci_mtk_probe(struct platform_device *pdev)
return ret;
irq = platform_get_irq_byname_optional(pdev, "host");
- if (irq < 0) {
+ if (irq <= 0) {
if (irq == -EPROBE_DEFER)
return irq;
@@ -925,7 +925,7 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb)
return -ENOMEM;
mtu->irq = platform_get_irq_byname_optional(pdev, "device");
- if (mtu->irq < 0) {
+ if (mtu->irq <= 0) {
if (mtu->irq == -EPROBE_DEFER)
return mtu->irq;
Currently platform_get_irq_byname_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_byname_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_byname_optional(...); if (ret < 0) return ret; if (ret > 0) ...we get an IRQ... Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru> --- Changes in version 2: - added the error check using dev_err_probe() to platform_get_irq_byname_optional(); - reformatted the patch description. drivers/base/platform.c | 17 ++++++++++++++--- drivers/gpu/drm/lima/lima_device.c | 2 +- drivers/mailbox/tegra-hsp.c | 4 ++-- drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/dsa/b53/b53_srab.c | 2 +- drivers/net/ethernet/freescale/fec_main.c | 2 +- drivers/net/ethernet/freescale/fec_ptp.c | 2 +- .../net/ethernet/stmicro/stmmac/dwmac-stm32.c | 4 ++-- .../ethernet/stmicro/stmmac/stmmac_platform.c | 4 ++-- .../pci/controller/dwc/pcie-designware-host.c | 2 +- drivers/spi/spi-bcm-qspi.c | 2 +- drivers/spi/spi-rspi.c | 8 ++++---- drivers/usb/cdns3/cdns3-plat.c | 5 +---- drivers/usb/host/xhci-mtk.c | 2 +- drivers/usb/mtu3/mtu3_core.c | 2 +- 15 files changed, 35 insertions(+), 27 deletions(-)