rtc: s5m: check the return value of s5m8767_rtc_init_reg()

Started by Bartosz Golaszewski on Jan 7, 2021 · 4 messages from 2 authors · Last reply Jan 7, 2021

Subsystems (3)

Maintainers (3)

STALE2132d

open the first message on its own page

  1. [PATCH v3 2/2] rtc: s5m: use devm_i2c_new_dummy_device()
    Related patches
Message details and related content
From: Bartosz Golaszewski <redacted>

This function can fail if regmap operations fail so check its return
value in probe().

Signed-off-by: Bartosz Golaszewski <redacted>
---
 drivers/rtc/rtc-s5m.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index eb9dde4095a9..e0011d3cf61b 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -791,6 +791,8 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, info);
 
 	ret = s5m8767_rtc_init_reg(info);
+	if (ret)
+		return ret;
 
 	device_init_wakeup(&pdev->dev, 1);
 
-- 
2.29.1

[PATCH v3 2/2] rtc: s5m: use devm_i2c_new_dummy_device()

Message details and related content
From: Bartosz Golaszewski <redacted>

Use the managed variant of i2c_new_dummy_device() to shrink code and
remove the goto label. We can drop the remove callback now too.

Signed-off-by: Bartosz Golaszewski <redacted>
---
v1 -> v2:
- remove the remove() callback

v2 -> v3:
- fix an error pointed out by the build robot

 drivers/rtc/rtc-s5m.c | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index e0011d3cf61b..b492070afe6a 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -760,7 +760,8 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	info->i2c = i2c_new_dummy_device(s5m87xx->i2c->adapter, RTC_I2C_ADDR);
+	info->i2c = devm_i2c_new_dummy_device(&pdev->dev, s5m87xx->i2c->adapter,
+					      RTC_I2C_ADDR);
 	if (IS_ERR(info->i2c)) {
 		dev_err(&pdev->dev, "Failed to allocate I2C for RTC\n");
 		return PTR_ERR(info->i2c);
@@ -768,10 +769,9 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 
 	info->regmap = devm_regmap_init_i2c(info->i2c, regmap_cfg);
 	if (IS_ERR(info->regmap)) {
-		ret = PTR_ERR(info->regmap);
 		dev_err(&pdev->dev, "Failed to allocate RTC register map: %d\n",
-				ret);
-		goto err;
+			PTR_ERR(info->regmap));
+		return PTR_ERR(info->regmap);
 	}
 
 	info->dev = &pdev->dev;
@@ -781,10 +781,9 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 	if (s5m87xx->irq_data) {
 		info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq);
 		if (info->irq <= 0) {
-			ret = -EINVAL;
 			dev_err(&pdev->dev, "Failed to get virtual IRQ %d\n",
 				alarm_irq);
-			goto err;
+			return -EINVAL;
 		}
 	}
 
@@ -799,10 +798,8 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "s5m-rtc",
 						 &s5m_rtc_ops, THIS_MODULE);
 
-	if (IS_ERR(info->rtc_dev)) {
-		ret = PTR_ERR(info->rtc_dev);
-		goto err;
-	}
+	if (IS_ERR(info->rtc_dev))
+		return PTR_ERR(info->rtc_dev);
 
 	if (!info->irq) {
 		dev_info(&pdev->dev, "Alarm IRQ not available\n");
@@ -815,23 +812,9 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
 			info->irq, ret);
-		goto err;
+		return ret;
 	}
 
-	return 0;
-
-err:
-	i2c_unregister_device(info->i2c);
-
-	return ret;
-}
-
-static int s5m_rtc_remove(struct platform_device *pdev)
-{
-	struct s5m_rtc_info *info = platform_get_drvdata(pdev);
-
-	i2c_unregister_device(info->i2c);
-
 	return 0;
 }
 
@@ -876,7 +859,6 @@ static struct platform_driver s5m_rtc_driver = {
 		.pm	= &s5m_rtc_pm_ops,
 	},
 	.probe		= s5m_rtc_probe,
-	.remove		= s5m_rtc_remove,
 	.id_table	= s5m_rtc_id,
 };
 
-- 
2.29.1

Re: [PATCH v3 2/2] rtc: s5m: use devm_i2c_new_dummy_device()

Message details and related content
Hi Bartosz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on v5.11-rc2 next-20210104]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/rtc-s5m-check-the-return-value-of-s5m8767_rtc_init_reg/20210107-214351
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: i386-randconfig-a016-20210107 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/acac325366af9adafe0057352be2e0567f59d099
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Bartosz-Golaszewski/rtc-s5m-check-the-return-value-of-s5m8767_rtc_init_reg/20210107-214351
        git checkout acac325366af9adafe0057352be2e0567f59d099
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All warnings (new ones prefixed by >>):

   In file included from include/linux/device.h:15,
                    from include/linux/acpi.h:15,
                    from include/linux/i2c.h:13,
                    from drivers/rtc/rtc-s5m.c:11:
   drivers/rtc/rtc-s5m.c: In function 's5m_rtc_probe':
quoted
drivers/rtc/rtc-s5m.c:772:23: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long int' [-Wformat=]
     772 |   dev_err(&pdev->dev, "Failed to allocate RTC register map: %d\n",
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:19:22: note: in definition of macro 'dev_fmt'
      19 | #define dev_fmt(fmt) fmt
         |                      ^~~
   drivers/rtc/rtc-s5m.c:772:3: note: in expansion of macro 'dev_err'
     772 |   dev_err(&pdev->dev, "Failed to allocate RTC register map: %d\n",
         |   ^~~~~~~
   drivers/rtc/rtc-s5m.c:772:62: note: format string is defined here
     772 |   dev_err(&pdev->dev, "Failed to allocate RTC register map: %d\n",
         |                                                             ~^
         |                                                              |
         |                                                              int
         |                                                             %ld


vim +772 drivers/rtc/rtc-s5m.c

5bccae6ec458704 Sangbeom Kim              2013-11-12  712  
5bccae6ec458704 Sangbeom Kim              2013-11-12  713  static int s5m_rtc_probe(struct platform_device *pdev)
5bccae6ec458704 Sangbeom Kim              2013-11-12  714  {
5bccae6ec458704 Sangbeom Kim              2013-11-12  715  	struct sec_pmic_dev *s5m87xx = dev_get_drvdata(pdev->dev.parent);
5bccae6ec458704 Sangbeom Kim              2013-11-12  716  	struct sec_platform_data *pdata = s5m87xx->pdata;
5bccae6ec458704 Sangbeom Kim              2013-11-12  717  	struct s5m_rtc_info *info;
e349c910e2398cb Krzysztof Kozlowski       2014-04-14  718  	const struct regmap_config *regmap_cfg;
a0347f20aaacc96 Krzysztof Kozlowski       2014-06-10  719  	int ret, alarm_irq;
5bccae6ec458704 Sangbeom Kim              2013-11-12  720  
5bccae6ec458704 Sangbeom Kim              2013-11-12  721  	if (!pdata) {
5bccae6ec458704 Sangbeom Kim              2013-11-12  722  		dev_err(pdev->dev.parent, "Platform data not supplied\n");
5bccae6ec458704 Sangbeom Kim              2013-11-12  723  		return -ENODEV;
5bccae6ec458704 Sangbeom Kim              2013-11-12  724  	}
5bccae6ec458704 Sangbeom Kim              2013-11-12  725  
5bccae6ec458704 Sangbeom Kim              2013-11-12  726  	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
5bccae6ec458704 Sangbeom Kim              2013-11-12  727  	if (!info)
5bccae6ec458704 Sangbeom Kim              2013-11-12  728  		return -ENOMEM;
5bccae6ec458704 Sangbeom Kim              2013-11-12  729  
94f919225890a1a Krzysztof Kozlowski       2015-04-16  730  	switch (platform_get_device_id(pdev)->driver_data) {
a65e5efa7c5faa8 Alim Akhtar               2015-11-20  731  	case S2MPS15X:
8ae83b6f76fc74e Krzysztof Kozlowski       2015-12-30  732  		regmap_cfg = &s2mps14_rtc_regmap_config;
8ae83b6f76fc74e Krzysztof Kozlowski       2015-12-30  733  		info->regs = &s2mps15_rtc_regs;

91 more lines

Re: [PATCH v3 2/2] rtc: s5m: use devm_i2c_new_dummy_device()

Message details and related content
Hi Bartosz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on v5.11-rc2 next-20210104]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/rtc-s5m-check-the-return-value-of-s5m8767_rtc_init_reg/20210107-214351
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: x86_64-randconfig-a005-20210107 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 5c951623bc8965fa1e89660f2f5f4a2944e4981a)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/acac325366af9adafe0057352be2e0567f59d099
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Bartosz-Golaszewski/rtc-s5m-check-the-return-value-of-s5m8767_rtc_init_reg/20210107-214351
        git checkout acac325366af9adafe0057352be2e0567f59d099
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All warnings (new ones prefixed by >>):
quoted
drivers/rtc/rtc-s5m.c:773:4: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
                           PTR_ERR(info->regmap));
                           ^~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:112:32: note: expanded from macro 'dev_err'
           _dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__)
                                 ~~~     ^~~~~~~~~~~
   1 warning generated.


vim +773 drivers/rtc/rtc-s5m.c

   712	
   713	static int s5m_rtc_probe(struct platform_device *pdev)
   714	{
   715		struct sec_pmic_dev *s5m87xx = dev_get_drvdata(pdev->dev.parent);
   716		struct sec_platform_data *pdata = s5m87xx->pdata;
   717		struct s5m_rtc_info *info;
   718		const struct regmap_config *regmap_cfg;
   719		int ret, alarm_irq;
   720	
   721		if (!pdata) {
   722			dev_err(pdev->dev.parent, "Platform data not supplied\n");
   723			return -ENODEV;
   724		}
   725	
   726		info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
   727		if (!info)
   728			return -ENOMEM;
   729	
   730		switch (platform_get_device_id(pdev)->driver_data) {
   731		case S2MPS15X:
   732			regmap_cfg = &s2mps14_rtc_regmap_config;
   733			info->regs = &s2mps15_rtc_regs;
   734			alarm_irq = S2MPS14_IRQ_RTCA0;
   735			break;
   736		case S2MPS14X:
   737			regmap_cfg = &s2mps14_rtc_regmap_config;
   738			info->regs = &s2mps14_rtc_regs;
   739			alarm_irq = S2MPS14_IRQ_RTCA0;
   740			break;
   741		case S2MPS13X:

83 more lines

Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help