diff mbox series

[v3,01/20] driver core: Split devres APIs to device/devres.h

Message ID 20250203080902.1864382-2-raag.jadav@intel.com
State New
Headers show
Series [v3,01/20] driver core: Split devres APIs to device/devres.h | expand

Commit Message

Raag Jadav Feb. 3, 2025, 8:08 a.m. UTC
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

device.h is a huge header which is hard to follow and easy to miss
something. Improve that by splitting devres APIs to device/devres.h.

In particular this helps to speedup the build of the code that includes
device.h solely for a devres APIs.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/device.h        | 119 +-------------------------------
 include/linux/device/devres.h | 124 ++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 118 deletions(-)
 create mode 100644 include/linux/device/devres.h

Comments

kernel test robot Feb. 5, 2025, 4:27 p.m. UTC | #1
Hi Raag,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 2014c95afecee3e76ca4a56956a936e23283f05b]

url:    https://github.com/intel-lab-lkp/linux/commits/Raag-Jadav/driver-core-Split-devres-APIs-to-device-devres-h/20250203-161554
base:   2014c95afecee3e76ca4a56956a936e23283f05b
patch link:    https://lore.kernel.org/r/20250203080902.1864382-2-raag.jadav%40intel.com
patch subject: [PATCH v3 01/20] driver core: Split devres APIs to device/devres.h
config: um-randconfig-r112-20250205 (https://download.01.org/0day-ci/archive/20250206/202502060025.XJwUub6I-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 355d0b186f178668b103068537e517f3d52ad639)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250206/202502060025.XJwUub6I-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502060025.XJwUub6I-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   drivers/net/pcs/pcs-xpcs-plat.c: note: in included file (through include/linux/device.h):
>> include/linux/device/devres.h:106:23: sparse: sparse: incorrect type in return expression (different address spaces) @@     expected void [noderef] __iomem * @@     got void * @@
   include/linux/device/devres.h:106:23: sparse:     expected void [noderef] __iomem *
   include/linux/device/devres.h:106:23: sparse:     got void *

vim +106 include/linux/device/devres.h

   102	
   103	static inline
   104	void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
   105	{
 > 106		return ERR_PTR(-EINVAL);
   107	}
   108
Raag Jadav Feb. 6, 2025, 6:13 a.m. UTC | #2
On Thu, Feb 06, 2025 at 12:27:03AM +0800, kernel test robot wrote:
> Hi Raag,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on 2014c95afecee3e76ca4a56956a936e23283f05b]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Raag-Jadav/driver-core-Split-devres-APIs-to-device-devres-h/20250203-161554
> base:   2014c95afecee3e76ca4a56956a936e23283f05b
> patch link:    https://lore.kernel.org/r/20250203080902.1864382-2-raag.jadav%40intel.com
> patch subject: [PATCH v3 01/20] driver core: Split devres APIs to device/devres.h
> config: um-randconfig-r112-20250205 (https://download.01.org/0day-ci/archive/20250206/202502060025.XJwUub6I-lkp@intel.com/config)
> compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 355d0b186f178668b103068537e517f3d52ad639)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250206/202502060025.XJwUub6I-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202502060025.XJwUub6I-lkp@intel.com/
> 
> sparse warnings: (new ones prefixed by >>)
>    drivers/net/pcs/pcs-xpcs-plat.c: note: in included file (through include/linux/device.h):
> >> include/linux/device/devres.h:106:23: sparse: sparse: incorrect type in return expression (different address spaces) @@     expected void [noderef] __iomem * @@     got void * @@
>    include/linux/device/devres.h:106:23: sparse:     expected void [noderef] __iomem *
>    include/linux/device/devres.h:106:23: sparse:     got void *
> 
> vim +106 include/linux/device/devres.h
> 
>    102	
>    103	static inline
>    104	void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
>    105	{
>  > 106		return ERR_PTR(-EINVAL);
>    107	}
>    108	

Andy, are we expecting this?

Raag
Andy Shevchenko Feb. 6, 2025, 3:12 p.m. UTC | #3
On Thu, Feb 06, 2025 at 08:13:12AM +0200, Raag Jadav wrote:
> On Thu, Feb 06, 2025 at 12:27:03AM +0800, kernel test robot wrote:

> >    102	
> >    103	static inline
> >    104	void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
> >    105	{
> >  > 106		return ERR_PTR(-EINVAL);
> >    107	}
> >    108	
> 
> Andy, are we expecting this?

Oh, no, it's sparse error, but easy to fix. Need to have

		return IOMEM_ERR_PTR(-EINVAL);
Andy Shevchenko Feb. 6, 2025, 3:14 p.m. UTC | #4
On Thu, Feb 06, 2025 at 05:12:49PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 06, 2025 at 08:13:12AM +0200, Raag Jadav wrote:
> > On Thu, Feb 06, 2025 at 12:27:03AM +0800, kernel test robot wrote:

...

> > >    102	
> > >    103	static inline
> > >    104	void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
> > >    105	{
> > >  > 106		return ERR_PTR(-EINVAL);
> > >    107	}
> > >    108	
> > 
> > Andy, are we expecting this?
> 
> Oh, no, it's sparse error, but easy to fix. Need to have
> 
> 		return IOMEM_ERR_PTR(-EINVAL);

But isn't it the original issue? I mean that it was already before this series.
If so, perhaps you can fix all sparse errors like this in the devres* code.
Raag Jadav Feb. 6, 2025, 6:11 p.m. UTC | #5
On Thu, Feb 06, 2025 at 05:14:05PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 06, 2025 at 05:12:49PM +0200, Andy Shevchenko wrote:
> > On Thu, Feb 06, 2025 at 08:13:12AM +0200, Raag Jadav wrote:
> > > On Thu, Feb 06, 2025 at 12:27:03AM +0800, kernel test robot wrote:
> 
> ...
> 
> > > >    102	
> > > >    103	static inline
> > > >    104	void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
> > > >    105	{
> > > >  > 106		return ERR_PTR(-EINVAL);
> > > >    107	}
> > > >    108	
> > > 
> > > Andy, are we expecting this?
> > 
> > Oh, no, it's sparse error, but easy to fix. Need to have
> > 
> > 		return IOMEM_ERR_PTR(-EINVAL);
> 
> But isn't it the original issue? I mean that it was already before this series.

For all this time?

> If so, perhaps you can fix all sparse errors like this in the devres* code.

With a fixes tag?

Raag
Andy Shevchenko Feb. 6, 2025, 6:56 p.m. UTC | #6
On Thu, Feb 06, 2025 at 08:11:08PM +0200, Raag Jadav wrote:
> On Thu, Feb 06, 2025 at 05:14:05PM +0200, Andy Shevchenko wrote:
> > On Thu, Feb 06, 2025 at 05:12:49PM +0200, Andy Shevchenko wrote:
> > > On Thu, Feb 06, 2025 at 08:13:12AM +0200, Raag Jadav wrote:
> > > > On Thu, Feb 06, 2025 at 12:27:03AM +0800, kernel test robot wrote:

...

> > > > >    102	
> > > > >    103	static inline
> > > > >    104	void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
> > > > >    105	{
> > > > >  > 106		return ERR_PTR(-EINVAL);
> > > > >    107	}
> > > > >    108	
> > > > 
> > > > Andy, are we expecting this?
> > > 
> > > Oh, no, it's sparse error, but easy to fix. Need to have
> > > 
> > > 		return IOMEM_ERR_PTR(-EINVAL);
> > 
> > But isn't it the original issue? I mean that it was already before this series.
> 
> For all this time?

Yep. 0-day bot doesn't complain on pre-existed issues, but in case one touches
the line it becomes a new issue from its point of view.

> > If so, perhaps you can fix all sparse errors like this in the devres* code.
> 
> With a fixes tag?

Maybe.
diff mbox series

Patch

diff --git a/include/linux/device.h b/include/linux/device.h
index 80a5b3268986..78ca7fd0e625 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -26,9 +26,9 @@ 
 #include <linux/atomic.h>
 #include <linux/uidgid.h>
 #include <linux/gfp.h>
-#include <linux/overflow.h>
 #include <linux/device/bus.h>
 #include <linux/device/class.h>
+#include <linux/device/devres.h>
 #include <linux/device/driver.h>
 #include <linux/cleanup.h>
 #include <asm/device.h>
@@ -281,123 +281,6 @@  int __must_check device_create_bin_file(struct device *dev,
 void device_remove_bin_file(struct device *dev,
 			    const struct bin_attribute *attr);
 
-/* device resource management */
-typedef void (*dr_release_t)(struct device *dev, void *res);
-typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
-
-void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp,
-			  int nid, const char *name) __malloc;
-#define devres_alloc(release, size, gfp) \
-	__devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)
-#define devres_alloc_node(release, size, gfp, nid) \
-	__devres_alloc_node(release, size, gfp, nid, #release)
-
-void devres_for_each_res(struct device *dev, dr_release_t release,
-			 dr_match_t match, void *match_data,
-			 void (*fn)(struct device *, void *, void *),
-			 void *data);
-void devres_free(void *res);
-void devres_add(struct device *dev, void *res);
-void *devres_find(struct device *dev, dr_release_t release,
-		  dr_match_t match, void *match_data);
-void *devres_get(struct device *dev, void *new_res,
-		 dr_match_t match, void *match_data);
-void *devres_remove(struct device *dev, dr_release_t release,
-		    dr_match_t match, void *match_data);
-int devres_destroy(struct device *dev, dr_release_t release,
-		   dr_match_t match, void *match_data);
-int devres_release(struct device *dev, dr_release_t release,
-		   dr_match_t match, void *match_data);
-
-/* devres group */
-void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp);
-void devres_close_group(struct device *dev, void *id);
-void devres_remove_group(struct device *dev, void *id);
-int devres_release_group(struct device *dev, void *id);
-
-/* managed devm_k.alloc/kfree for device drivers */
-void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __alloc_size(2);
-void *devm_krealloc(struct device *dev, void *ptr, size_t size,
-		    gfp_t gfp) __must_check __realloc_size(3);
-__printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp,
-				     const char *fmt, va_list ap) __malloc;
-__printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp,
-				    const char *fmt, ...) __malloc;
-static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
-{
-	return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
-}
-static inline void *devm_kmalloc_array(struct device *dev,
-				       size_t n, size_t size, gfp_t flags)
-{
-	size_t bytes;
-
-	if (unlikely(check_mul_overflow(n, size, &bytes)))
-		return NULL;
-
-	return devm_kmalloc(dev, bytes, flags);
-}
-static inline void *devm_kcalloc(struct device *dev,
-				 size_t n, size_t size, gfp_t flags)
-{
-	return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
-}
-static inline __realloc_size(3, 4) void * __must_check
-devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags)
-{
-	size_t bytes;
-
-	if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
-		return NULL;
-
-	return devm_krealloc(dev, p, bytes, flags);
-}
-
-void devm_kfree(struct device *dev, const void *p);
-char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
-const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);
-void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
-	__realloc_size(3);
-
-unsigned long devm_get_free_pages(struct device *dev,
-				  gfp_t gfp_mask, unsigned int order);
-void devm_free_pages(struct device *dev, unsigned long addr);
-
-#ifdef CONFIG_HAS_IOMEM
-void __iomem *devm_ioremap_resource(struct device *dev,
-				    const struct resource *res);
-void __iomem *devm_ioremap_resource_wc(struct device *dev,
-				       const struct resource *res);
-
-void __iomem *devm_of_iomap(struct device *dev,
-			    struct device_node *node, int index,
-			    resource_size_t *size);
-#else
-
-static inline
-void __iomem *devm_ioremap_resource(struct device *dev,
-				    const struct resource *res)
-{
-	return ERR_PTR(-EINVAL);
-}
-
-static inline
-void __iomem *devm_ioremap_resource_wc(struct device *dev,
-				       const struct resource *res)
-{
-	return ERR_PTR(-EINVAL);
-}
-
-static inline
-void __iomem *devm_of_iomap(struct device *dev,
-			    struct device_node *node, int index,
-			    resource_size_t *size)
-{
-	return ERR_PTR(-EINVAL);
-}
-
-#endif
-
 /* allows to add/remove a custom action to devres stack */
 int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
 
diff --git a/include/linux/device/devres.h b/include/linux/device/devres.h
new file mode 100644
index 000000000000..128d65defafc
--- /dev/null
+++ b/include/linux/device/devres.h
@@ -0,0 +1,124 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _DEVICE_DEVRES_H_
+#define _DEVICE_DEVRES_H_
+
+#include <linux/err.h>
+#include <linux/gfp_types.h>
+#include <linux/numa.h>
+#include <linux/overflow.h>
+#include <linux/stdarg.h>
+#include <linux/types.h>
+
+struct device;
+struct device_node;
+struct resource;
+
+/* device resource management */
+typedef void (*dr_release_t)(struct device *dev, void *res);
+typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
+
+void * __malloc
+__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, const char *name);
+#define devres_alloc(release, size, gfp) \
+	__devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)
+#define devres_alloc_node(release, size, gfp, nid) \
+	__devres_alloc_node(release, size, gfp, nid, #release)
+
+void devres_for_each_res(struct device *dev, dr_release_t release,
+			 dr_match_t match, void *match_data,
+			 void (*fn)(struct device *, void *, void *),
+			 void *data);
+void devres_free(void *res);
+void devres_add(struct device *dev, void *res);
+void *devres_find(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
+void *devres_get(struct device *dev, void *new_res, dr_match_t match, void *match_data);
+void *devres_remove(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
+int devres_destroy(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
+int devres_release(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
+
+/* devres group */
+void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp);
+void devres_close_group(struct device *dev, void *id);
+void devres_remove_group(struct device *dev, void *id);
+int devres_release_group(struct device *dev, void *id);
+
+/* managed devm_k.alloc/kfree for device drivers */
+void * __alloc_size(2)
+devm_kmalloc(struct device *dev, size_t size, gfp_t gfp);
+void * __must_check __realloc_size(3)
+devm_krealloc(struct device *dev, void *ptr, size_t size, gfp_t gfp);
+static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
+{
+	return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
+}
+static inline void *devm_kmalloc_array(struct device *dev, size_t n, size_t size, gfp_t flags)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(n, size, &bytes)))
+		return NULL;
+
+	return devm_kmalloc(dev, bytes, flags);
+}
+static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags)
+{
+	return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
+}
+static inline __realloc_size(3, 4) void * __must_check
+devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
+		return NULL;
+
+	return devm_krealloc(dev, p, bytes, flags);
+}
+
+void devm_kfree(struct device *dev, const void *p);
+
+void * __realloc_size(3)
+devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp);
+
+char * __malloc
+devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
+const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);
+char * __printf(3, 0) __malloc
+devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap);
+char * __printf(3, 4) __malloc
+devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...);
+
+unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order);
+void devm_free_pages(struct device *dev, unsigned long addr);
+
+#ifdef CONFIG_HAS_IOMEM
+
+void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res);
+void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res);
+
+void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index,
+			    resource_size_t *size);
+#else
+
+static inline
+void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res)
+{
+	return ERR_PTR(-EINVAL);
+}
+
+static inline
+void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res)
+{
+	return ERR_PTR(-EINVAL);
+}
+
+static inline
+void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index,
+			    resource_size_t *size)
+{
+	return ERR_PTR(-EINVAL);
+}
+
+#endif
+
+#endif /* _DEVICE_DEVRES_H_ */