Commit 02a4a696 authored by Vladimir Zapolskiy's avatar Vladimir Zapolskiy Committed by Wolfram Sang

i2c: qcom-cci: don't put a device tree node before i2c_add_adapter()

There is a minor chance for a race, if a pointer to an i2c-bus subnode
is stored and then reused after releasing its reference, and it would
be sufficient to get one more reference under a loop over children
subnodes.

Fixes: e5175261 ("i2c: Add Qualcomm CCI I2C driver")
Signed-off-by: default avatarVladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Reviewed-by: default avatarRobert Foss <robert.foss@linaro.org>
Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent a0d48505
...@@ -558,7 +558,7 @@ static int cci_probe(struct platform_device *pdev) ...@@ -558,7 +558,7 @@ static int cci_probe(struct platform_device *pdev)
cci->master[idx].adap.quirks = &cci->data->quirks; cci->master[idx].adap.quirks = &cci->data->quirks;
cci->master[idx].adap.algo = &cci_algo; cci->master[idx].adap.algo = &cci_algo;
cci->master[idx].adap.dev.parent = dev; cci->master[idx].adap.dev.parent = dev;
cci->master[idx].adap.dev.of_node = child; cci->master[idx].adap.dev.of_node = of_node_get(child);
cci->master[idx].master = idx; cci->master[idx].master = idx;
cci->master[idx].cci = cci; cci->master[idx].cci = cci;
...@@ -643,8 +643,10 @@ static int cci_probe(struct platform_device *pdev) ...@@ -643,8 +643,10 @@ static int cci_probe(struct platform_device *pdev)
continue; continue;
ret = i2c_add_adapter(&cci->master[i].adap); ret = i2c_add_adapter(&cci->master[i].adap);
if (ret < 0) if (ret < 0) {
of_node_put(cci->master[i].adap.dev.of_node);
goto error_i2c; goto error_i2c;
}
} }
pm_runtime_set_autosuspend_delay(dev, MSEC_PER_SEC); pm_runtime_set_autosuspend_delay(dev, MSEC_PER_SEC);
...@@ -656,8 +658,10 @@ static int cci_probe(struct platform_device *pdev) ...@@ -656,8 +658,10 @@ static int cci_probe(struct platform_device *pdev)
error_i2c: error_i2c:
for (--i ; i >= 0; i--) { for (--i ; i >= 0; i--) {
if (cci->master[i].cci) if (cci->master[i].cci) {
i2c_del_adapter(&cci->master[i].adap); i2c_del_adapter(&cci->master[i].adap);
of_node_put(cci->master[i].adap.dev.of_node);
}
} }
error: error:
disable_irq(cci->irq); disable_irq(cci->irq);
...@@ -673,8 +677,10 @@ static int cci_remove(struct platform_device *pdev) ...@@ -673,8 +677,10 @@ static int cci_remove(struct platform_device *pdev)
int i; int i;
for (i = 0; i < cci->data->num_masters; i++) { for (i = 0; i < cci->data->num_masters; i++) {
if (cci->master[i].cci) if (cci->master[i].cci) {
i2c_del_adapter(&cci->master[i].adap); i2c_del_adapter(&cci->master[i].adap);
of_node_put(cci->master[i].adap.dev.of_node);
}
cci_halt(cci, i); cci_halt(cci, i);
} }
......
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