Skip to content

Commit b9fbb62

Browse files
charleskeepaxSamuel Ortiz
authored andcommitted
mfd: Only unregister platform devices allocated by the mfd core
mfd_remove_devices would iterate over all devices sharing a parent with an mfd device regardless of whether they were allocated by the mfd core or not. This especially caused problems when the device structure was not contained within a platform_device, because to_platform_device is used on each device pointer. This patch defines a device_type for mfd devices and checks this is present from mfd_remove_devices_fn before processing the device. Cc: stable@vger.kernel.org Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Tested-by: Peter Tyser <ptyser@xes-inc.com> Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent d511b9c commit b9fbb62

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

drivers/mfd/mfd-core.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <linux/irqdomain.h>
2222
#include <linux/of.h>
2323

24+
static struct device_type mfd_dev_type = {
25+
.name = "mfd_device",
26+
};
27+
2428
int mfd_cell_enable(struct platform_device *pdev)
2529
{
2630
const struct mfd_cell *cell = mfd_get_cell(pdev);
@@ -91,6 +95,7 @@ static int mfd_add_device(struct device *parent, int id,
9195
goto fail_device;
9296

9397
pdev->dev.parent = parent;
98+
pdev->dev.type = &mfd_dev_type;
9499

95100
if (parent->of_node && cell->of_compatible) {
96101
for_each_child_of_node(parent->of_node, np) {
@@ -204,10 +209,16 @@ EXPORT_SYMBOL(mfd_add_devices);
204209

205210
static int mfd_remove_devices_fn(struct device *dev, void *c)
206211
{
207-
struct platform_device *pdev = to_platform_device(dev);
208-
const struct mfd_cell *cell = mfd_get_cell(pdev);
212+
struct platform_device *pdev;
213+
const struct mfd_cell *cell;
209214
atomic_t **usage_count = c;
210215

216+
if (dev->type != &mfd_dev_type)
217+
return 0;
218+
219+
pdev = to_platform_device(dev);
220+
cell = mfd_get_cell(pdev);
221+
211222
/* find the base address of usage_count pointers (for freeing) */
212223
if (!*usage_count || (cell->usage_count < *usage_count))
213224
*usage_count = cell->usage_count;

0 commit comments

Comments
 (0)