mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/
synced 2025-04-19 20:58:31 +09:00
Convert regulator drivers to use
Merge series from Raag Jadav <raag.jadav@intel.com>: This series converts regulator drivers to use the newly introduced[1] devm_kmemdup_array() helper. [1] https://lore.kernel.org/r/20250212062513.2254767-1-raag.jadav@intel.com
This commit is contained in:
commit
1455f0badd
@ -7,7 +7,7 @@
|
||||
* Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/device/devres.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/gfp_types.h>
|
||||
#include <linux/i2c.h>
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/device/devres.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/gfp_types.h>
|
||||
#include <linux/module.h>
|
||||
|
@ -138,8 +138,8 @@ static int cros_ec_regulator_init_info(struct device *dev,
|
||||
data->num_voltages =
|
||||
min_t(u16, ARRAY_SIZE(resp.voltages_mv), resp.num_voltages);
|
||||
data->voltages_mV =
|
||||
devm_kmemdup(dev, resp.voltages_mv,
|
||||
sizeof(u16) * data->num_voltages, GFP_KERNEL);
|
||||
devm_kmemdup_array(dev, resp.voltages_mv, data->num_voltages,
|
||||
sizeof(resp.voltages_mv[0]), GFP_KERNEL);
|
||||
if (!data->voltages_mV)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -332,9 +332,8 @@ int devm_regulator_bulk_get_const(struct device *dev, int num_consumers,
|
||||
const struct regulator_bulk_data *in_consumers,
|
||||
struct regulator_bulk_data **out_consumers)
|
||||
{
|
||||
*out_consumers = devm_kmemdup(dev, in_consumers,
|
||||
num_consumers * sizeof(*in_consumers),
|
||||
GFP_KERNEL);
|
||||
*out_consumers = devm_kmemdup_array(dev, in_consumers, num_consumers,
|
||||
sizeof(*in_consumers), GFP_KERNEL);
|
||||
if (*out_consumers == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
129
include/linux/device/devres.h
Normal file
129
include/linux/device/devres.h
Normal file
@ -0,0 +1,129 @@
|
||||
/* 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);
|
||||
static inline void *devm_kmemdup_array(struct device *dev, const void *src,
|
||||
size_t n, size_t size, gfp_t flags)
|
||||
{
|
||||
return devm_kmemdup(dev, src, size_mul(size, n), flags);
|
||||
}
|
||||
|
||||
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 IOMEM_ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
static inline
|
||||
void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res)
|
||||
{
|
||||
return IOMEM_ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
static inline
|
||||
void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index,
|
||||
resource_size_t *size)
|
||||
{
|
||||
return IOMEM_ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DEVICE_DEVRES_H_ */
|
@ -44,6 +44,9 @@ static inline void * __must_check ERR_PTR(long error)
|
||||
/* Return the pointer in the percpu address space. */
|
||||
#define ERR_PTR_PCPU(error) ((void __percpu *)(unsigned long)ERR_PTR(error))
|
||||
|
||||
/* Cast an error pointer to __iomem. */
|
||||
#define IOMEM_ERR_PTR(error) (__force void __iomem *)ERR_PTR(error)
|
||||
|
||||
/**
|
||||
* PTR_ERR - Extract the error code from an error pointer.
|
||||
* @ptr: An error pointer.
|
||||
|
@ -65,8 +65,6 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
|
||||
|
||||
void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
|
||||
resource_size_t size);
|
||||
void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,
|
||||
|
Loading…
x
Reference in New Issue
Block a user