summaryrefslogtreecommitdiff
path: root/drivers/i2c/i2c-stub.c
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2014-07-10 14:45:11 +0400
committerWolfram Sang <wsa@the-dreams.de>2014-07-17 21:56:10 +0400
commit1dff59831b2b78122a883f44269be6597b378afa (patch)
tree4f7d24a008efeaae85b91e6d423a17486ec67628 /drivers/i2c/i2c-stub.c
parent6f16b75a41abbbd11c4c8b7c62eb66604879b981 (diff)
downloadlinux-1dff59831b2b78122a883f44269be6597b378afa.tar.xz
i2c: stub: Remember the number of emulated chips
This makes initialization, cleanup and look-up easier. Signed-off-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/i2c-stub.c')
-rw-r--r--drivers/i2c/i2c-stub.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/i2c/i2c-stub.c b/drivers/i2c/i2c-stub.c
index e0bb4655661d..ad52f0701198 100644
--- a/drivers/i2c/i2c-stub.c
+++ b/drivers/i2c/i2c-stub.c
@@ -68,6 +68,7 @@ struct stub_chip {
};
static struct stub_chip *stub_chips;
+static int stub_chips_nr;
static struct smbus_block_data *stub_find_block(struct device *dev,
struct stub_chip *chip,
@@ -101,7 +102,7 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags,
struct smbus_block_data *b;
/* 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]) {
chip = stub_chips + i;
break;
@@ -281,12 +282,14 @@ static int __init i2c_stub_init(void)
}
/* 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) {
pr_err("i2c-stub: Out of memory\n");
return -ENOMEM;
}
- for (i--; i >= 0; i--)
+ for (i = 0; i < stub_chips_nr; i++)
INIT_LIST_HEAD(&stub_chips[i].smbus_blocks);
ret = i2c_add_adapter(&stub_adapter);