Commit 85de7fac authored by Marek Vasut's avatar Marek Vasut Committed by Wolfram Sang

i2c: mxs: Fix misuse init_completion

The init_completion() call does reinit not only the variable carrying
the flag that the completion finished, but also initialized the
waitqueue associated with the completion. On the contrary, the
INIT_COMPLETION() call only reinits the flag.

In case there was anything still stuck in the waitqueue, subsequent call
to init_completion() would be able to create possible race condition. This
patch uses the proper function and moves init_completion() into .probe() call
of the driver, to be issued only once.

Note that such scenario is impossible, since two threads can never enter the
mxs_i2c_xfer_msg(), since whole this section is protected by mutex in I2C core.
This by no means allows this issue to exit though.
Signed-off-by: default avatarMarek Vasut <marex@denx.de>
Signed-off-by: default avatarWolfram Sang <w.sang@pengutronix.de>
parent 7d1f9aef
...@@ -316,7 +316,7 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, ...@@ -316,7 +316,7 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
if (msg->len == 0) if (msg->len == 0)
return -EINVAL; return -EINVAL;
init_completion(&i2c->cmd_complete); INIT_COMPLETION(i2c->cmd_complete);
i2c->cmd_err = 0; i2c->cmd_err = 0;
ret = mxs_i2c_dma_setup_xfer(adap, msg, flags); ret = mxs_i2c_dma_setup_xfer(adap, msg, flags);
...@@ -473,6 +473,8 @@ static int mxs_i2c_probe(struct platform_device *pdev) ...@@ -473,6 +473,8 @@ static int mxs_i2c_probe(struct platform_device *pdev)
i2c->dev = dev; i2c->dev = dev;
i2c->speed = &mxs_i2c_95kHz_config; i2c->speed = &mxs_i2c_95kHz_config;
init_completion(&i2c->cmd_complete);
if (dev->of_node) { if (dev->of_node) {
err = mxs_i2c_get_ofdata(i2c); err = mxs_i2c_get_ofdata(i2c);
if (err) if (err)
......
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