Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Laxman Dewangan and committed by
Lee Jones
a8f447be bd425113

+42
+38
drivers/mfd/mfd-core.c
··· 334 334 } 335 335 EXPORT_SYMBOL(mfd_remove_devices); 336 336 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 + 337 375 int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones) 338 376 { 339 377 struct mfd_cell cell_entry;
+4
include/linux/mfd/core.h
··· 131 131 132 132 extern void mfd_remove_devices(struct device *parent); 133 133 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); 134 138 #endif