mfd: Simplify return logic
Subsystems (3)
cover mfd: Simplify return logic
Hello Lee,
This series contains trivial patches that simplify the return logic in a number of functions in mfd drivers. All these were found by running make coccichek M=drivers/mfd.
The patches don't contain functional changes but makes the functions simpler and removes unnecessary lines of code.
Best regards,
Javier
Javier Martinez Canillas (8):
mfd: htc-i2cpld: Remove unneded ret variable
mfd: arizona: Remove unneded ret variable
mfd: pcf50633: Remove unneded ret variable
mfd: kempld-core: Simplify function return logic
mfd: rtsx: Simplify function return logic
mfd: da903x: Simplify function return logic
mfd: da9052: Simplify function return logic
mfd: lm3533: Simplify function return logic
drivers/mfd/arizona-core.c | 4 +--- drivers/mfd/da903x.c | 6 +----- drivers/mfd/da9052-i2c.c | 6 +----- drivers/mfd/da9052-spi.c | 6 +----- drivers/mfd/htc-i2cpld.c | 3 +-- drivers/mfd/kempld-core.c | 14 ++------------ drivers/mfd/lm3533-core.c | 12 ++---------- drivers/mfd/pcf50633-irq.c | 4 ++-- drivers/mfd/rts5209.c | 6 +----- drivers/mfd/rts5227.c | 6 +----- drivers/mfd/rts5229.c | 6 +----- drivers/mfd/rts5249.c | 6 +----- drivers/mfd/rtsx_pcr.c | 6 +----- 13 files changed, 16 insertions(+), 69 deletions(-)
Signature · 1 line
2.4.3
PATCH 1/8 mfd: htc-i2cpld: Remove unneded ret variable
The ret variable is not needed since is not used in the function. Remove the variable and just return 0 instead.
---
drivers/mfd/htc-i2cpld.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mfd/htc-i2cpld.c +1 -2
@@ -318,7 +318,6 @@ static int htcpld_setup_chip_irq(struct htcpld_data *htcpld;struct htcpld_chip *chip;unsigned int irq, irq_end; -int ret =0 ;/* Get the platform and driver data */ htcpld =platform_get_drvdata (pdev);
@@ -333,7 +332,7 @@ static int htcpld_setup_chip_irq(irq_clear_status_flags (irq,IRQ_NOREQUEST |IRQ_NOPROBE ); } -return ret; +return 0 ; } static int htcpld_register_chip_i2c(
Signature · 1 line
2.4.3
Lee Jones
AppliedRe: [PATCH 1/8] mfd: htc-i2cpld: Remove unneded ret variable
Quoted 8 lines · Javier Martinez Canillas
The ret variable is not needed since is not used in the function. Remove the variable and just return 0 instead.
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/mfd/htc-i2cpld.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Applied, thanks.
Quoted 21 lines
drivers/mfd/htc-i2cpld.c +1
-2@@ -318,7 +318,6 @@ static int htcpld_setup_chip_irq(struct htcpld_data *htcpld;struct htcpld_chip *chip;unsigned int irq, irq_end; -int ret =0 ;/* Get the platform and driver data */ htcpld =platform_get_drvdata (pdev);@@ -333,7 +332,7 @@ static int htcpld_setup_chip_irq(irq_clear_status_flags (irq,IRQ_NOREQUEST |IRQ_NOPROBE ); } -return ret; +return 0 ; } static int htcpld_register_chip_i2c(
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 2/8 mfd: arizona: Remove unneded ret variable
In reply to Javier Martinez CanillasThe ret variable is not needed since is not used in the function. Remove the variable and just return 0 instead.
---
drivers/mfd/arizona-core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mfd/arizona-core.c +1 -3
@@ -69,8 +69,6 @@ EXPORT_SYMBOL_GPL(arizona_clk32k_enable);int arizona_clk32k_disable (struct arizona *arizona) { -int ret =0 ; -mutex_lock (&arizona->clk_lock);BUG_ON (arizona->clk32k_ref <=0 );
@@ -90,7 +88,7 @@ int arizona_clk32k_disable(struct arizona *arizona)mutex_unlock (&arizona->clk_lock); -return ret; +return 0 ; }EXPORT_SYMBOL_GPL (arizona_clk32k_disable);
Signature · 1 line
2.4.3
Re: [PATCH 2/8] mfd: arizona: Remove unneded ret variable
Quoted 5 lines · Javier Martinez Canillas
The ret variable is not needed since is not used in the function. Remove the variable and just return 0 instead.
Signed-off-by Javier Martinez Canillas <[email protected]>---
Thanks,
Charles
Lee Jones
AppliedRe: [PATCH 2/8] mfd: arizona: Remove unneded ret variable
In reply to Javier Martinez CanillasQuoted 8 lines · Javier Martinez Canillas
The ret variable is not needed since is not used in the function. Remove the variable and just return 0 instead.
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/mfd/arizona-core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Applied, thanks.
Quoted 22 lines
drivers/mfd/arizona-core.c +1
-3@@ -69,8 +69,6 @@ EXPORT_SYMBOL_GPL(arizona_clk32k_enable);int arizona_clk32k_disable (struct arizona *arizona) { -int ret =0 ; -mutex_lock (&arizona->clk_lock);BUG_ON (arizona->clk32k_ref <=0 );@@ -90,7 +88,7 @@ int arizona_clk32k_disable(struct arizona *arizona)mutex_unlock (&arizona->clk_lock); -return ret; +return 0 ; }EXPORT_SYMBOL_GPL (arizona_clk32k_disable);
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 3/8 mfd: pcf50633: Remove unneded ret variable
In reply to Javier Martinez CanillasThe ret variable is not needed since is not used in the function. Remove the variable and just return 0 instead.
---
drivers/mfd/pcf50633-irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mfd/pcf50633-irq.c +2 -2
@@ -55,7 +55,7 @@ EXPORT_SYMBOL_GPL(pcf50633_free_irq);static int __pcf50633_irq_mask_set (struct pcf50633 *pcf,int irq,u8 mask) {u8 reg, bit; -int ret =0 , idx; +int idx; idx = irq >>3 ; reg =PCF50633_REG_INT1M + idx;
@@ -72,7 +72,7 @@ static int __pcf50633_irq_mask_set(struct pcf50633 *pcf, int irq, u8 mask)mutex_unlock (&pcf->lock); -return ret; +return 0 ; }int pcf50633_irq_mask (struct pcf50633 *pcf,int irq)
Signature · 1 line
2.4.3
Lee Jones
AppliedRe: [PATCH 3/8] mfd: pcf50633: Remove unneded ret variable
Quoted 8 lines · Javier Martinez Canillas
The ret variable is not needed since is not used in the function. Remove the variable and just return 0 instead.
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/mfd/pcf50633-irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied, thanks.
Quoted 22 lines
drivers/mfd/pcf50633-irq.c +2
-2@@ -55,7 +55,7 @@ EXPORT_SYMBOL_GPL(pcf50633_free_irq);static int __pcf50633_irq_mask_set (struct pcf50633 *pcf,int irq,u8 mask) {u8 reg, bit; -int ret =0 , idx; +int idx; idx = irq >>3 ; reg =PCF50633_REG_INT1M + idx;@@ -72,7 +72,7 @@ static int __pcf50633_irq_mask_set(struct pcf50633 *pcf, int irq, u8 mask)mutex_unlock (&pcf->lock); -return ret; +return 0 ; }int pcf50633_irq_mask (struct pcf50633 *pcf,int irq)
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 4/8 mfd: kempld-core: Simplify function return logic
In reply to Javier Martinez CanillasThe invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
---
drivers/mfd/kempld-core.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/mfd/kempld-core.c +2 -12
@@ -448,7 +448,6 @@ static int kempld_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct kempld_device_data *pld;struct resource *ioport; -int ret; pld =devm_kzalloc (dev,sizeof (*pld),GFP_KERNEL );if (!pld)
@@ -471,11 +470,7 @@ static int kempld_probe(struct platform_device *pdev)mutex_init (&pld->lock);platform_set_drvdata (pdev, pld); - ret =kempld_detect_device (pld); -if (ret) -return ret; - -return 0 ; +return kempld_detect_device (pld); }static int kempld_remove (struct platform_device *pdev)
@@ -756,7 +751,6 @@ MODULE_DEVICE_TABLE(dmi, kempld_dmi_table);static int __init kempld_init (void ) {const struct dmi_system_id *id; -int ret;if (force_device_id[0 ]) { for (id = kempld_dmi_table;
@@ -771,11 +765,7 @@ static int __init kempld_init(void)return -ENODEV ; } - ret =platform_driver_register (&kempld_driver); -if (ret) -return ret; - -return 0 ; +return platform_driver_register (&kempld_driver); } static void __exit kempld_exit(void)
Signature · 1 line
2.4.3
Lee Jones
AppliedRe: [PATCH 4/8] mfd: kempld-core: Simplify function return logic
Quoted 8 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/mfd/kempld-core.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
Applied, thanks.
Quoted 46 lines
drivers/mfd/kempld-core.c +2
-12@@ -448,7 +448,6 @@ static int kempld_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct kempld_device_data *pld;struct resource *ioport; -int ret; pld =devm_kzalloc (dev,sizeof (*pld),GFP_KERNEL );if (!pld)@@ -471,11 +470,7 @@ static int kempld_probe(struct platform_device *pdev)mutex_init (&pld->lock);platform_set_drvdata (pdev, pld); - ret =kempld_detect_device (pld); -if (ret) -return ret; - -return 0 ; +return kempld_detect_device (pld); }static int kempld_remove (struct platform_device *pdev)@@ -756,7 +751,6 @@ MODULE_DEVICE_TABLE(dmi, kempld_dmi_table);static int __init kempld_init (void ) {const struct dmi_system_id *id; -int ret;if (force_device_id[0 ]) { for (id = kempld_dmi_table;@@ -771,11 +765,7 @@ static int __init kempld_init(void)return -ENODEV ; } - ret =platform_driver_register (&kempld_driver); -if (ret) -return ret; - -return 0 ; +return platform_driver_register (&kempld_driver); } static void __exit kempld_exit(void)
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 5/8 mfd: rtsx: Simplify function return logic
In reply to Javier Martinez CanillasThe invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
---
drivers/mfd/rts5209.c | 6 +----- drivers/mfd/rts5227.c | 6 +----- drivers/mfd/rts5229.c | 6 +----- drivers/mfd/rts5249.c | 6 +----- drivers/mfd/rtsx_pcr.c | 6 +----- 5 files changed, 5 insertions(+), 25 deletions(-)
drivers/mfd/rts5209.c +1 -5
@@ -138,11 +138,7 @@ static int rts5209_card_power_on(struct rtsx_pcr *pcr, int card)rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,CARD_PWR_CTL , pwr_mask, pwr_on);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x00 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rts5209_card_power_off (struct rtsx_pcr *pcr,int card)
drivers/mfd/rts5227.c +1 -5
@@ -179,11 +179,7 @@ static int rts5227_card_power_on(struct rtsx_pcr *pcr, int card) SD_POWER_MASK, SD_POWER_ON);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x06 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rts5227_card_power_off (struct rtsx_pcr *pcr,int card)
drivers/mfd/rts5229.c +1 -5
@@ -129,11 +129,7 @@ static int rts5229_card_power_on(struct rtsx_pcr *pcr, int card) SD_POWER_MASK, SD_POWER_ON);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x06 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rts5229_card_power_off (struct rtsx_pcr *pcr,int card)
drivers/mfd/rts5249.c +1 -5
@@ -234,11 +234,7 @@ static int rtsx_base_card_power_on(struct rtsx_pcr *pcr, int card) SD_POWER_MASK, SD_VCC_POWER_ON);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x06 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rtsx_base_card_power_off (struct rtsx_pcr *pcr,int card)
drivers/mfd/rtsx_pcr.c +1 -5
@@ -571,11 +571,7 @@ static int rtsx_pci_set_pull_ctl(struct rtsx_pcr *pcr, const u32 *tbl) tbl++; } - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }int rtsx_pci_card_pull_ctl_enable (struct rtsx_pcr *pcr,int card)
Signature · 1 line
2.4.3
Lee Jones
AppliedRe: [PATCH 5/8] mfd: rtsx: Simplify function return logic
Quoted 4 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>
Quoted 8 lines
---
drivers/mfd/rts5209.c | 6 +----- drivers/mfd/rts5227.c | 6 +----- drivers/mfd/rts5229.c | 6 +----- drivers/mfd/rts5249.c | 6 +----- drivers/mfd/rtsx_pcr.c | 6 +----- 5 files changed, 5 insertions(+), 25 deletions(-)
Applied, thanks.
Quoted 85 lines
drivers/mfd/rts5209.c +1
-5@@ -138,11 +138,7 @@ static int rts5209_card_power_on(struct rtsx_pcr *pcr, int card)rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,CARD_PWR_CTL , pwr_mask, pwr_on);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x00 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rts5209_card_power_off (struct rtsx_pcr *pcr,int card)drivers/mfd/rts5227.c +1
-5@@ -179,11 +179,7 @@ static int rts5227_card_power_on(struct rtsx_pcr *pcr, int card) SD_POWER_MASK, SD_POWER_ON);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x06 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rts5227_card_power_off (struct rtsx_pcr *pcr,int card)drivers/mfd/rts5229.c +1
-5@@ -129,11 +129,7 @@ static int rts5229_card_power_on(struct rtsx_pcr *pcr, int card) SD_POWER_MASK, SD_POWER_ON);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x06 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rts5229_card_power_off (struct rtsx_pcr *pcr,int card)drivers/mfd/rts5249.c +1
-5@@ -234,11 +234,7 @@ static int rtsx_base_card_power_on(struct rtsx_pcr *pcr, int card) SD_POWER_MASK, SD_VCC_POWER_ON);rtsx_pci_add_cmd (pcr,WRITE_REG_CMD ,PWR_GATE_CTRL ,LDO3318_PWR_MASK ,0x06 ); - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }static int rtsx_base_card_power_off (struct rtsx_pcr *pcr,int card)drivers/mfd/rtsx_pcr.c +1
-5@@ -571,11 +571,7 @@ static int rtsx_pci_set_pull_ctl(struct rtsx_pcr *pcr, const u32 *tbl) tbl++; } - err =rtsx_pci_send_cmd (pcr,100 ); -if (err <0 ) -return err; - -return 0 ; +return rtsx_pci_send_cmd (pcr,100 ); }int rtsx_pci_card_pull_ctl_enable (struct rtsx_pcr *pcr,int card)
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 6/8 mfd: da903x: Simplify function return logic
In reply to Javier Martinez CanillasThe invoked function already returns zero on success or a negative errno code so there is no need to open code the logic in the caller.
---
drivers/mfd/da903x.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mfd/da903x.c +1 -5
@@ -532,11 +532,7 @@ static int da903x_probe(struct i2c_client *client,return ret; } - ret =da903x_add_subdevs (chip, pdata); -if (ret) -return ret; - -return 0 ; +return da903x_add_subdevs (chip, pdata); }static int da903x_remove (struct i2c_client *client)
Signature · 1 line
2.4.3
RE: [PATCH 6/8] mfd: da903x: Simplify function return logic
Quoted 5 lines · Javier Martinez Canillas
The invoked function already returns zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>---
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Lee Jones
AppliedRe: [PATCH 6/8] mfd: da903x: Simplify function return logic
In reply to Javier Martinez CanillasQuoted 8 lines · Javier Martinez Canillas
The invoked function already returns zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/mfd/da903x.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Applied, thanks.
Quoted 17 lines
drivers/mfd/da903x.c +1
-5@@ -532,11 +532,7 @@ static int da903x_probe(struct i2c_client *client,return ret; } - ret =da903x_add_subdevs (chip, pdata); -if (ret) -return ret; - -return 0 ; +return da903x_add_subdevs (chip, pdata); }static int da903x_remove (struct i2c_client *client)
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 7/8 mfd: da9052: Simplify function return logic
In reply to Javier Martinez CanillasThe invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
---
drivers/mfd/da9052-i2c.c | 6 +----- drivers/mfd/da9052-spi.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-)
drivers/mfd/da9052-i2c.c +1 -5
@@ -174,11 +174,7 @@ static int da9052_i2c_probe(struct i2c_client *client,return ret; } - ret =da9052_device_init (da9052, id->driver_data); -if (ret !=0 ) -return ret; - -return 0 ; +return da9052_device_init (da9052, id->driver_data); }static int da9052_i2c_remove (struct i2c_client *client)
drivers/mfd/da9052-spi.c +1 -5
@@ -56,11 +56,7 @@ static int da9052_spi_probe(struct spi_device *spi)return ret; } - ret =da9052_device_init (da9052, id->driver_data); -if (ret !=0 ) -return ret; - -return 0 ; +return da9052_device_init (da9052, id->driver_data); }static int da9052_spi_remove (struct spi_device *spi)
Signature · 1 line
2.4.3
RE: [PATCH 7/8] mfd: da9052: Simplify function return logic
Quoted 5 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>---
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Lee Jones
AppliedRe: [PATCH 7/8] mfd: da9052: Simplify function return logic
In reply to Javier Martinez CanillasQuoted 9 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/mfd/da9052-i2c.c | 6 +----- drivers/mfd/da9052-spi.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-)
Applied, thanks.
Quoted 34 lines
drivers/mfd/da9052-i2c.c +1
-5@@ -174,11 +174,7 @@ static int da9052_i2c_probe(struct i2c_client *client,return ret; } - ret =da9052_device_init (da9052, id->driver_data); -if (ret !=0 ) -return ret; - -return 0 ; +return da9052_device_init (da9052, id->driver_data); }static int da9052_i2c_remove (struct i2c_client *client)drivers/mfd/da9052-spi.c +1
-5@@ -56,11 +56,7 @@ static int da9052_spi_probe(struct spi_device *spi)return ret; } - ret =da9052_device_init (da9052, id->driver_data); -if (ret !=0 ) -return ret; - -return 0 ; +return da9052_device_init (da9052, id->driver_data); }static int da9052_spi_remove (struct spi_device *spi)
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 8/8 mfd: lm3533: Simplify function return logic
In reply to Javier Martinez CanillasThe invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
---
drivers/mfd/lm3533-core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/mfd/lm3533-core.c +2 -10
@@ -472,11 +472,7 @@ static int lm3533_device_setup(struct lm3533 *lm3533,if (ret)return ret; - ret =lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -if (ret) -return ret; - -return 0 ; +return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); }static int lm3533_device_init (struct lm3533 *lm3533)
@@ -613,11 +609,7 @@ static int lm3533_i2c_probe(struct i2c_client *i2c, lm3533->dev = &i2c->dev; lm3533->irq = i2c->irq; - ret =lm3533_device_init (lm3533); -if (ret) -return ret; - -return 0 ; +return lm3533_device_init (lm3533); }static int lm3533_i2c_remove (struct i2c_client *i2c)
Signature · 1 line
2.4.3
Re: [PATCH 8/8] mfd: lm3533: Simplify function return logic
Quoted 4 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>
I do not consider this an improvement in any way and suggest this patch is dropped.
Quoted 10 lines
---
drivers/mfd/lm3533-core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/mfd/lm3533-core.c +0
-0
drivers/mfd/lm3533-core.c static int lm3533_device_setup(struct lm3533 *lm3533, · line 475
Quoted 9 lines
drivers/mfd/lm3533-core.c +1
-5@@ -472,11 +472,7 @@ static int lm3533_device_setup(struct lm3533 *lm3533,if (ret)return ret; - ret =lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -if (ret) -return ret; - -return 0 ; +return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp);
You're saving a few lines of code but instead introduce asymmetries and obscure the fact that the function returns zero on success.
Johan
Re: [PATCH 8/8] mfd: lm3533: Simplify function return logic
Hello Johan,
Quoted 9 lines · Johan Hovold
Quoted 4 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>I do not consider this an improvement in any way and suggest this patch is dropped.
Since I posted the patch I obviously disagree but I don't really mind if the patch is dropped.
Quoted 13 lines
Quoted 13 lines
---
drivers/mfd/lm3533-core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/mfd/lm3533-core.c +0
-0@@ -472,11 +472,7 @@ static int lm3533_device_setup(struct lm3533 *lm3533,if (ret)return ret;
Quoted 10 lines
drivers/mfd/lm3533-core.c static int lm3533_device_setup(struct lm3533 *lm3533, · line 475
Quoted 6 lines
drivers/mfd/lm3533-core.c +1
-5- ret =lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -if (ret) -return ret; - -return 0 ; +return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp);You're saving a few lines of code but instead introduce asymmetries and obscure the fact that the function returns zero on success.
I don't think the change makes the code more obscure tbh, the return foo() construct is very common in the kernel and most functions return 0 on success and a negative errno code on failure.
Also, we have a coccinelle semantic patch to find this pattern [0] so if you think that is not worth it, please add a comment to the code. Otherwise another developer could attempt to post the same patch since make coccicheck will always complain about this file.
Quoted 2 lines
Johan
[0]: http://lxr.free-electrons.com/source/scripts/coccinelle/misc/simple_return.cocci
Best regards,
Signature · 3 lines
Javier Martinez Canillas Open Source Group Samsung Research America
Re: [PATCH 8/8] mfd: lm3533: Simplify function return logic
Quoted 21 lines · Javier Martinez Canillas
Quoted 10 lines · Johan Hovold
Quoted 8 lines · Javier Martinez Canillas
drivers/mfd/lm3533-core.c +0
-0@@ -472,11 +472,7 @@ static int lm3533_device_setup(struct lm3533 *lm3533,if (ret)return ret;Quoted 9 lines
drivers/mfd/lm3533-core.c static int lm3533_device_setup(struct lm3533 *lm3533, · line 475
Quoted 6 lines
drivers/mfd/lm3533-core.c +1
-5- ret =lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -if (ret) -return ret; - -return 0 ; +return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp);You're saving a few lines of code but instead introduce asymmetries and obscure the fact that the function returns zero on success.
Quoted 3 lines
I don't think the change makes the code more obscure tbh, the return
foo()construct is very common in the kernel and most functions return 0 on success and a negative errno code on failure.
But it was perfectly obvious from just looking at the function before your change.
Quoted 4 lines
Also, we have a coccinelle semantic patch to find this pattern [0] so if you think that is not worth it, please add a comment to the code. Otherwise another developer could attempt to post the same patch since make coccicheck will always complain about this file.
Yes, I've NAKed similar so called clean up patches based on that pattern for USB-serial and would be very glad to see that semantic patch removed.
Coccinelle can be very useful to detect and fix real bugs, but this return-value exercise is just pointless at best.
Johan
Re: [PATCH 8/8] mfd: lm3533: Simplify function return logic
In reply to Johan HovoldQuoted 8 lines · Johan Hovold
Quoted 4 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>I do not consider this an improvement in any way and suggest this patch is dropped.
Sorry Johan, but I disagree.
Quoted 12 lines
Quoted 12 lines
--- drivers/mfd/lm3533-core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/mfd/lm3533-core.c +0
-0@@ -472,11 +472,7 @@ static int lm3533_device_setup(struct lm3533 *lm3533,if (ret)return ret;
Quoted 9 lines
drivers/mfd/lm3533-core.c static int lm3533_device_setup(struct lm3533 *lm3533, · line 475
Quoted 6 lines
drivers/mfd/lm3533-core.c +1
-5- ret =lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -if (ret) -return ret; - -return 0 ; +return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp);You're saving a few lines of code but instead introduce asymmetries and obscure the fact that the function returns zero on success.
There is no obfuscation here. Functions normally return zero on success and !zero on failure, it's what's expected.
I'm going to apply the patch.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH 8/8] mfd: lm3533: Simplify function return logic
Quoted 6 lines · Lee Jones
Quoted 4 lines · Johan Hovold
Quoted 3 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Javier Martinez Canillas <[email protected]>I do not consider this an improvement in any way and suggest this patch is dropped.
Sorry Johan, but I disagree.
It's your call now, but I really think this is something that should be up to the author of the code (which in this case happens to be me).
Neither style is incorrect, but there are reasons for preferring the current style in this case.
Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
--- drivers/mfd/lm3533-core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/mfd/lm3533-core.c +0
-0@@ -472,11 +472,7 @@ static int lm3533_device_setup(struct lm3533 *lm3533,if (ret)return ret;Quoted 9 lines
drivers/mfd/lm3533-core.c static int lm3533_device_setup(struct lm3533 *lm3533, · line 475
Quoted 6 lines
drivers/mfd/lm3533-core.c +1
-5- ret =lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -if (ret) -return ret; - -return 0 ; +return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp);You're saving a few lines of code but instead introduce asymmetries and obscure the fact that the function returns zero on success.
Quoted 2 lines
There is no obfuscation here. Functions normally return zero on success and !zero on failure, it's what's expected.
We have functions returning boolean true or a positive integer on success.
In summary (rehashing what I wrote in a different thread) I do think that:
{
int ret;
ret = init_a(...);
if (ret)
return ret;
ret = init_b(...);
if (ret)
return ret;
return 0;
}is (at least to me) preferred over:
{
int ret;
ret = init_a(...);
if (ret)
return ret;
return init_b(...);
}for symmetry and readability reasons (e.g. I don't have to look at init_b to figure out what the functions returns). And with a long parameter list to init_b with line breaks, this would look even worse.
But either way, it should be up to the author of the code to decide what style to use.
Quoted 1 line
I'm going to apply the patch.
Fair enough. I've asked for the warnings to be removed from coccinelle so hopefully we can get on to fix real issues. ;)
Johan
Lee Jones
AppliedRe: [PATCH 8/8] mfd: lm3533: Simplify function return logic
In reply to Javier Martinez CanillasQuoted 9 lines · Javier Martinez Canillas
The invoked functions already return zero on success or a negative errno code so there is no need to open code the logic in the caller.
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/mfd/lm3533-core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
Applied, thanks.
Quoted 30 lines
drivers/mfd/lm3533-core.c +2
-10@@ -472,11 +472,7 @@ static int lm3533_device_setup(struct lm3533 *lm3533,if (ret)return ret; - ret =lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -if (ret) -return ret; - -return 0 ; +return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); }static int lm3533_device_init (struct lm3533 *lm3533)@@ -613,11 +609,7 @@ static int lm3533_i2c_probe(struct i2c_client *i2c, lm3533->dev = &i2c->dev; lm3533->irq = i2c->irq; - ret =lm3533_device_init (lm3533); -if (ret) -return ret; - -return 0 ; +return lm3533_device_init (lm3533); }static int lm3533_i2c_remove (struct i2c_client *i2c)
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog