diff mbox series

[v3,08/21] nvmem: sunxi_sid: use devm_nvmem_register()

Message ID 20180912075129.25185-9-brgl@bgdev.pl (mailing list archive)
State Superseded, archived
Headers show
Series nvmem: rework of the subsystem for non-DT users | expand

Commit Message

Bartosz Golaszewski Sept. 12, 2018, 7:51 a.m. UTC
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Use the resource managed variant of nvmem_register().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/nvmem/sunxi_sid.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

Comments

kernel test robot Sept. 13, 2018, 1:38 a.m. UTC | #1
Hi Bartosz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.19-rc3 next-20180912]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/nvmem-rework-of-the-subsystem-for-non-DT-users/20180913-071053
config: arm-sunxi_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=arm 

All warnings (new ones prefixed by >>):

   drivers/nvmem/sunxi_sid.c: In function 'sunxi_sid_probe':
>> drivers/nvmem/sunxi_sid.c:190:18: warning: passing argument 1 of 'PTR_ERR' makes pointer from integer without a cast [-Wint-conversion]
      return PTR_ERR(-EINVAL);
                     ^
   In file included from include/linux/kernfs.h:11:0,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/device.h:16,
                    from drivers/nvmem/sunxi_sid.c:18:
   include/linux/err.h:29:33: note: expected 'const void *' but argument is of type 'int'
    static inline long __must_check PTR_ERR(__force const void *ptr)
                                    ^~~~~~~
   drivers/nvmem/sunxi_sid.c:157:6: warning: unused variable 'ret' [-Wunused-variable]
     int ret, i, size;
         ^~~

vim +/PTR_ERR +190 drivers/nvmem/sunxi_sid.c

   150	
   151	static int sunxi_sid_probe(struct platform_device *pdev)
   152	{
   153		struct device *dev = &pdev->dev;
   154		struct resource *res;
   155		struct nvmem_device *nvmem;
   156		struct sunxi_sid *sid;
   157		int ret, i, size;
   158		char *randomness;
   159		const struct sunxi_sid_cfg *cfg;
   160	
   161		sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL);
   162		if (!sid)
   163			return -ENOMEM;
   164	
   165		cfg = of_device_get_match_data(dev);
   166		if (!cfg)
   167			return -EINVAL;
   168		sid->value_offset = cfg->value_offset;
   169	
   170		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   171		sid->base = devm_ioremap_resource(dev, res);
   172		if (IS_ERR(sid->base))
   173			return PTR_ERR(sid->base);
   174	
   175		size = cfg->size;
   176	
   177		econfig.size = size;
   178		econfig.dev = dev;
   179		if (cfg->need_register_readout)
   180			econfig.reg_read = sun8i_sid_read_by_reg;
   181		else
   182			econfig.reg_read = sunxi_sid_read;
   183		econfig.priv = sid;
   184		nvmem = devm_nvmem_register(dev, &econfig);
   185		if (IS_ERR(nvmem))
   186			return PTR_ERR(nvmem);
   187	
   188		randomness = kzalloc(size, GFP_KERNEL);
   189		if (!randomness)
 > 190			return PTR_ERR(-EINVAL);
   191	
   192		for (i = 0; i < size; i++)
   193			econfig.reg_read(sid, i, &randomness[i], 1);
   194	
   195		add_device_randomness(randomness, size);
   196		kfree(randomness);
   197	
   198		platform_set_drvdata(pdev, nvmem);
   199	
   200		return 0;
   201	}
   202	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Bartosz Golaszewski Sept. 13, 2018, 8:39 a.m. UTC | #2
2018-09-13 3:38 GMT+02:00 kbuild test robot <lkp@intel.com>:
> Hi Bartosz,
>
> I love your patch! Perhaps something to improve:
>
> [auto build test WARNING on linus/master]
> [also build test WARNING on v4.19-rc3 next-20180912]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>
> url:    https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/nvmem-rework-of-the-subsystem-for-non-DT-users/20180913-071053
> config: arm-sunxi_defconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
> reproduce:
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # save the attached .config to linux build tree
>         GCC_VERSION=7.2.0 make.cross ARCH=arm
>
> All warnings (new ones prefixed by >>):
>
>    drivers/nvmem/sunxi_sid.c: In function 'sunxi_sid_probe':
>>> drivers/nvmem/sunxi_sid.c:190:18: warning: passing argument 1 of 'PTR_ERR' makes pointer from integer without a cast [-Wint-conversion]
>       return PTR_ERR(-EINVAL);
>                      ^
>    In file included from include/linux/kernfs.h:11:0,
>                     from include/linux/sysfs.h:16,
>                     from include/linux/kobject.h:20,
>                     from include/linux/device.h:16,
>                     from drivers/nvmem/sunxi_sid.c:18:
>    include/linux/err.h:29:33: note: expected 'const void *' but argument is of type 'int'
>     static inline long __must_check PTR_ERR(__force const void *ptr)
>                                     ^~~~~~~
>    drivers/nvmem/sunxi_sid.c:157:6: warning: unused variable 'ret' [-Wunused-variable]
>      int ret, i, size;
>          ^~~
>
> vim +/PTR_ERR +190 drivers/nvmem/sunxi_sid.c
>
>    150
>    151  static int sunxi_sid_probe(struct platform_device *pdev)
>    152  {
>    153          struct device *dev = &pdev->dev;
>    154          struct resource *res;
>    155          struct nvmem_device *nvmem;
>    156          struct sunxi_sid *sid;
>    157          int ret, i, size;
>    158          char *randomness;
>    159          const struct sunxi_sid_cfg *cfg;
>    160
>    161          sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL);
>    162          if (!sid)
>    163                  return -ENOMEM;
>    164
>    165          cfg = of_device_get_match_data(dev);
>    166          if (!cfg)
>    167                  return -EINVAL;
>    168          sid->value_offset = cfg->value_offset;
>    169
>    170          res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>    171          sid->base = devm_ioremap_resource(dev, res);
>    172          if (IS_ERR(sid->base))
>    173                  return PTR_ERR(sid->base);
>    174
>    175          size = cfg->size;
>    176
>    177          econfig.size = size;
>    178          econfig.dev = dev;
>    179          if (cfg->need_register_readout)
>    180                  econfig.reg_read = sun8i_sid_read_by_reg;
>    181          else
>    182                  econfig.reg_read = sunxi_sid_read;
>    183          econfig.priv = sid;
>    184          nvmem = devm_nvmem_register(dev, &econfig);
>    185          if (IS_ERR(nvmem))
>    186                  return PTR_ERR(nvmem);
>    187
>    188          randomness = kzalloc(size, GFP_KERNEL);
>    189          if (!randomness)
>  > 190                  return PTR_ERR(-EINVAL);

Will fix in v4. I think this should also return -ENOMEM, not -EINVAL.

Bart

>    191
>    192          for (i = 0; i < size; i++)
>    193                  econfig.reg_read(sid, i, &randomness[i], 1);
>    194
>    195          add_device_randomness(randomness, size);
>    196          kfree(randomness);
>    197
>    198          platform_set_drvdata(pdev, nvmem);
>    199
>    200          return 0;
>    201  }
>    202
>
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c
index d020f89248fd..0296c23db322 100644
--- a/drivers/nvmem/sunxi_sid.c
+++ b/drivers/nvmem/sunxi_sid.c
@@ -181,15 +181,13 @@  static int sunxi_sid_probe(struct platform_device *pdev)
 	else
 		econfig.reg_read = sunxi_sid_read;
 	econfig.priv = sid;
-	nvmem = nvmem_register(&econfig);
+	nvmem = devm_nvmem_register(dev, &econfig);
 	if (IS_ERR(nvmem))
 		return PTR_ERR(nvmem);
 
 	randomness = kzalloc(size, GFP_KERNEL);
-	if (!randomness) {
-		ret = -EINVAL;
-		goto err_unreg_nvmem;
-	}
+	if (!randomness)
+		return PTR_ERR(-EINVAL);
 
 	for (i = 0; i < size; i++)
 		econfig.reg_read(sid, i, &randomness[i], 1);
@@ -200,17 +198,6 @@  static int sunxi_sid_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, nvmem);
 
 	return 0;
-
-err_unreg_nvmem:
-	nvmem_unregister(nvmem);
-	return ret;
-}
-
-static int sunxi_sid_remove(struct platform_device *pdev)
-{
-	struct nvmem_device *nvmem = platform_get_drvdata(pdev);
-
-	return nvmem_unregister(nvmem);
 }
 
 static const struct sunxi_sid_cfg sun4i_a10_cfg = {
@@ -243,7 +230,6 @@  MODULE_DEVICE_TABLE(of, sunxi_sid_of_match);
 
 static struct platform_driver sunxi_sid_driver = {
 	.probe = sunxi_sid_probe,
-	.remove = sunxi_sid_remove,
 	.driver = {
 		.name = "eeprom-sunxi-sid",
 		.of_match_table = sunxi_sid_of_match,