generic: mtd: backport SPI_NOR_HAS_LOCK
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 7185-staging-fsl-mc-fix-asymmetry-in-destroy-of-mc_io.patch
1 From 4e55a4c296d3a93c95320cdac0b8e72f3cfefb98 Mon Sep 17 00:00:00 2001
2 From: Bharat Bhushan <Bharat.Bhushan@nxp.com>
3 Date: Wed, 22 Jun 2016 16:40:48 -0500
4 Subject: [PATCH 185/226] staging: fsl-mc: fix asymmetry in destroy of mc_io
5
6 An mc_io represents a mapped MC portal. Previously, an mc_io was
7 created for the root dprc in fsl_mc_bus_probe() and for child dprcs
8 in dprc_probe(). But the free of that data structure happened in the
9 general bus remove callback. This asymmetry resulted in some bugs due
10 to unwanted destroys of mc_io object in some scenarios (e.g. vfio).
11
12 Fix this bug by making things symmetric-- mc_io created in
13 fsl_mc_bus_probe() is freed in fsl_mc_bus_remove(). The mc_io created
14 in dprc_probe() is freed in dprc_remove().
15
16 Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
17 [Stuart: added check for root dprc and reworded commit message]
18 Signed-off-by: Stuart Yoder <stuart.yoder@nxp.com>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 ---
21 drivers/staging/fsl-mc/bus/dprc-driver.c | 5 +++++
22 drivers/staging/fsl-mc/bus/mc-bus.c | 8 ++++----
23 2 files changed, 9 insertions(+), 4 deletions(-)
24
25 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c
26 +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
27 @@ -801,6 +801,11 @@ static int dprc_remove(struct fsl_mc_dev
28 dev_set_msi_domain(&mc_dev->dev, NULL);
29 }
30
31 + if (!fsl_mc_is_root_dprc(&mc_dev->dev)) {
32 + fsl_destroy_mc_io(mc_dev->mc_io);
33 + mc_dev->mc_io = NULL;
34 + }
35 +
36 dev_info(&mc_dev->dev, "DPRC device unbound from driver");
37 return 0;
38 }
39 --- a/drivers/staging/fsl-mc/bus/mc-bus.c
40 +++ b/drivers/staging/fsl-mc/bus/mc-bus.c
41 @@ -579,10 +579,6 @@ void fsl_mc_device_remove(struct fsl_mc_
42
43 if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) {
44 mc_bus = to_fsl_mc_bus(mc_dev);
45 - if (mc_dev->mc_io) {
46 - fsl_destroy_mc_io(mc_dev->mc_io);
47 - mc_dev->mc_io = NULL;
48 - }
49
50 if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
51 if (atomic_read(&root_dprc_count) > 0)
52 @@ -810,6 +806,10 @@ static int fsl_mc_bus_remove(struct plat
53 return -EINVAL;
54
55 fsl_mc_device_remove(mc->root_mc_bus_dev);
56 +
57 + fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io);
58 + mc->root_mc_bus_dev->mc_io = NULL;
59 +
60 dev_info(&pdev->dev, "Root MC bus device removed");
61 return 0;
62 }