Skip to content

Commit a8f447b

Browse files
ldewanganLee Jones
authored andcommitted
mfd: Add resource managed APIs for mfd_add_devices
Add resource managed API devm_mfd_add_devices() for the mfd_add_devices(). This helps in reducing code in error path as it is not required to call mfd_remove_devices() explicitly to remove all child-devices. In some cases, it also helps not to implement .remove() callback which get called during driver unbind. Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent bd42511 commit a8f447b

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎drivers/mfd/mfd-core.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,44 @@ void mfd_remove_devices(struct device *parent)
334334
}
335335
EXPORT_SYMBOL(mfd_remove_devices);
336336

337+
static void devm_mfd_dev_release(struct device *dev, void *res)
338+
{
339+
mfd_remove_devices(dev);
340+
}
341+
342+
/**
343+
* devm_mfd_add_devices - Resource managed version of mfd_add_devices()
344+
*
345+
* Returns 0 on success or an appropriate negative error number on failure.
346+
* All child-devices of the MFD will automatically be removed when it gets
347+
* unbinded.
348+
*/
349+
int devm_mfd_add_devices(struct device *dev, int id,
350+
const struct mfd_cell *cells, int n_devs,
351+
struct resource *mem_base,
352+
int irq_base, struct irq_domain *domain)
353+
{
354+
struct device **ptr;
355+
int ret;
356+
357+
ptr = devres_alloc(devm_mfd_dev_release, sizeof(*ptr), GFP_KERNEL);
358+
if (!ptr)
359+
return -ENOMEM;
360+
361+
ret = mfd_add_devices(dev, id, cells, n_devs, mem_base,
362+
irq_base, domain);
363+
if (ret < 0) {
364+
devres_free(ptr);
365+
return ret;
366+
}
367+
368+
*ptr = dev;
369+
devres_add(dev, ptr);
370+
371+
return ret;
372+
}
373+
EXPORT_SYMBOL(devm_mfd_add_devices);
374+
337375
int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones)
338376
{
339377
struct mfd_cell cell_entry;

‎include/linux/mfd/core.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,8 @@ static inline int mfd_add_hotplug_devices(struct device *parent,
131131

132132
extern void mfd_remove_devices(struct device *parent);
133133

134+
extern int devm_mfd_add_devices(struct device *dev, int id,
135+
const struct mfd_cell *cells, int n_devs,
136+
struct resource *mem_base,
137+
int irq_base, struct irq_domain *irq_domain);
134138
#endif

0 commit comments

Comments
 (0)