Clean-up: squash lines for immediate return
Subsystems (12)
v2 cover Clean-up: squash lines for immediate return
ret = [expression];
if (ret)
return ret;
return 0;
... is equivalent to:
return [expression];
First, I sent a tree-wide patch:
http://patchwork.ozlabs.org/patch/665199/
In the review of v1, Stephen suggested that twee-wide conversion with something like Coccinelle can break code uniformity.
I took a closer look once again, I found many hunks we should not change.
So, here is v2.
I limited this refactoring to cases, I think, really beneficial.
(Mostly, they well be simple wrappers with this series.)
I also split patches per-subsystem
so that custodians can easily review and issue Acked-by (or NACK if they found no good reason to change).
Masahiro Yamada (7):
mmc: squash lines for immediate return
video: squash lines for immediate return
usb: squash lines for immediate return
x86: squash lines for immediate return
samsung: squash lines for immediate return
power: squash lines for immediate return
libfdt: simplify fdt_del_mem_rsv()
arch/x86/cpu/baytrail/valleyview.c | 8 +------- arch/x86/cpu/ivybridge/ivybridge.c | 8 +------- arch/x86/cpu/qemu/qemu.c | 8 +------- arch/x86/cpu/queensbay/tnc.c | 8 +------- board/samsung/goni/goni.c | 8 +------- drivers/mmc/atmel_sdhci.c | 7 +------ drivers/mmc/exynos_dw_mmc.c | 7 +------ drivers/mmc/mmc_boot.c | 28 ++++++++-------------------- drivers/mmc/msm_sdhci.c | 7 +------ drivers/mmc/rockchip_dw_mmc.c | 7 +------ drivers/mmc/rockchip_sdhci.c | 7 +------ drivers/mmc/sandbox_mmc.c | 7 +------ drivers/mmc/zynq_sdhci.c | 7 +------ drivers/power/axp809.c | 8 +------- drivers/usb/host/ehci-atmel.c | 8 +------- drivers/usb/host/ehci-fsl.c | 8 +------- drivers/usb/host/ehci-marvell.c | 8 +------- drivers/usb/host/ehci-mx6.c | 8 +------- drivers/usb/host/ehci-pci.c | 8 +------- drivers/usb/host/ehci-zynq.c | 8 +------- drivers/usb/host/xhci-fsl.c | 7 +------ drivers/video/bridge/ptn3460.c | 7 +------ drivers/video/tegra124/display.c | 8 +------- drivers/video/vidconsole-uclass.c | 6 +----- lib/libfdt/fdt_rw.c | 6 +----- 25 files changed, 32 insertions(+), 175 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/7 mmc: squash lines for immediate return
These functions can be much simpler by squashing lines for immediate return.
For *_bind() callbacks, they will be a simple wrapper function of an upper-level bind API.
For mmc_set_{boot_bus_width,part_conf}, they will be a wrapper of mmc_switch().
---
drivers/mmc/atmel_sdhci.c | 7 +------ drivers/mmc/exynos_dw_mmc.c | 7 +------ drivers/mmc/mmc_boot.c | 28 ++++++++-------------------- drivers/mmc/msm_sdhci.c | 7 +------ drivers/mmc/rockchip_dw_mmc.c | 7 +------ drivers/mmc/rockchip_sdhci.c | 7 +------ drivers/mmc/sandbox_mmc.c | 7 +------ drivers/mmc/zynq_sdhci.c | 7 +------ 8 files changed, 15 insertions(+), 62 deletions(-)
drivers/mmc/atmel_sdhci.c +1 -6
@@ -136,13 +136,8 @@ static int atmel_sdhci_probe(struct udevice *dev)static int atmel_sdhci_bind (struct udevice *dev) {struct atmel_sdhci_plat *plat =dev_get_platdata (dev); -int ret; - ret =sdhci_bind (dev, &plat->mmc, &plat->cfg); -if (ret) -return ret; - -return 0 ; +return sdhci_bind (dev, &plat->mmc, &plat->cfg); }static const struct udevice_id atmel_sdhci_ids[] = {
drivers/mmc/exynos_dw_mmc.c +1 -6
@@ -284,13 +284,8 @@ static int exynos_dwmmc_probe(struct udevice *dev)static int exynos_dwmmc_bind (struct udevice *dev) {struct exynos_mmc_plat *plat =dev_get_platdata (dev); -int ret; - ret =dwmci_bind (dev, &plat->mmc, &plat->cfg); -if (ret) -return ret; - -return 0 ; +return dwmci_bind (dev, &plat->mmc, &plat->cfg); }static const struct udevice_id exynos_dwmmc_ids[] = {
drivers/mmc/mmc_boot.c +8 -20
@@ -85,16 +85,10 @@ int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,*/ int mmc_set_boot_bus_width (struct mmc *mmc,u8 width,u8 reset,u8 mode) { -int err; - - err =mmc_switch (mmc,EXT_CSD_CMD_SET_NORMAL ,EXT_CSD_BOOT_BUS_WIDTH , -EXT_CSD_BOOT_BUS_WIDTH_MODE (mode) | -EXT_CSD_BOOT_BUS_WIDTH_RESET (reset) | -EXT_CSD_BOOT_BUS_WIDTH_WIDTH (width)); - -if (err) -return err; -return 0 ; +return mmc_switch (mmc,EXT_CSD_CMD_SET_NORMAL ,EXT_CSD_BOOT_BUS_WIDTH , +EXT_CSD_BOOT_BUS_WIDTH_MODE (mode) | +EXT_CSD_BOOT_BUS_WIDTH_RESET (reset) | +EXT_CSD_BOOT_BUS_WIDTH_WIDTH (width)); }/*
@@ -106,16 +100,10 @@ int mmc_set_boot_bus_width(struct mmc *mmc, u8 width, u8 reset, u8 mode)*/ int mmc_set_part_conf (struct mmc *mmc,u8 ack,u8 part_num,u8 access) { -int err; - - err =mmc_switch (mmc,EXT_CSD_CMD_SET_NORMAL ,EXT_CSD_PART_CONF , -EXT_CSD_BOOT_ACK (ack) | -EXT_CSD_BOOT_PART_NUM (part_num) | -EXT_CSD_PARTITION_ACCESS (access)); - -if (err) -return err; -return 0 ; +return mmc_switch (mmc,EXT_CSD_CMD_SET_NORMAL ,EXT_CSD_PART_CONF , +EXT_CSD_BOOT_ACK (ack) | +EXT_CSD_BOOT_PART_NUM (part_num) | +EXT_CSD_PARTITION_ACCESS (access)); }/*
drivers/mmc/msm_sdhci.c +1 -6
@@ -190,13 +190,8 @@ static int msm_ofdata_to_platdata(struct udevice *dev)static int msm_sdc_bind (struct udevice *dev) {struct msm_sdhc_plat *plat =dev_get_platdata (dev); -int ret; - ret =sdhci_bind (dev, &plat->mmc, &plat->cfg); -if (ret) -return ret; - -return 0 ; +return sdhci_bind (dev, &plat->mmc, &plat->cfg); }static const struct udevice_id msm_mmc_ids[] = {
drivers/mmc/rockchip_dw_mmc.c +1 -6
@@ -142,13 +142,8 @@ static int rockchip_dwmmc_probe(struct udevice *dev)static int rockchip_dwmmc_bind (struct udevice *dev) {struct rockchip_mmc_plat *plat =dev_get_platdata (dev); -int ret; - ret =dwmci_bind (dev, &plat->mmc, &plat->cfg); -if (ret) -return ret; - -return 0 ; +return dwmci_bind (dev, &plat->mmc, &plat->cfg); }static const struct udevice_id rockchip_dwmmc_ids[] = {
drivers/mmc/rockchip_sdhci.c +1 -6
@@ -62,13 +62,8 @@ static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)static int rockchip_sdhci_bind (struct udevice *dev) {struct rockchip_sdhc_plat *plat =dev_get_platdata (dev); -int ret; - ret =sdhci_bind (dev, &plat->mmc, &plat->cfg); -if (ret) -return ret; - -return 0 ; +return sdhci_bind (dev, &plat->mmc, &plat->cfg); }static const struct udevice_id arasan_sdhci_ids[] = {
drivers/mmc/sandbox_mmc.c +1 -6
@@ -112,7 +112,6 @@ int sandbox_mmc_bind(struct udevice *dev) {struct sandbox_mmc_plat *plat =dev_get_platdata (dev);struct mmc_config *cfg = &plat->cfg; -int ret; cfg->name = dev->name; cfg->host_caps = MMC_MODE_HS_52MHz |MMC_MODE_HS |MMC_MODE_8BIT ;
@@ -121,11 +120,7 @@ int sandbox_mmc_bind(struct udevice *dev) cfg->f_max =52000000 ; cfg->b_max =U32_MAX ; - ret =mmc_bind (dev, &plat->mmc, cfg); -if (ret) -return ret; - -return 0 ; +return mmc_bind (dev, &plat->mmc, cfg); }int sandbox_mmc_unbind (struct udevice *dev)
drivers/mmc/zynq_sdhci.c +1 -6
@@ -63,13 +63,8 @@ static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)static int arasan_sdhci_bind (struct udevice *dev) {struct arasan_sdhci_plat *plat =dev_get_platdata (dev); -int ret; - ret =sdhci_bind (dev, &plat->mmc, &plat->cfg); -if (ret) -return ret; - -return 0 ; +return sdhci_bind (dev, &plat->mmc, &plat->cfg); }static const struct udevice_id arasan_sdhci_ids[] = {
Signature · 1 line
1.9.1
PATCH v2 2/7 video: squash lines for immediate return
In reply to Masahiro Yamadaptn3460_attach() and display_update_config_from_edid() will become a simple wrapper function.
For vidconsole_post_probe(), it is common coding style to let a probe method return the value of a resister function.
---
drivers/video/bridge/ptn3460.c | 7 +------ drivers/video/tegra124/display.c | 8 +------- drivers/video/vidconsole-uclass.c | 6 +----- 3 files changed, 3 insertions(+), 18 deletions(-)
drivers/video/bridge/ptn3460.c +1 -6
@@ -11,14 +11,9 @@static int ptn3460_attach (struct udevice *dev) { -int ret; -debug ("%s: %s\n" , __func__, dev->name); - ret =video_bridge_set_active (dev, true); -if (ret) -return ret; -return 0 ; +return video_bridge_set_active (dev, true); }struct video_bridge_ops ptn3460_ops = {
drivers/video/tegra124/display.c +1 -7
@@ -326,13 +326,7 @@ static int display_update_config_from_edid(struct udevice *dp_dev,int *panel_bppp, struct display_timing *timing) { - int ret; - - ret =display_read_timing (dp_dev, timing); -if (ret) -return ret; - -return 0 ; + return display_read_timing(dp_dev, timing); } static int display_init(struct udevice *dev, void *lcdbase,
drivers/video/vidconsole-uclass.c +1 -5
@@ -190,7 +190,6 @@ static int vidconsole_post_probe(struct udevice *dev) {struct vidconsole_priv *priv =dev_get_uclass_priv (dev);struct stdio_dev *sdev = &priv->sdev; -int ret;if (!priv->tab_width_frac) priv->tab_width_frac =VID_TO_POS (priv->x_charsize) *8 ;
@@ -206,11 +205,8 @@ static int vidconsole_post_probe(struct udevice *dev) sdev->putc = vidconsole_putc; sdev->puts = vidconsole_puts; sdev->priv = dev; - ret =stdio_register (sdev); -if (ret) -return ret; -return 0 ; +return stdio_register (sdev); }UCLASS_DRIVER (vidconsole) = {
Signature · 1 line
1.9.1
PATCH v2 2/7 video: squash lines for immediate return
Quoted 5 lines · On Mon, 5 Sep 2016 22:38:38 +0900 Masahiro Yamada yamada.masahiro at…
ptn3460_attach()anddisplay_update_config_from_edid()will become a simple wrapper function.For
vidconsole_post_probe(), it is common coding style to let a probe method return the value of a resister function.
s/resister/register/
otherwise
PATCH v2 2/7 video: squash lines for immediate return
2016-09-06 2:12 GMT+09:00 Anatolij Gustschin <[email protected]>:
Quoted 6 lines
Quoted 3 lines · On Mon, 5 Sep 2016 22:38:38 +0900 Masahiro Yamada yamada.masahiro at…
ptn3460_attach()anddisplay_update_config_from_edid()will become a simple wrapper function.
Quoted 8 lines
Quoted 2 lines
For
vidconsole_post_probe(), it is common coding style to let a probe method return the value of a resister function.s/resister/register/
otherwise
I will send v3. Thanks!
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH v2 3/7 usb: squash lines for immediate return
In reply to Masahiro Yamadaehci_*_remove() is just a wrapper of ehci_deregister(). xhci_fsl_remove() can be simpler as well.
---
drivers/usb/host/ehci-atmel.c | 8 +------- drivers/usb/host/ehci-fsl.c | 8 +------- drivers/usb/host/ehci-marvell.c | 8 +------- drivers/usb/host/ehci-mx6.c | 8 +------- drivers/usb/host/ehci-pci.c | 8 +------- drivers/usb/host/ehci-zynq.c | 8 +------- drivers/usb/host/xhci-fsl.c | 7 +------ 7 files changed, 7 insertions(+), 48 deletions(-)
drivers/usb/host/ehci-atmel.c +1 -7
@@ -130,13 +130,7 @@ static int ehci_atmel_probe(struct udevice *dev)static int ehci_atmel_remove (struct udevice *dev) { -int ret; - - ret =ehci_deregister (dev); -if (ret) -return ret; - -return 0 ; +return ehci_deregister (dev); }static const struct udevice_id ehci_usb_ids[] = {
drivers/usb/host/ehci-fsl.c +1 -7
@@ -120,13 +120,7 @@ static int ehci_fsl_probe(struct udevice *dev)static int ehci_fsl_remove (struct udevice *dev) { -int ret; - - ret =ehci_deregister (dev); -if (ret) -return ret; - -return 0 ; +return ehci_deregister (dev); }static const struct udevice_id ehci_usb_ids[] = {
drivers/usb/host/ehci-marvell.c +1 -7
@@ -96,13 +96,7 @@ static int ehci_mvebu_probe(struct udevice *dev)static int ehci_mvebu_remove (struct udevice *dev) { -int ret; - - ret =ehci_deregister (dev); -if (ret) -return ret; - -return 0 ; +return ehci_deregister (dev); }static const struct udevice_id ehci_usb_ids[] = {
drivers/usb/host/ehci-mx6.c +1 -7
@@ -453,13 +453,7 @@ static int ehci_usb_probe(struct udevice *dev)static int ehci_usb_remove (struct udevice *dev) { -int ret; - - ret =ehci_deregister (dev); -if (ret) -return ret; - -return 0 ; +return ehci_deregister (dev); }static const struct udevice_id mx6_usb_ids[] = {
drivers/usb/host/ehci-pci.c +1 -7
@@ -128,13 +128,7 @@ static int ehci_pci_probe(struct udevice *dev)static int ehci_pci_remove (struct udevice *dev) { -int ret; - - ret =ehci_deregister (dev); -if (ret) -return ret; - -return 0 ; +return ehci_deregister (dev); }static const struct udevice_id ehci_pci_ids[] = {
drivers/usb/host/ehci-zynq.c +1 -7
@@ -75,13 +75,7 @@ static int ehci_zynq_probe(struct udevice *dev)static int ehci_zynq_remove (struct udevice *dev) { -int ret; - - ret =ehci_deregister (dev); -if (ret) -return ret; - -return 0 ; +return ehci_deregister (dev); }static const struct udevice_id ehci_zynq_ids[] = {
drivers/usb/host/xhci-fsl.c +1 -6
@@ -129,15 +129,10 @@ static int xhci_fsl_probe(struct udevice *dev)static int xhci_fsl_remove (struct udevice *dev) {struct xhci_fsl_priv *priv =dev_get_priv (dev); -int ret;fsl_xhci_core_exit (&priv->ctx); - ret =xhci_deregister (dev); -if (ret) -return ret; - -return 0 ; +return xhci_deregister (dev); }static const struct udevice_id xhci_usb_ids[] = {
Signature · 1 line
1.9.1
PATCH v2 4/7 x86: squash lines for immediate return
In reply to Masahiro Yamadaarch_cpu_init() can be simpler by this refactoring.
---
arch/x86/cpu/baytrail/valleyview.c | 8 +------- arch/x86/cpu/ivybridge/ivybridge.c | 8 +------- arch/x86/cpu/qemu/qemu.c | 8 +------- arch/x86/cpu/queensbay/tnc.c | 8 +------- 4 files changed, 4 insertions(+), 28 deletions(-)
arch/x86/cpu/baytrail/valleyview.c +1 -7
@@ -25,15 +25,9 @@ int cpu_mmc_init(bd_t *bis)#ifndef CONFIG_EFI_APP int arch_cpu_init (void ) { -int ret; -post_code (POST_CPU_INIT ); - ret =x86_cpu_init_f (); -if (ret) -return ret; - -return 0 ; +return x86_cpu_init_f (); }int arch_misc_init (void )
arch/x86/cpu/ivybridge/ivybridge.c +1 -7
@@ -10,13 +10,7 @@int arch_cpu_init (void ) { -int ret; -post_code (POST_CPU_INIT ); - ret =x86_cpu_init_f (); -if (ret) -return ret; - -return 0 ; +return x86_cpu_init_f (); }
arch/x86/cpu/qemu/qemu.c +1 -7
@@ -139,15 +139,9 @@ static void qemu_chipset_init(void)int arch_cpu_init (void ) { -int ret; -post_code (POST_CPU_INIT ); - ret =x86_cpu_init_f (); -if (ret) -return ret; - -return 0 ; +return x86_cpu_init_f (); }#ifndef CONFIG_EFI_STUB
arch/x86/cpu/queensbay/tnc.c +1 -7
@@ -94,15 +94,9 @@ static int __maybe_unused disable_igd(void)int arch_cpu_init (void ) { -int ret; -post_code (POST_CPU_INIT ); - ret =x86_cpu_init_f (); -if (ret) -return ret; - -return 0 ; +return x86_cpu_init_f (); }int arch_early_init_r (void )
Signature · 1 line
1.9.1
PATCH v2 4/7 x86: squash lines for immediate return
Quoted 11 lines · Masahiro Yamada
arch_cpu_init()can be simpler by this refactoring.Signed-off-by Masahiro Yamada <[email protected]>---
arch/x86/cpu/baytrail/valleyview.c | 8 +------- arch/x86/cpu/ivybridge/ivybridge.c | 8 +------- arch/x86/cpu/qemu/qemu.c | 8 +------- arch/x86/cpu/queensbay/tnc.c | 8 +------- 4 files changed, 4 insertions(+), 28 deletions(-)
PATCH v2 4/7 x86: squash lines for immediate return
In reply to Masahiro YamadaQuoted 10 lines · Masahiro Yamada
arch_cpu_init()can be simpler by this refactoring.Signed-off-by Masahiro Yamada <[email protected]>---
arch/x86/cpu/baytrail/valleyview.c | 8 +------- arch/x86/cpu/ivybridge/ivybridge.c | 8 +------- arch/x86/cpu/qemu/qemu.c | 8 +------- arch/x86/cpu/queensbay/tnc.c | 8 +------- 4 files changed, 4 insertions(+), 28 deletions(-)
PATCH v2 5/7 samsung: squash lines for immediate return
In reply to Masahiro YamadaCurrently, this function is just a wrapper of pmic_init().
---
board/samsung/goni/goni.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
board/samsung/goni/goni.c +1 -7
@@ -45,17 +45,11 @@ void i2c_init_board(void)int power_init_board (void ) { -int ret; -/* * For PMIC the I2C bus is named as I2C5, but it is connected * to logical I2C adapter 0 */ - ret =pmic_init (I2C_0 ); -if (ret) -return ret; - -return 0 ; +return pmic_init (I2C_0 ); }int dram_init (void )
Signature · 1 line
1.9.1
PATCH v2 6/7 power: squash lines for immediate return
In reply to Masahiro YamadaCurrently, this function is just a wrapper of pmic_bus_init().
---
drivers/power/axp809.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/power/axp809.c +1 -7
@@ -217,13 +217,7 @@ int axp_set_sw(bool on)int axp_init (void ) { -int ret; - - ret =pmic_bus_init (); -if (ret) -return ret; - -return 0 ; +return pmic_bus_init (); }int do_poweroff (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[])
Signature · 1 line
1.9.1
PATCH v2 7/7 libfdt: simplify fdt_del_mem_rsv()
In reply to Masahiro YamadaThe variable "err" is unneeded.
[ Backport from Device Tree Compiler
commit: 36fd7331fb11276c09a6affc0d8cd4977f2fe100 ]
---
lib/libfdt/fdt_rw.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
lib/libfdt/fdt_rw.c +1 -5
@@ -148,17 +148,13 @@ int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)int fdt_del_mem_rsv (void *fdt,int n) {struct fdt_reserve_entry *re =_fdt_mem_rsv_w (fdt, n); -int err;FDT_RW_CHECK_HEADER (fdt);if (n >=fdt_num_mem_rsv (fdt))return -FDT_ERR_NOTFOUND ; - err =_fdt_splice_mem_rsv (fdt, re,1 ,0 ); -if (err) -return err; -return 0 ; +return _fdt_splice_mem_rsv (fdt, re,1 ,0 ); } static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name,
Signature · 1 line
1.9.1