mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] treewide: make use of PTR_ERR_OR_ZERO
@ 2020-06-24 13:58 Uwe Kleine-König
  2020-06-26  8:20 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2020-06-24 13:58 UTC (permalink / raw)
  To: barebox

PTR_ERR_OR_ZERO is designed to replace boiler plate like:

	if (IS_ERR(x))
		return PTR_ERR(x);
	return 0;

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c |  4 +---
 arch/arm/boards/karo-tx28/tx28-stk5.c         |  4 +---
 common/globalvar.c                            |  5 +----
 common/serdev.c                               |  5 +----
 drivers/mfd/rave-sp.c                         |  5 +----
 drivers/mtd/ubi/eba.c                         | 12 +++---------
 drivers/net/designware_generic.c              |  5 +----
 drivers/pci/pci-tegra.c                       |  5 +----
 drivers/pwm/core.c                            |  5 +----
 drivers/usb/otg/otgdev.c                      |  5 +----
 drivers/watchdog/rave-sp-wdt.c                |  5 +----
 11 files changed, 13 insertions(+), 47 deletions(-)

diff --git a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
index 9dc5967bd93e..b12bb0dd79fb 100644
--- a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
+++ b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
@@ -79,9 +79,7 @@ static int register_persistent_environment(void)
 	/* use the full partition as our persistent environment storage */
 	cdev = devfs_add_partition("disk0.1", 0, cdev->size,
 						DEVFS_PARTITION_FIXED, "env0");
-	if (IS_ERR(cdev))
-		return PTR_ERR(cdev);
-	return 0;
+	return PTR_ERR_OR_ZERO(cdev);
 }
 
 static int mx23_evk_devices_init(void)
diff --git a/arch/arm/boards/karo-tx28/tx28-stk5.c b/arch/arm/boards/karo-tx28/tx28-stk5.c
index 838754d042ab..c9b947953bb2 100644
--- a/arch/arm/boards/karo-tx28/tx28-stk5.c
+++ b/arch/arm/boards/karo-tx28/tx28-stk5.c
@@ -333,9 +333,7 @@ static int register_persistent_environment(void)
 	/* use the full partition as our persistent environment storage */
 	cdev = devfs_add_partition("disk0.1", 0, cdev->size,
 					DEVFS_PARTITION_FIXED, "env0");
-	if (IS_ERR(cdev))
-		return PTR_ERR(cdev);
-	return 0;
+	return PTR_ERR_OR_ZERO(cdev);
 }
 
 static void tx28_get_ethaddr(void)
diff --git a/common/globalvar.c b/common/globalvar.c
index c87f2c933904..98a028a68aa7 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -563,10 +563,7 @@ int globalvar_add_simple_bitmask(const char *name, unsigned long *value,
 	p = dev_add_param_bitmask(&global_device, name, NULL, NULL,
 		value, names, max, NULL);
 
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(p);
 }
 
 int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
diff --git a/common/serdev.c b/common/serdev.c
index c50b3bd26acb..4bf11b161892 100644
--- a/common/serdev.c
+++ b/common/serdev.c
@@ -84,10 +84,7 @@ int serdev_device_open(struct serdev_device *serdev)
 	p = dev_add_param_uint64(serdev->dev, "polling_interval",
 				 serdev_device_set_polling_interval, NULL,
 				 &serdev->polling_interval, "%llu", serdev);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(p);
 }
 
 unsigned int serdev_device_set_baudrate(struct serdev_device *serdev,
diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
index c6ad57d517dc..8fc46b66bb2c 100644
--- a/drivers/mfd/rave-sp.c
+++ b/drivers/mfd/rave-sp.c
@@ -787,10 +787,7 @@ static int rave_sp_add_params(struct rave_sp *sp)
 
 	p = dev_add_param_ip(dev, "netmask", NULL, rave_sp_req_ip_addr,
 			     &sp->netmask, sp);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(p);
 }
 
 static int rave_sp_probe(struct device_d *dev)
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index cca6ec4ba915..071bbca236e9 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -324,9 +324,7 @@ static int leb_read_lock(struct ubi_device *ubi, int vol_id, int lnum)
 	struct ubi_ltree_entry *le;
 
 	le = ltree_add_entry(ubi, vol_id, lnum);
-	if (IS_ERR(le))
-		return PTR_ERR(le);
-	return 0;
+	return PTR_ERR_OR_ZERO(le);
 }
 
 /**
@@ -362,9 +360,7 @@ static int leb_write_lock(struct ubi_device *ubi, int vol_id, int lnum)
 	struct ubi_ltree_entry *le;
 
 	le = ltree_add_entry(ubi, vol_id, lnum);
-	if (IS_ERR(le))
-		return PTR_ERR(le);
-	return 0;
+	return PTR_ERR_OR_ZERO(le);
 }
 
 /**
@@ -383,9 +379,7 @@ static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
 	struct ubi_ltree_entry *le;
 
 	le = ltree_add_entry(ubi, vol_id, lnum);
-	if (IS_ERR(le))
-		return PTR_ERR(le);
-	return 0;
+	return PTR_ERR_OR_ZERO(le);
 }
 
 /**
diff --git a/drivers/net/designware_generic.c b/drivers/net/designware_generic.c
index 809c7b7b69e6..90fca1951d88 100644
--- a/drivers/net/designware_generic.c
+++ b/drivers/net/designware_generic.c
@@ -21,10 +21,7 @@ static int dwc_ether_probe(struct device_d *dev)
 	struct dw_eth_dev *dwc;
 
 	dwc = dwc_drv_probe(dev);
-	if (IS_ERR(dwc))
-		return PTR_ERR(dwc);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(dwc);
 }
 
 static __maybe_unused struct of_device_id dwc_ether_compatible[] = {
diff --git a/drivers/pci/pci-tegra.c b/drivers/pci/pci-tegra.c
index 7f10b7af2ee1..b534285c97f7 100644
--- a/drivers/pci/pci-tegra.c
+++ b/drivers/pci/pci-tegra.c
@@ -822,10 +822,7 @@ static int tegra_pcie_resets_get(struct tegra_pcie *pcie)
 		return PTR_ERR(pcie->afi_rst);
 
 	pcie->pcie_xrst = reset_control_get(pcie->dev, "pcie_x");
-	if (IS_ERR(pcie->pcie_xrst))
-		return PTR_ERR(pcie->pcie_xrst);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(pcie->pcie_xrst);
 }
 
 static int tegra_pcie_get_resources(struct tegra_pcie *pcie)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 878f4d72bbf5..aba6c2a7098e 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -122,10 +122,7 @@ int pwmchip_add(struct pwm_chip *chip, struct device_d *dev)
 
 	p = dev_add_param_bool(&pwm->dev, "inverted", apply_params,
 			       NULL, &pwm->params.polarity, pwm);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(p);
 }
 EXPORT_SYMBOL_GPL(pwmchip_add);
 
diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
index 7017796e8cb1..52f43b75d2bd 100644
--- a/drivers/usb/otg/otgdev.c
+++ b/drivers/usb/otg/otgdev.c
@@ -62,8 +62,5 @@ int usb_register_otg_device(struct device_d *parent,
 	param_mode = dev_add_param_enum(&otg_device, "mode",
 			otg_set_mode, NULL, &otg_mode,
 			otg_mode_names, ARRAY_SIZE(otg_mode_names), ctx);
-	if (IS_ERR(param_mode))
-		return PTR_ERR(param_mode);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(param_mode);
 }
diff --git a/drivers/watchdog/rave-sp-wdt.c b/drivers/watchdog/rave-sp-wdt.c
index dc673ee35fa4..cad63e22f921 100644
--- a/drivers/watchdog/rave-sp-wdt.c
+++ b/drivers/watchdog/rave-sp-wdt.c
@@ -299,10 +299,7 @@ static int rave_sp_wdt_add_params(struct rave_sp_wdt *sp_wd)
 			      rave_sp_wdt_set_boot_source,
 			      rave_sp_wdt_get_boot_source,
 			      &sp_wd->boot_source, "%u", sp_wd);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(p);
 }
 
 static int rave_sp_wdt_probe(struct device_d *dev)
-- 
2.27.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] treewide: make use of PTR_ERR_OR_ZERO
  2020-06-24 13:58 [PATCH] treewide: make use of PTR_ERR_OR_ZERO Uwe Kleine-König
@ 2020-06-26  8:20 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-06-26  8:20 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On Wed, Jun 24, 2020 at 03:58:36PM +0200, Uwe Kleine-König wrote:
> PTR_ERR_OR_ZERO is designed to replace boiler plate like:
> 
> 	if (IS_ERR(x))
> 		return PTR_ERR(x);
> 	return 0;
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---

Applied, thanks

Sascha

>  arch/arm/boards/freescale-mx23-evk/mx23-evk.c |  4 +---
>  arch/arm/boards/karo-tx28/tx28-stk5.c         |  4 +---
>  common/globalvar.c                            |  5 +----
>  common/serdev.c                               |  5 +----
>  drivers/mfd/rave-sp.c                         |  5 +----
>  drivers/mtd/ubi/eba.c                         | 12 +++---------
>  drivers/net/designware_generic.c              |  5 +----
>  drivers/pci/pci-tegra.c                       |  5 +----
>  drivers/pwm/core.c                            |  5 +----
>  drivers/usb/otg/otgdev.c                      |  5 +----
>  drivers/watchdog/rave-sp-wdt.c                |  5 +----
>  11 files changed, 13 insertions(+), 47 deletions(-)
> 
> diff --git a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
> index 9dc5967bd93e..b12bb0dd79fb 100644
> --- a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
> +++ b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
> @@ -79,9 +79,7 @@ static int register_persistent_environment(void)
>  	/* use the full partition as our persistent environment storage */
>  	cdev = devfs_add_partition("disk0.1", 0, cdev->size,
>  						DEVFS_PARTITION_FIXED, "env0");
> -	if (IS_ERR(cdev))
> -		return PTR_ERR(cdev);
> -	return 0;
> +	return PTR_ERR_OR_ZERO(cdev);
>  }
>  
>  static int mx23_evk_devices_init(void)
> diff --git a/arch/arm/boards/karo-tx28/tx28-stk5.c b/arch/arm/boards/karo-tx28/tx28-stk5.c
> index 838754d042ab..c9b947953bb2 100644
> --- a/arch/arm/boards/karo-tx28/tx28-stk5.c
> +++ b/arch/arm/boards/karo-tx28/tx28-stk5.c
> @@ -333,9 +333,7 @@ static int register_persistent_environment(void)
>  	/* use the full partition as our persistent environment storage */
>  	cdev = devfs_add_partition("disk0.1", 0, cdev->size,
>  					DEVFS_PARTITION_FIXED, "env0");
> -	if (IS_ERR(cdev))
> -		return PTR_ERR(cdev);
> -	return 0;
> +	return PTR_ERR_OR_ZERO(cdev);
>  }
>  
>  static void tx28_get_ethaddr(void)
> diff --git a/common/globalvar.c b/common/globalvar.c
> index c87f2c933904..98a028a68aa7 100644
> --- a/common/globalvar.c
> +++ b/common/globalvar.c
> @@ -563,10 +563,7 @@ int globalvar_add_simple_bitmask(const char *name, unsigned long *value,
>  	p = dev_add_param_bitmask(&global_device, name, NULL, NULL,
>  		value, names, max, NULL);
>  
> -	if (IS_ERR(p))
> -		return PTR_ERR(p);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(p);
>  }
>  
>  int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
> diff --git a/common/serdev.c b/common/serdev.c
> index c50b3bd26acb..4bf11b161892 100644
> --- a/common/serdev.c
> +++ b/common/serdev.c
> @@ -84,10 +84,7 @@ int serdev_device_open(struct serdev_device *serdev)
>  	p = dev_add_param_uint64(serdev->dev, "polling_interval",
>  				 serdev_device_set_polling_interval, NULL,
>  				 &serdev->polling_interval, "%llu", serdev);
> -	if (IS_ERR(p))
> -		return PTR_ERR(p);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(p);
>  }
>  
>  unsigned int serdev_device_set_baudrate(struct serdev_device *serdev,
> diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
> index c6ad57d517dc..8fc46b66bb2c 100644
> --- a/drivers/mfd/rave-sp.c
> +++ b/drivers/mfd/rave-sp.c
> @@ -787,10 +787,7 @@ static int rave_sp_add_params(struct rave_sp *sp)
>  
>  	p = dev_add_param_ip(dev, "netmask", NULL, rave_sp_req_ip_addr,
>  			     &sp->netmask, sp);
> -	if (IS_ERR(p))
> -		return PTR_ERR(p);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(p);
>  }
>  
>  static int rave_sp_probe(struct device_d *dev)
> diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
> index cca6ec4ba915..071bbca236e9 100644
> --- a/drivers/mtd/ubi/eba.c
> +++ b/drivers/mtd/ubi/eba.c
> @@ -324,9 +324,7 @@ static int leb_read_lock(struct ubi_device *ubi, int vol_id, int lnum)
>  	struct ubi_ltree_entry *le;
>  
>  	le = ltree_add_entry(ubi, vol_id, lnum);
> -	if (IS_ERR(le))
> -		return PTR_ERR(le);
> -	return 0;
> +	return PTR_ERR_OR_ZERO(le);
>  }
>  
>  /**
> @@ -362,9 +360,7 @@ static int leb_write_lock(struct ubi_device *ubi, int vol_id, int lnum)
>  	struct ubi_ltree_entry *le;
>  
>  	le = ltree_add_entry(ubi, vol_id, lnum);
> -	if (IS_ERR(le))
> -		return PTR_ERR(le);
> -	return 0;
> +	return PTR_ERR_OR_ZERO(le);
>  }
>  
>  /**
> @@ -383,9 +379,7 @@ static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
>  	struct ubi_ltree_entry *le;
>  
>  	le = ltree_add_entry(ubi, vol_id, lnum);
> -	if (IS_ERR(le))
> -		return PTR_ERR(le);
> -	return 0;
> +	return PTR_ERR_OR_ZERO(le);
>  }
>  
>  /**
> diff --git a/drivers/net/designware_generic.c b/drivers/net/designware_generic.c
> index 809c7b7b69e6..90fca1951d88 100644
> --- a/drivers/net/designware_generic.c
> +++ b/drivers/net/designware_generic.c
> @@ -21,10 +21,7 @@ static int dwc_ether_probe(struct device_d *dev)
>  	struct dw_eth_dev *dwc;
>  
>  	dwc = dwc_drv_probe(dev);
> -	if (IS_ERR(dwc))
> -		return PTR_ERR(dwc);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(dwc);
>  }
>  
>  static __maybe_unused struct of_device_id dwc_ether_compatible[] = {
> diff --git a/drivers/pci/pci-tegra.c b/drivers/pci/pci-tegra.c
> index 7f10b7af2ee1..b534285c97f7 100644
> --- a/drivers/pci/pci-tegra.c
> +++ b/drivers/pci/pci-tegra.c
> @@ -822,10 +822,7 @@ static int tegra_pcie_resets_get(struct tegra_pcie *pcie)
>  		return PTR_ERR(pcie->afi_rst);
>  
>  	pcie->pcie_xrst = reset_control_get(pcie->dev, "pcie_x");
> -	if (IS_ERR(pcie->pcie_xrst))
> -		return PTR_ERR(pcie->pcie_xrst);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(pcie->pcie_xrst);
>  }
>  
>  static int tegra_pcie_get_resources(struct tegra_pcie *pcie)
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 878f4d72bbf5..aba6c2a7098e 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -122,10 +122,7 @@ int pwmchip_add(struct pwm_chip *chip, struct device_d *dev)
>  
>  	p = dev_add_param_bool(&pwm->dev, "inverted", apply_params,
>  			       NULL, &pwm->params.polarity, pwm);
> -	if (IS_ERR(p))
> -		return PTR_ERR(p);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(p);
>  }
>  EXPORT_SYMBOL_GPL(pwmchip_add);
>  
> diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
> index 7017796e8cb1..52f43b75d2bd 100644
> --- a/drivers/usb/otg/otgdev.c
> +++ b/drivers/usb/otg/otgdev.c
> @@ -62,8 +62,5 @@ int usb_register_otg_device(struct device_d *parent,
>  	param_mode = dev_add_param_enum(&otg_device, "mode",
>  			otg_set_mode, NULL, &otg_mode,
>  			otg_mode_names, ARRAY_SIZE(otg_mode_names), ctx);
> -	if (IS_ERR(param_mode))
> -		return PTR_ERR(param_mode);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(param_mode);
>  }
> diff --git a/drivers/watchdog/rave-sp-wdt.c b/drivers/watchdog/rave-sp-wdt.c
> index dc673ee35fa4..cad63e22f921 100644
> --- a/drivers/watchdog/rave-sp-wdt.c
> +++ b/drivers/watchdog/rave-sp-wdt.c
> @@ -299,10 +299,7 @@ static int rave_sp_wdt_add_params(struct rave_sp_wdt *sp_wd)
>  			      rave_sp_wdt_set_boot_source,
>  			      rave_sp_wdt_get_boot_source,
>  			      &sp_wd->boot_source, "%u", sp_wd);
> -	if (IS_ERR(p))
> -		return PTR_ERR(p);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(p);
>  }
>  
>  static int rave_sp_wdt_probe(struct device_d *dev)
> -- 
> 2.27.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-26  9:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 13:58 [PATCH] treewide: make use of PTR_ERR_OR_ZERO Uwe Kleine-König
2020-06-26  8:20 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox