Skip to content

Commit 29bb1bd

Browse files
committed
Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
* 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6: hwmon: (lm75) Drop legacy i2c driver i2c: correct some size_t printk formats i2c: Check for address business before creating clients i2c: Let users select algorithm drivers manually again i2c: Fix NULL pointer dereference in i2c_new_probed_device i2c: Fix oops on bus multiplexer driver loading
2 parents 3f1ae22 + 8ff69ee commit 29bb1bd

File tree

8 files changed

+66
-110
lines changed

8 files changed

+66
-110
lines changed

drivers/hwmon/lm75.c

Lines changed: 22 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ enum lm75_type { /* keep sorted in alphabetical order */
5454
tmp75,
5555
};
5656

57-
/* Addresses scanned by legacy style driver binding */
57+
/* Addresses scanned */
5858
static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
5959
0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
6060

61-
/* Insmod parameters (only for legacy style driver binding) */
61+
/* Insmod parameters */
6262
I2C_CLIENT_INSMOD_1(lm75);
6363

6464

@@ -72,7 +72,6 @@ static const u8 LM75_REG_TEMP[3] = {
7272

7373
/* Each client has this additional data */
7474
struct lm75_data {
75-
struct i2c_client *client;
7675
struct device *hwmon_dev;
7776
struct mutex update_lock;
7877
u8 orig_conf;
@@ -138,7 +137,7 @@ static const struct attribute_group lm75_group = {
138137

139138
/*-----------------------------------------------------------------------*/
140139

141-
/* "New style" I2C driver binding -- following the driver model */
140+
/* device probe and removal */
142141

143142
static int
144143
lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
@@ -157,8 +156,6 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
157156
return -ENOMEM;
158157

159158
i2c_set_clientdata(client, data);
160-
161-
data->client = client;
162159
mutex_init(&data->update_lock);
163160

164161
/* Set to LM75 resolution (9 bits, 1/2 degree C) and range.
@@ -236,45 +233,16 @@ static const struct i2c_device_id lm75_ids[] = {
236233
};
237234
MODULE_DEVICE_TABLE(i2c, lm75_ids);
238235

239-
static struct i2c_driver lm75_driver = {
240-
.driver = {
241-
.name = "lm75",
242-
},
243-
.probe = lm75_probe,
244-
.remove = lm75_remove,
245-
.id_table = lm75_ids,
246-
};
247-
248-
/*-----------------------------------------------------------------------*/
249-
250-
/* "Legacy" I2C driver binding */
251-
252-
static struct i2c_driver lm75_legacy_driver;
253-
254-
/* This function is called by i2c_probe */
255-
static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
236+
/* Return 0 if detection is successful, -ENODEV otherwise */
237+
static int lm75_detect(struct i2c_client *new_client, int kind,
238+
struct i2c_board_info *info)
256239
{
240+
struct i2c_adapter *adapter = new_client->adapter;
257241
int i;
258-
struct i2c_client *new_client;
259-
int err = 0;
260242

261243
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
262244
I2C_FUNC_SMBUS_WORD_DATA))
263-
goto exit;
264-
265-
/* OK. For now, we presume we have a valid address. We create the
266-
client structure, even though there may be no sensor present.
267-
But it allows us to use i2c_smbus_read_*_data() calls. */
268-
new_client = kzalloc(sizeof *new_client, GFP_KERNEL);
269-
if (!new_client) {
270-
err = -ENOMEM;
271-
goto exit;
272-
}
273-
274-
new_client->addr = address;
275-
new_client->adapter = adapter;
276-
new_client->driver = &lm75_legacy_driver;
277-
new_client->flags = 0;
245+
return -ENODEV;
278246

279247
/* Now, we do the remaining detection. There is no identification-
280248
dedicated register so we have to rely on several tricks:
@@ -294,71 +262,44 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
294262
|| i2c_smbus_read_word_data(new_client, 5) != hyst
295263
|| i2c_smbus_read_word_data(new_client, 6) != hyst
296264
|| i2c_smbus_read_word_data(new_client, 7) != hyst)
297-
goto exit_free;
265+
return -ENODEV;
298266
os = i2c_smbus_read_word_data(new_client, 3);
299267
if (i2c_smbus_read_word_data(new_client, 4) != os
300268
|| i2c_smbus_read_word_data(new_client, 5) != os
301269
|| i2c_smbus_read_word_data(new_client, 6) != os
302270
|| i2c_smbus_read_word_data(new_client, 7) != os)
303-
goto exit_free;
271+
return -ENODEV;
304272

305273
/* Unused bits */
306274
if (conf & 0xe0)
307-
goto exit_free;
275+
return -ENODEV;
308276

309277
/* Addresses cycling */
310278
for (i = 8; i < 0xff; i += 8)
311279
if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
312280
|| i2c_smbus_read_word_data(new_client, i + 2) != hyst
313281
|| i2c_smbus_read_word_data(new_client, i + 3) != os)
314-
goto exit_free;
282+
return -ENODEV;
315283
}
316284

317285
/* NOTE: we treat "force=..." and "force_lm75=..." the same.
318286
* Only new-style driver binding distinguishes chip types.
319287
*/
320-
strlcpy(new_client->name, "lm75", I2C_NAME_SIZE);
321-
322-
/* Tell the I2C layer a new client has arrived */
323-
err = i2c_attach_client(new_client);
324-
if (err)
325-
goto exit_free;
326-
327-
err = lm75_probe(new_client, NULL);
328-
if (err < 0)
329-
goto exit_detach;
288+
strlcpy(info->type, "lm75", I2C_NAME_SIZE);
330289

331290
return 0;
332-
333-
exit_detach:
334-
i2c_detach_client(new_client);
335-
exit_free:
336-
kfree(new_client);
337-
exit:
338-
return err;
339-
}
340-
341-
static int lm75_attach_adapter(struct i2c_adapter *adapter)
342-
{
343-
if (!(adapter->class & I2C_CLASS_HWMON))
344-
return 0;
345-
return i2c_probe(adapter, &addr_data, lm75_detect);
346291
}
347292

348-
static int lm75_detach_client(struct i2c_client *client)
349-
{
350-
lm75_remove(client);
351-
i2c_detach_client(client);
352-
kfree(client);
353-
return 0;
354-
}
355-
356-
static struct i2c_driver lm75_legacy_driver = {
293+
static struct i2c_driver lm75_driver = {
294+
.class = I2C_CLASS_HWMON,
357295
.driver = {
358-
.name = "lm75_legacy",
296+
.name = "lm75",
359297
},
360-
.attach_adapter = lm75_attach_adapter,
361-
.detach_client = lm75_detach_client,
298+
.probe = lm75_probe,
299+
.remove = lm75_remove,
300+
.id_table = lm75_ids,
301+
.detect = lm75_detect,
302+
.address_data = &addr_data,
362303
};
363304

364305
/*-----------------------------------------------------------------------*/
@@ -424,22 +365,11 @@ static struct lm75_data *lm75_update_device(struct device *dev)
424365

425366
static int __init sensors_lm75_init(void)
426367
{
427-
int status;
428-
429-
status = i2c_add_driver(&lm75_driver);
430-
if (status < 0)
431-
return status;
432-
433-
status = i2c_add_driver(&lm75_legacy_driver);
434-
if (status < 0)
435-
i2c_del_driver(&lm75_driver);
436-
437-
return status;
368+
return i2c_add_driver(&lm75_driver);
438369
}
439370

440371
static void __exit sensors_lm75_exit(void)
441372
{
442-
i2c_del_driver(&lm75_legacy_driver);
443373
i2c_del_driver(&lm75_driver);
444374
}
445375

drivers/i2c/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ config I2C_CHARDEV
3838
This support is also available as a module. If so, the module
3939
will be called i2c-dev.
4040

41+
config I2C_HELPER_AUTO
42+
bool "Autoselect pertinent helper modules"
43+
default y
44+
help
45+
Some I2C bus drivers require so-called "I2C algorithm" modules
46+
to work. These are basically software-only abstractions of generic
47+
I2C interfaces. This option will autoselect them so that you don't
48+
have to care.
49+
50+
Unselect this only if you need to enable additional helper
51+
modules, for example for use with external I2C bus drivers.
52+
53+
In doubt, say Y.
54+
4155
source drivers/i2c/algos/Kconfig
4256
source drivers/i2c/busses/Kconfig
4357
source drivers/i2c/chips/Kconfig

drivers/i2c/algos/Kconfig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
# I2C algorithm drivers configuration
33
#
44

5+
menu "I2C Algorithms"
6+
depends on !I2C_HELPER_AUTO
7+
58
config I2C_ALGOBIT
6-
tristate
9+
tristate "I2C bit-banging interfaces"
710

811
config I2C_ALGOPCF
9-
tristate
12+
tristate "I2C PCF 8584 interfaces"
1013

1114
config I2C_ALGOPCA
12-
tristate
15+
tristate "I2C PCA 9564 interfaces"
1316

1417
config I2C_ALGO_SGI
1518
tristate
1619
depends on SGI_IP22 || SGI_IP32 || X86_VISWS
20+
21+
endmenu

drivers/i2c/busses/i2c-amd756-s4882.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ static int __init amd756_s4882_init(void)
155155
int i, error;
156156
union i2c_smbus_data ioconfig;
157157

158+
if (!amd756_smbus.dev.parent)
159+
return -ENODEV;
160+
158161
/* Configure the PCA9556 multiplexer */
159162
ioconfig.byte = 0x00; /* All I/O to output mode */
160163
error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
@@ -168,11 +171,7 @@ static int __init amd756_s4882_init(void)
168171
/* Unregister physical bus */
169172
error = i2c_del_adapter(&amd756_smbus);
170173
if (error) {
171-
if (error == -EINVAL)
172-
error = -ENODEV;
173-
else
174-
dev_err(&amd756_smbus.dev, "Physical bus removal "
175-
"failed\n");
174+
dev_err(&amd756_smbus.dev, "Physical bus removal failed\n");
176175
goto ERROR0;
177176
}
178177

drivers/i2c/busses/i2c-nforce2-s4985.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ static int __init nforce2_s4985_init(void)
150150
int i, error;
151151
union i2c_smbus_data ioconfig;
152152

153+
if (!nforce2_smbus)
154+
return -ENODEV;
155+
153156
/* Configure the PCA9556 multiplexer */
154157
ioconfig.byte = 0x00; /* All I/O to output mode */
155158
error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
@@ -161,8 +164,6 @@ static int __init nforce2_s4985_init(void)
161164
}
162165

163166
/* Unregister physical bus */
164-
if (!nforce2_smbus)
165-
return -ENODEV;
166167
error = i2c_del_adapter(nforce2_smbus);
167168
if (error) {
168169
dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n");

drivers/i2c/chips/at24.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
188188
count = I2C_SMBUS_BLOCK_MAX;
189189
status = i2c_smbus_read_i2c_block_data(client, offset,
190190
count, buf);
191-
dev_dbg(&client->dev, "smbus read %zd@%d --> %d\n",
191+
dev_dbg(&client->dev, "smbus read %zu@%d --> %d\n",
192192
count, offset, status);
193193
return (status < 0) ? -EIO : status;
194194
}
@@ -214,7 +214,7 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
214214
msg[1].len = count;
215215

216216
status = i2c_transfer(client->adapter, msg, 2);
217-
dev_dbg(&client->dev, "i2c read %zd@%d --> %d\n",
217+
dev_dbg(&client->dev, "i2c read %zu@%d --> %d\n",
218218
count, offset, status);
219219

220220
if (status == 2)
@@ -334,7 +334,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, char *buf,
334334
if (status == 1)
335335
status = count;
336336
}
337-
dev_dbg(&client->dev, "write %zd@%d --> %zd (%ld)\n",
337+
dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n",
338338
count, offset, status, jiffies);
339339

340340
if (status == count)
@@ -512,7 +512,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
512512

513513
i2c_set_clientdata(client, at24);
514514

515-
dev_info(&client->dev, "%Zd byte %s EEPROM %s\n",
515+
dev_info(&client->dev, "%zu byte %s EEPROM %s\n",
516516
at24->bin.size, client->name,
517517
writable ? "(writable)" : "(read-only)");
518518
dev_dbg(&client->dev,

drivers/i2c/i2c-core.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,12 @@ static int i2c_check_addr(struct i2c_adapter *adapter, int addr)
813813
int i2c_attach_client(struct i2c_client *client)
814814
{
815815
struct i2c_adapter *adapter = client->adapter;
816-
int res = 0;
816+
int res;
817+
818+
/* Check for address business */
819+
res = i2c_check_addr(adapter, client->addr);
820+
if (res)
821+
return res;
817822

818823
client->dev.parent = &client->adapter->dev;
819824
client->dev.bus = &i2c_bus_type;
@@ -1451,9 +1456,11 @@ i2c_new_probed_device(struct i2c_adapter *adap,
14511456
if ((addr_list[i] & ~0x07) == 0x30
14521457
|| (addr_list[i] & ~0x0f) == 0x50
14531458
|| !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
1459+
union i2c_smbus_data data;
1460+
14541461
if (i2c_smbus_xfer(adap, addr_list[i], 0,
14551462
I2C_SMBUS_READ, 0,
1456-
I2C_SMBUS_BYTE, NULL) >= 0)
1463+
I2C_SMBUS_BYTE, &data) >= 0)
14571464
break;
14581465
} else {
14591466
if (i2c_smbus_xfer(adap, addr_list[i], 0,

drivers/i2c/i2c-dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count,
147147
if (tmp==NULL)
148148
return -ENOMEM;
149149

150-
pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n",
150+
pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n",
151151
iminor(file->f_path.dentry->d_inode), count);
152152

153153
ret = i2c_master_recv(client,tmp,count);
@@ -175,7 +175,7 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
175175
return -EFAULT;
176176
}
177177

178-
pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n",
178+
pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
179179
iminor(file->f_path.dentry->d_inode), count);
180180

181181
ret = i2c_master_send(client,tmp,count);

0 commit comments

Comments
 (0)