diff options
author | Jean Delvare <jdelvare@suse.de> | 2014-07-10 06:45:11 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2014-07-17 13:56:10 -0400 |
commit | 1dff59831b2b78122a883f44269be6597b378afa (patch) | |
tree | 4f7d24a008efeaae85b91e6d423a17486ec67628 | |
parent | 6f16b75a41abbbd11c4c8b7c62eb66604879b981 (diff) |
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>
-rw-r--r-- | drivers/i2c/i2c-stub.c | 9 |
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 { | |||
68 | }; | 68 | }; |
69 | 69 | ||
70 | static struct stub_chip *stub_chips; | 70 | static struct stub_chip *stub_chips; |
71 | static int stub_chips_nr; | ||
71 | 72 | ||
72 | static struct smbus_block_data *stub_find_block(struct device *dev, | 73 | static struct smbus_block_data *stub_find_block(struct device *dev, |
73 | struct stub_chip *chip, | 74 | struct stub_chip *chip, |
@@ -101,7 +102,7 @@ static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags, | |||
101 | struct smbus_block_data *b; | 102 | struct smbus_block_data *b; |
102 | 103 | ||
103 | /* Search for the right chip */ | 104 | /* Search for the right chip */ |
104 | for (i = 0; i < MAX_CHIPS && chip_addr[i]; i++) { | 105 | for (i = 0; i < stub_chips_nr; i++) { |
105 | if (addr == chip_addr[i]) { | 106 | if (addr == chip_addr[i]) { |
106 | chip = stub_chips + i; | 107 | chip = stub_chips + i; |
107 | break; | 108 | break; |
@@ -281,12 +282,14 @@ static int __init i2c_stub_init(void) | |||
281 | } | 282 | } |
282 | 283 | ||
283 | /* Allocate memory for all chips at once */ | 284 | /* Allocate memory for all chips at once */ |
284 | stub_chips = kzalloc(i * sizeof(struct stub_chip), GFP_KERNEL); | 285 | stub_chips_nr = i; |
286 | stub_chips = kcalloc(stub_chips_nr, sizeof(struct stub_chip), | ||
287 | GFP_KERNEL); | ||
285 | if (!stub_chips) { | 288 | if (!stub_chips) { |
286 | pr_err("i2c-stub: Out of memory\n"); | 289 | pr_err("i2c-stub: Out of memory\n"); |
287 | return -ENOMEM; | 290 | return -ENOMEM; |
288 | } | 291 | } |
289 | for (i--; i >= 0; i--) | 292 | for (i = 0; i < stub_chips_nr; i++) |
290 | INIT_LIST_HEAD(&stub_chips[i].smbus_blocks); | 293 | INIT_LIST_HEAD(&stub_chips[i].smbus_blocks); |
291 | 294 | ||
292 | ret = i2c_add_adapter(&stub_adapter); | 295 | ret = i2c_add_adapter(&stub_adapter); |