[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250225113314.12353-1-anindya.sg@samsung.com>
Date: Tue, 25 Feb 2025 17:03:14 +0530
From: Anindya Sundar Gayen <anindya.sg@...sung.com>
To: andi.shyti@...nel.org, linux-i2c@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: aswani.reddy@...sung.com, pankaj.dubey@...sung.com
Subject: [PATCH] i2c-algo-bit: Added the bus lock during a i2c transaction
Earlier i2c-bus lock was not available to i2c-algo-bit driver
for that reason if there are back to back i2c transaction occurs
it may be possible to occur a race condition.
To avoid the race condition we added a mutex lock mechanism which will
help to protect the i2c_outb()with a proper lock.
Signed-off-by: Anindya Sundar Gayen <anindya.sg@...sung.com>
---
drivers/i2c/algos/i2c-algo-bit.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index eddf25b90ca8..18021dd9eef3 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -31,7 +31,7 @@
#endif /* DEBUG */
/* ----- global variables --------------------------------------------- */
-
+static DEFINE_MUTEX(i2c_bus_lock);
static int bit_test; /* see if the line-setting functions work */
module_param(bit_test, int, S_IRUGO);
MODULE_PARM_DESC(bit_test, "lines testing - 0 off; 1 report; 2 fail if stuck");
@@ -349,6 +349,8 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
int retval;
int wrcount = 0;
+ /* Aquire the lock before accessing the I2C bus */
+ mutex_lock(&i2c_bus_lock);
while (count > 0) {
retval = i2c_outb(i2c_adap, *temp);
@@ -379,6 +381,7 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
return retval;
}
}
+ mutex_unlock(&i2c_bus_lock);
return wrcount;
}
--
2.17.1
Powered by blists - more mailing lists