[PATCH v3 07/25] i2c: designware: Save pointer to semaphore callbacks instead of index
From: Andy Shevchenko
Date: Fri Nov 10 2023 - 14:07:48 EST
Instead of saving index and do an additional level of referencing,
save just a pointer to the semaphore callbacks directly. It makes
code cleaner.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
drivers/i2c/busses/i2c-designware-core.h | 4 +++-
drivers/i2c/busses/i2c-designware-platdrv.c | 12 ++++--------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index a7f6f3eafad7..f8dd87cb0ae9 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -187,6 +187,8 @@ struct clk;
struct device;
struct reset_control;
+struct i2c_dw_semaphore_callbacks;
+
/**
* struct dw_i2c_dev - private i2c-designware data
* @dev: driver model device node
@@ -291,7 +293,7 @@ struct dw_i2c_dev {
u16 hs_lcnt;
int (*acquire_lock)(void);
void (*release_lock)(void);
- int semaphore_idx;
+ const struct i2c_dw_semaphore_callbacks *semaphore_cb;
bool shared_with_punit;
void (*disable)(struct dw_i2c_dev *dev);
int (*init)(struct dw_i2c_dev *dev);
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index cb954f11540e..4b5e58e1ce5b 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -247,21 +247,18 @@ static void i2c_dw_remove_lock_support(void *data)
{
struct dw_i2c_dev *dev = data;
- if (dev->semaphore_idx < 0)
+ if (!dev->semaphore_cb)
return;
- if (i2c_dw_semaphore_cb_table[dev->semaphore_idx].remove)
- i2c_dw_semaphore_cb_table[dev->semaphore_idx].remove(dev);
+ if (dev->semaphore_cb->remove)
+ dev->semaphore_cb->remove(dev);
}
static int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev)
{
const struct i2c_dw_semaphore_callbacks *ptr;
- int i = 0;
int ret;
- dev->semaphore_idx = -1;
-
for (ptr = i2c_dw_semaphore_cb_table; ptr->probe; ptr++) {
ret = ptr->probe(dev);
if (ret) {
@@ -273,11 +270,10 @@ static int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev)
if (ret != -ENODEV)
return ret;
- i++;
continue;
}
- dev->semaphore_idx = i;
+ dev->semaphore_cb = ptr;
break;
}
--
2.43.0.rc1.1.gbec44491f096