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: Jochen Friedrich <jochen@scram.de>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
This commit is contained in:
Russell King
2012-01-20 22:51:07 +00:00
parent 0af5e4c36e
commit 30816ac049
3 changed files with 20 additions and 10 deletions

View File

@@ -195,10 +195,11 @@ static int mcp_sa11x0_probe(struct platform_device *pdev)
mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) /
mcp->sclk_rate;
ret = mcp_host_register(mcp);
ret = mcp_host_add(mcp);
if (ret == 0)
goto out;
mcp_host_free(mcp);
release:
release_mem_region(0x80060000, 0x60);
platform_set_drvdata(pdev, NULL);
@@ -212,7 +213,8 @@ static int mcp_sa11x0_remove(struct platform_device *dev)
struct mcp *mcp = platform_get_drvdata(dev);
platform_set_drvdata(dev, NULL);
mcp_host_unregister(mcp);
mcp_host_del(mcp);
mcp_host_free(mcp);
release_mem_region(0x80060000, 0x60);
return 0;