Skip to content

Commit 5a47c0f

Browse files
author
Lee Jones
committed
mfd: mfd-core: Remove usage counting for .{en,dis}able() call-backs
The MFD implementation for reference counting was complex and unnecessary. There was only one bona fide user which has now been converted to handle the process in a different way. Any future resource protection, shared enablement functions should be handed by the parent device, rather than through the MFD subsystem API. Signed-off-by: Lee Jones <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Reviewed-by: Mark Brown <[email protected]>
1 parent 504c3fa commit 5a47c0f

File tree

2 files changed

+9
-50
lines changed

2 files changed

+9
-50
lines changed

drivers/mfd/mfd-core.c

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,31 @@ static struct device_type mfd_dev_type = {
2626
int mfd_cell_enable(struct platform_device *pdev)
2727
{
2828
const struct mfd_cell *cell = mfd_get_cell(pdev);
29-
int err = 0;
3029

3130
if (!cell->enable) {
3231
dev_dbg(&pdev->dev, "No .enable() call-back registered\n");
3332
return 0;
3433
}
3534

36-
/* only call enable hook if the cell wasn't previously enabled */
37-
if (atomic_inc_return(cell->usage_count) == 1)
38-
err = cell->enable(pdev);
39-
40-
/* if the enable hook failed, decrement counter to allow retries */
41-
if (err)
42-
atomic_dec(cell->usage_count);
43-
44-
return err;
35+
return cell->enable(pdev);
4536
}
4637
EXPORT_SYMBOL(mfd_cell_enable);
4738

4839
int mfd_cell_disable(struct platform_device *pdev)
4940
{
5041
const struct mfd_cell *cell = mfd_get_cell(pdev);
51-
int err = 0;
5242

5343
if (!cell->disable) {
5444
dev_dbg(&pdev->dev, "No .disable() call-back registered\n");
5545
return 0;
5646
}
5747

58-
/* only disable if no other clients are using it */
59-
if (atomic_dec_return(cell->usage_count) == 0)
60-
err = cell->disable(pdev);
61-
62-
/* if the disable hook failed, increment to allow retries */
63-
if (err)
64-
atomic_inc(cell->usage_count);
65-
66-
/* sanity check; did someone call disable too many times? */
67-
WARN_ON(atomic_read(cell->usage_count) < 0);
68-
69-
return err;
48+
return cell->disable(pdev);
7049
}
7150
EXPORT_SYMBOL(mfd_cell_disable);
7251

7352
static int mfd_platform_add_cell(struct platform_device *pdev,
74-
const struct mfd_cell *cell,
75-
atomic_t *usage_count)
53+
const struct mfd_cell *cell)
7654
{
7755
if (!cell)
7856
return 0;
@@ -81,7 +59,6 @@ static int mfd_platform_add_cell(struct platform_device *pdev,
8159
if (!pdev->mfd_cell)
8260
return -ENOMEM;
8361

84-
pdev->mfd_cell->usage_count = usage_count;
8562
return 0;
8663
}
8764

@@ -144,7 +121,7 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell,
144121
#endif
145122

146123
static int mfd_add_device(struct device *parent, int id,
147-
const struct mfd_cell *cell, atomic_t *usage_count,
124+
const struct mfd_cell *cell,
148125
struct resource *mem_base,
149126
int irq_base, struct irq_domain *domain)
150127
{
@@ -206,7 +183,7 @@ static int mfd_add_device(struct device *parent, int id,
206183
goto fail_alias;
207184
}
208185

209-
ret = mfd_platform_add_cell(pdev, cell, usage_count);
186+
ret = mfd_platform_add_cell(pdev, cell);
210187
if (ret)
211188
goto fail_alias;
212189

@@ -296,16 +273,9 @@ int mfd_add_devices(struct device *parent, int id,
296273
{
297274
int i;
298275
int ret;
299-
atomic_t *cnts;
300-
301-
/* initialize reference counting for all cells */
302-
cnts = kcalloc(n_devs, sizeof(*cnts), GFP_KERNEL);
303-
if (!cnts)
304-
return -ENOMEM;
305276

306277
for (i = 0; i < n_devs; i++) {
307-
atomic_set(&cnts[i], 0);
308-
ret = mfd_add_device(parent, id, cells + i, cnts + i, mem_base,
278+
ret = mfd_add_device(parent, id, cells + i, mem_base,
309279
irq_base, domain);
310280
if (ret)
311281
goto fail;
@@ -316,17 +286,15 @@ int mfd_add_devices(struct device *parent, int id,
316286
fail:
317287
if (i)
318288
mfd_remove_devices(parent);
319-
else
320-
kfree(cnts);
289+
321290
return ret;
322291
}
323292
EXPORT_SYMBOL(mfd_add_devices);
324293

325-
static int mfd_remove_devices_fn(struct device *dev, void *c)
294+
static int mfd_remove_devices_fn(struct device *dev, void *data)
326295
{
327296
struct platform_device *pdev;
328297
const struct mfd_cell *cell;
329-
atomic_t **usage_count = c;
330298

331299
if (dev->type != &mfd_dev_type)
332300
return 0;
@@ -337,20 +305,13 @@ static int mfd_remove_devices_fn(struct device *dev, void *c)
337305
regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
338306
cell->num_parent_supplies);
339307

340-
/* find the base address of usage_count pointers (for freeing) */
341-
if (!*usage_count || (cell->usage_count < *usage_count))
342-
*usage_count = cell->usage_count;
343-
344308
platform_device_unregister(pdev);
345309
return 0;
346310
}
347311

348312
void mfd_remove_devices(struct device *parent)
349313
{
350-
atomic_t *cnts = NULL;
351-
352-
device_for_each_child_reverse(parent, &cnts, mfd_remove_devices_fn);
353-
kfree(cnts);
314+
device_for_each_child_reverse(parent, NULL, mfd_remove_devices_fn);
354315
}
355316
EXPORT_SYMBOL(mfd_remove_devices);
356317

include/linux/mfd/core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ struct mfd_cell {
5959
const char *name;
6060
int id;
6161

62-
/* refcounting for multiple drivers to use a single cell */
63-
atomic_t *usage_count;
6462
int (*enable)(struct platform_device *dev);
6563
int (*disable)(struct platform_device *dev);
6664

0 commit comments

Comments
 (0)