diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-11-07 10:53:44 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-12-29 05:16:45 -0500 |
commit | 7bd444ede7285cad4ed5047ff954432325fe7f95 (patch) | |
tree | cec812f2174cc690d0238a617e882ab653517aeb /drivers | |
parent | 8ea43d0a2f87b8460f46ddb7b42b5eb17c5385d2 (diff) |
[media] TM6000: Clean-up i2c initialization
Usage of templates for large structures is a bad idea, as it wastes a
lot of space. Manually initializing the few fields we need is way more
efficient.
Also set the algorithm data const, use strlcpy instead of strcpy, fix
a small race (device data must always be set before registering said
device) and properly return error on adapter registration failure.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Michel Ludwig <michel.ludwig@gmail.com>
Cc: Stefan Ringel <stefan.ringel@arcor.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/tm6000/tm6000-i2c.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c index 93f625fc852b..798087e9efb9 100644 --- a/drivers/staging/tm6000/tm6000-i2c.c +++ b/drivers/staging/tm6000/tm6000-i2c.c | |||
@@ -313,21 +313,11 @@ static u32 functionality(struct i2c_adapter *adap) | |||
313 | msleep(10); \ | 313 | msleep(10); \ |
314 | } | 314 | } |
315 | 315 | ||
316 | static struct i2c_algorithm tm6000_algo = { | 316 | static const struct i2c_algorithm tm6000_algo = { |
317 | .master_xfer = tm6000_i2c_xfer, | 317 | .master_xfer = tm6000_i2c_xfer, |
318 | .functionality = functionality, | 318 | .functionality = functionality, |
319 | }; | 319 | }; |
320 | 320 | ||
321 | static struct i2c_adapter tm6000_adap_template = { | ||
322 | .owner = THIS_MODULE, | ||
323 | .name = "tm6000", | ||
324 | .algo = &tm6000_algo, | ||
325 | }; | ||
326 | |||
327 | static struct i2c_client tm6000_client_template = { | ||
328 | .name = "tm6000 internal", | ||
329 | }; | ||
330 | |||
331 | /* ----------------------------------------------------------- */ | 321 | /* ----------------------------------------------------------- */ |
332 | 322 | ||
333 | /* | 323 | /* |
@@ -337,17 +327,20 @@ static struct i2c_client tm6000_client_template = { | |||
337 | int tm6000_i2c_register(struct tm6000_core *dev) | 327 | int tm6000_i2c_register(struct tm6000_core *dev) |
338 | { | 328 | { |
339 | unsigned char eedata[256]; | 329 | unsigned char eedata[256]; |
330 | int rc; | ||
340 | 331 | ||
341 | dev->i2c_adap = tm6000_adap_template; | 332 | dev->i2c_adap.owner = THIS_MODULE; |
333 | dev->i2c_adap.algo = &tm6000_algo; | ||
342 | dev->i2c_adap.dev.parent = &dev->udev->dev; | 334 | dev->i2c_adap.dev.parent = &dev->udev->dev; |
343 | strcpy(dev->i2c_adap.name, dev->name); | 335 | strlcpy(dev->i2c_adap.name, dev->name, sizeof(dev->i2c_adap.name)); |
344 | dev->i2c_adap.algo_data = dev; | 336 | dev->i2c_adap.algo_data = dev; |
345 | i2c_add_adapter(&dev->i2c_adap); | 337 | i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev); |
338 | rc = i2c_add_adapter(&dev->i2c_adap); | ||
339 | if (rc) | ||
340 | return rc; | ||
346 | 341 | ||
347 | dev->i2c_client = tm6000_client_template; | ||
348 | dev->i2c_client.adapter = &dev->i2c_adap; | 342 | dev->i2c_client.adapter = &dev->i2c_adap; |
349 | 343 | strlcpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE); | |
350 | i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev); | ||
351 | 344 | ||
352 | tm6000_i2c_eeprom(dev, eedata, sizeof(eedata)); | 345 | tm6000_i2c_eeprom(dev, eedata, sizeof(eedata)); |
353 | 346 | ||