Commit 1dff5983 authored by Jean Delvare's avatar Jean Delvare Committed by Wolfram Sang

i2c: stub: Remember the number of emulated chips

This makes initialization, cleanup and look-up easier.
Signed-off-by: default avatarJean Delvare <jdelvare@suse.de>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 6f16b75a
...@@ -68,6 +68,7 @@ struct stub_chip { ...@@ -68,6 +68,7 @@ struct stub_chip {
}; };
static struct stub_chip *stub_chips; static struct stub_chip *stub_chips;
static int stub_chips_nr;
static struct smbus_block_data *stub_find_block(struct device *dev, static struct smbus_block_data *stub_find_block(struct device *dev,
struct stub_chip *chip, struct stub_chip *chip,
...@@ -101,7 +102,7 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags, ...@@ -101,7 +102,7 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
struct smbus_block_data *b; struct smbus_block_data *b;
/* Search for the right chip */ /* Search for the right chip */
for (i = 0; i < MAX_CHIPS && chip_addr[i]; i++) { for (i = 0; i < stub_chips_nr; i++) {
if (addr == chip_addr[i]) { if (addr == chip_addr[i]) {
chip = stub_chips + i; chip = stub_chips + i;
break; break;
...@@ -281,12 +282,14 @@ static int __init i2c_stub_init(void) ...@@ -281,12 +282,14 @@ static int __init i2c_stub_init(void)
} }
/* Allocate memory for all chips at once */ /* Allocate memory for all chips at once */
stub_chips = kzalloc(i * sizeof(struct stub_chip), GFP_KERNEL); stub_chips_nr = i;
stub_chips = kcalloc(stub_chips_nr, sizeof(struct stub_chip),
GFP_KERNEL);
if (!stub_chips) { if (!stub_chips) {
pr_err("i2c-stub: Out of memory\n"); pr_err("i2c-stub: Out of memory\n");
return -ENOMEM; return -ENOMEM;
} }
for (i--; i >= 0; i--) for (i = 0; i < stub_chips_nr; i++)
INIT_LIST_HEAD(&stub_chips[i].smbus_blocks); INIT_LIST_HEAD(&stub_chips[i].smbus_blocks);
ret = i2c_add_adapter(&stub_adapter); ret = i2c_add_adapter(&stub_adapter);
......
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