Commit 30816ac0 authored by Russell King's avatar Russell King

MFD: mcp-core: sanitize host creation/removal

host_unregister() gives us no chance between removing the device
and the mcp data structure being freed to access the data inbetween,
which drivers may need to do if they need to iounmap() pointers in
their private data structures.

Therefore, re-jig the interfaces, which are now, on creation:

	mcp = mcp_host_alloc()
	if (mcp) {
		ret = mcp_host_add(mcp, data);

		if (!ret)
			mcp_host_free(mcp);
	}

and on removal:

	mcp_host_del(mcp);
	... access mcp ...
	mcp_host_free(mcp);

The free does the final put_device() on the struct device as one would
expect.
Acked-by: default avatarJochen Friedrich <jochen@scram.de>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 0af5e4c3
...@@ -208,6 +208,7 @@ struct mcp *mcp_host_alloc(struct device *parent, size_t size) ...@@ -208,6 +208,7 @@ struct mcp *mcp_host_alloc(struct device *parent, size_t size)
mcp = kzalloc(sizeof(struct mcp) + size, GFP_KERNEL); mcp = kzalloc(sizeof(struct mcp) + size, GFP_KERNEL);
if (mcp) { if (mcp) {
spin_lock_init(&mcp->lock); spin_lock_init(&mcp->lock);
device_initialize(&mcp->attached_device);
mcp->attached_device.parent = parent; mcp->attached_device.parent = parent;
mcp->attached_device.bus = &mcp_bus_type; mcp->attached_device.bus = &mcp_bus_type;
mcp->attached_device.dma_mask = parent->dma_mask; mcp->attached_device.dma_mask = parent->dma_mask;
...@@ -217,18 +218,24 @@ struct mcp *mcp_host_alloc(struct device *parent, size_t size) ...@@ -217,18 +218,24 @@ struct mcp *mcp_host_alloc(struct device *parent, size_t size)
} }
EXPORT_SYMBOL(mcp_host_alloc); EXPORT_SYMBOL(mcp_host_alloc);
int mcp_host_register(struct mcp *mcp) int mcp_host_add(struct mcp *mcp)
{ {
dev_set_name(&mcp->attached_device, "mcp0"); dev_set_name(&mcp->attached_device, "mcp0");
return device_register(&mcp->attached_device); return device_add(&mcp->attached_device);
} }
EXPORT_SYMBOL(mcp_host_register); EXPORT_SYMBOL(mcp_host_add);
void mcp_host_unregister(struct mcp *mcp) void mcp_host_del(struct mcp *mcp)
{ {
device_unregister(&mcp->attached_device); device_del(&mcp->attached_device);
} }
EXPORT_SYMBOL(mcp_host_unregister); EXPORT_SYMBOL(mcp_host_del);
void mcp_host_free(struct mcp *mcp)
{
put_device(&mcp->attached_device);
}
EXPORT_SYMBOL(mcp_host_free);
int mcp_driver_register(struct mcp_driver *mcpdrv) int mcp_driver_register(struct mcp_driver *mcpdrv)
{ {
......
...@@ -195,10 +195,11 @@ static int mcp_sa11x0_probe(struct platform_device *pdev) ...@@ -195,10 +195,11 @@ static int mcp_sa11x0_probe(struct platform_device *pdev)
mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) / mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) /
mcp->sclk_rate; mcp->sclk_rate;
ret = mcp_host_register(mcp); ret = mcp_host_add(mcp);
if (ret == 0) if (ret == 0)
goto out; goto out;
mcp_host_free(mcp);
release: release:
release_mem_region(0x80060000, 0x60); release_mem_region(0x80060000, 0x60);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
...@@ -212,7 +213,8 @@ static int mcp_sa11x0_remove(struct platform_device *dev) ...@@ -212,7 +213,8 @@ static int mcp_sa11x0_remove(struct platform_device *dev)
struct mcp *mcp = platform_get_drvdata(dev); struct mcp *mcp = platform_get_drvdata(dev);
platform_set_drvdata(dev, NULL); platform_set_drvdata(dev, NULL);
mcp_host_unregister(mcp); mcp_host_del(mcp);
mcp_host_free(mcp);
release_mem_region(0x80060000, 0x60); release_mem_region(0x80060000, 0x60);
return 0; return 0;
......
...@@ -47,8 +47,9 @@ void mcp_disable(struct mcp *); ...@@ -47,8 +47,9 @@ void mcp_disable(struct mcp *);
#define mcp_get_sclk_rate(mcp) ((mcp)->sclk_rate) #define mcp_get_sclk_rate(mcp) ((mcp)->sclk_rate)
struct mcp *mcp_host_alloc(struct device *, size_t); struct mcp *mcp_host_alloc(struct device *, size_t);
int mcp_host_register(struct mcp *); int mcp_host_add(struct mcp *);
void mcp_host_unregister(struct mcp *); void mcp_host_del(struct mcp *);
void mcp_host_free(struct mcp *);
struct mcp_driver { struct mcp_driver {
struct device_driver drv; struct device_driver drv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment