[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>
This commit is contained in:
parent
8ea43d0a2f
commit
7bd444ede7
|
@ -313,21 +313,11 @@ static u32 functionality(struct i2c_adapter *adap)
|
||||||
msleep(10); \
|
msleep(10); \
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct i2c_algorithm tm6000_algo = {
|
static const struct i2c_algorithm tm6000_algo = {
|
||||||
.master_xfer = tm6000_i2c_xfer,
|
.master_xfer = tm6000_i2c_xfer,
|
||||||
.functionality = functionality,
|
.functionality = functionality,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct i2c_adapter tm6000_adap_template = {
|
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.name = "tm6000",
|
|
||||||
.algo = &tm6000_algo,
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct i2c_client tm6000_client_template = {
|
|
||||||
.name = "tm6000 internal",
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------- */
|
/* ----------------------------------------------------------- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -337,17 +327,20 @@ static struct i2c_client tm6000_client_template = {
|
||||||
int tm6000_i2c_register(struct tm6000_core *dev)
|
int tm6000_i2c_register(struct tm6000_core *dev)
|
||||||
{
|
{
|
||||||
unsigned char eedata[256];
|
unsigned char eedata[256];
|
||||||
|
int rc;
|
||||||
|
|
||||||
dev->i2c_adap = tm6000_adap_template;
|
dev->i2c_adap.owner = THIS_MODULE;
|
||||||
|
dev->i2c_adap.algo = &tm6000_algo;
|
||||||
dev->i2c_adap.dev.parent = &dev->udev->dev;
|
dev->i2c_adap.dev.parent = &dev->udev->dev;
|
||||||
strcpy(dev->i2c_adap.name, dev->name);
|
strlcpy(dev->i2c_adap.name, dev->name, sizeof(dev->i2c_adap.name));
|
||||||
dev->i2c_adap.algo_data = dev;
|
dev->i2c_adap.algo_data = dev;
|
||||||
i2c_add_adapter(&dev->i2c_adap);
|
|
||||||
|
|
||||||
dev->i2c_client = tm6000_client_template;
|
|
||||||
dev->i2c_client.adapter = &dev->i2c_adap;
|
|
||||||
|
|
||||||
i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
|
i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
|
||||||
|
rc = i2c_add_adapter(&dev->i2c_adap);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
dev->i2c_client.adapter = &dev->i2c_adap;
|
||||||
|
strlcpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE);
|
||||||
|
|
||||||
tm6000_i2c_eeprom(dev, eedata, sizeof(eedata));
|
tm6000_i2c_eeprom(dev, eedata, sizeof(eedata));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue